Bug 1610511 - Port |Bug 1070986 - React to the removal of us-ascii as a Gecko-canonical name (map us-ascii to windows-1252)| to SeaMonkey. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Tue, 04 Feb 2020 23:13:30 +0100
changeset 37198 c1d7e03fd0d5972326caaaec47939dbec019e03a
parent 37197 92b874862cac354aa75a862a6198934b0010d9b4
child 37199 2bd348484d80259e1a3a1b7eab6e45b99215c41e
push id2552
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:24:16 +0000
treeherdercomm-beta@f95a6f4408a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg
bugs1610511, 1070986
Bug 1610511 - Port |Bug 1070986 - React to the removal of us-ascii as a Gecko-canonical name (map us-ascii to windows-1252)| to SeaMonkey. r=frg
suite/mailnews/components/compose/content/MsgComposeCommands.js
--- a/suite/mailnews/components/compose/content/MsgComposeCommands.js
+++ b/suite/mailnews/components/compose/content/MsgComposeCommands.js
@@ -68,18 +68,16 @@ var gLogComposePerformance;
 var gMsgIdentityElement;
 var gMsgAddressingWidgetElement;
 var gMsgSubjectElement;
 var gMsgAttachmentElement;
 var gMsgHeadersToolbarElement;
 var gComposeType;
 
 // i18n globals
-var gSendDefaultCharset;
-var gCharsetTitle;
 var gCharsetConvertManager;
 
 var gLastWindowToHaveFocus;
 var gReceiptOptionChanged;
 var gDSNOptionChanged;
 var gAttachVCardOptionChanged;
 
 var gMailSession;
@@ -100,18 +98,16 @@ function InitializeGlobalVariables()
   gContentChanged = false;
   gCurrentIdentity = null;
   defaultSaveOperation = "draft";
   gSendOrSaveOperationInProgress = false;
   gAutoSaving = false;
   gCloseWindowAfterSave = false;
   gSavedSendNowKey = null;
   gSendFormat = nsIMsgCompSendFormat.AskUser;
-  gSendDefaultCharset = null;
-  gCharsetTitle = null;
   gCharsetConvertManager = Cc['@mozilla.org/charset-converter-manager;1'].getService(Ci.nsICharsetConverterManager);
   gMailSession = Cc["@mozilla.org/messenger/services/session;1"].getService(Ci.nsIMsgMailSession);
   gHideMenus = false;
   // We are storing the value of the bool logComposePerformance inorder to avoid logging unnecessarily.
   if (sMsgComposeService)
     gLogComposePerformance = sMsgComposeService.logComposePerformance;
 
   gLastWindowToHaveFocus = null;
@@ -1528,65 +1524,35 @@ function ComposeSetCharacterSet(aEvent)
 
 function SetDocumentCharacterSet(aCharset)
 {
   // Replace generic Japanese with ISO-2022-JP.
   if (aCharset == "Japanese") {
     aCharset = "ISO-2022-JP";
   }
   gMsgCompose.SetDocumentCharset(aCharset);
-  gCharsetTitle = null;
   SetComposeWindowTitle();
 }
 
 function GetCharsetUIString()
 {
-  var charset = gMsgCompose.compFields.characterSet;
-  if (gSendDefaultCharset == null) {
-    gSendDefaultCharset = gMsgCompose.compFields.defaultCharacterSet;
+  // The charset here is already the canonical charset (not an alias).
+  let charset = gMsgCompose.compFields.characterSet;
+  if (!charset)
+    return "";
+
+  if (charset.toLowerCase() != gMsgCompose.compFields.defaultCharacterSet.toLowerCase()) {
+    try {
+      return " - " + gCharsetConvertManager.getCharsetTitle(charset);
+    }
+    catch(e) { // Not a canonical charset after all...
+      Cu.reportError("Not charset title for charset=" + charset);
+      return " - " + charset;
+    }
   }
-
-  charset = charset.toUpperCase();
-  if (charset == "US-ASCII")
-    charset = "ISO-8859-1";
-
-  if (charset != gSendDefaultCharset) {
-
-    if (gCharsetTitle == null) {
-      try {
-        // check if we have a converter for this charset
-        var charsetAlias = gCharsetConvertManager.getCharsetAlias(charset);
-        var encoderList = gCharsetConvertManager.getEncoderList();
-        var found = false;
-        while (encoderList.hasMore()) {
-            if (charsetAlias == encoderList.getNext()) {
-                found = true;
-                break;
-            }
-        }
-        if (!found)
-        {
-          dump("no charset converter available for " +  charset + " default charset is used instead\n");
-          // set to default charset, no need to show it in the window title
-          gMsgCompose.compFields.characterSet = gSendDefaultCharset;
-          return "";
-        }
-
-        // get a localized string
-        gCharsetTitle = gCharsetConvertManager.getCharsetTitle(charsetAlias);
-      }
-      catch (ex) {
-        dump("failed to get a charset title of " + charset + "!\n");
-        gCharsetTitle = charset; // just show the charset itself
-      }
-    }
-
-    return " - " + gCharsetTitle;
-  }
-
   return "";
 }
 
 // Add-ons can override this to customize the behavior.
 function DoSpellCheckBeforeSend()
 {
   return Services.prefs.getBoolPref("mail.SpellCheckBeforeSend");
 }