Backed out changeset fc1c18cda24b (bug 1597891) for causing oranges BETA_BASE_20191202
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 02 Dec 2019 14:32:11 +0200
changeset 28299 9c5ad9180e9133d9268073251fe2a574cefd7716
parent 28298 fc1c18cda24b0a157d4b6d71c401bf4b5146b17e
child 28300 2b456102758533eb849a6324ae2be1637361561c
push id16752
push usermkmelin@iki.fi
push dateMon, 02 Dec 2019 12:33:26 +0000
treeherdercomm-central@9c5ad9180e91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1597891
backs outfc1c18cda24b0a157d4b6d71c401bf4b5146b17e
Backed out changeset fc1c18cda24b (bug 1597891) for causing oranges Oranges: https://treeherder.mozilla.org/#/jobs?repo=comm-central&selectedJob=279022667&revision=fc1c18cda24b0a157d4b6d71c401bf4b5146b17e
mailnews/mime/src/mimemoz2.cpp
--- a/mailnews/mime/src/mimemoz2.cpp
+++ b/mailnews/mime/src/mimemoz2.cpp
@@ -1767,41 +1767,52 @@ extern "C" char *MimeGetStringByName(con
   }
 
   return strdup("???");
 }
 
 void ResetChannelCharset(MimeObject *obj) {
   if (obj->options && obj->options->stream_closure &&
       obj->options->default_charset && obj->headers) {
-    // The previous version of this code would have entered an infinite
-    // loop. But it never showed up, so it's not clear that it is ever called.
-    // See bug #1597891.
-    MOZ_DIAGNOSTIC_ASSERT(false, "Should never get here (see bug 1597891)");
-
     mime_stream_data *msd = (mime_stream_data *)(obj->options->stream_closure);
     char *ct = MimeHeaders_get(obj->headers, HEADER_CONTENT_TYPE, false, false);
-    if (ct && msd && msd->channel) {
-      char *cSet = MimeHeaders_get_parameter(ct, "charset", nullptr, nullptr);
-      if (cSet) {
-        // First, setup the channel.
+    if ((ct) && (msd) && (msd->channel)) {
+      char *ptr = strstr(ct, "charset=");
+      if (ptr) {
+        // First, setup the channel!
         msd->channel->SetContentType(nsDependentCString(ct));
 
         // Second, if this is a Save As operation, then we need to convert
-        // to override the output charset.
-        if (msd->format_out == nsMimeOutput::nsMimeMessageSaveAs) {
-          PR_FREEIF(obj->options->default_charset);
-          obj->options->default_charset = cSet;
-          cSet = nullptr;  // Ownership was transferred.
-          obj->options->override_charset = true;
+        // to override the output charset!
+        mime_stream_data *msd = GetMSD(obj->options);
+        if ((msd) && (msd->format_out == nsMimeOutput::nsMimeMessageSaveAs)) {
+          // Extract the charset alone
+          char *cSet = nullptr;
+          if (*(ptr + 8) == '"')
+            cSet = strdup(ptr + 9);
+          else
+            cSet = strdup(ptr + 8);
+          if (cSet) {
+            char *ptr2 = cSet;
+            while ((*cSet) && (*cSet != ' ') && (*cSet != ';') &&
+                   (*cSet != '\r') && (*cSet != '\n') && (*cSet != '"'))
+              ptr2++;
+
+            if (*cSet) {
+              PR_FREEIF(obj->options->default_charset);
+              obj->options->default_charset = strdup(cSet);
+              obj->options->override_charset = true;
+            }
+
+            PR_FREEIF(cSet);
+          }
         }
-        PR_FREEIF(cSet);
       }
+      PR_FREEIF(ct);
     }
-    PR_FREEIF(ct);
   }
 }
 
 ////////////////////////////////////////////////////////////
 // Function to get up mail/news fontlang
 ////////////////////////////////////////////////////////////
 
 nsresult GetMailNewsFont(MimeObject *obj, bool styleFixed,