Bug 1251783 - Retrieve full header to obtain charset. r=mkmelin a=jorgk
authorJorg K <mozilla@jorgk.com>
Mon, 29 Feb 2016 12:25:00 +0200
changeset 26802 e38c9c1defb9445f973c9e91d7fd402375274911
parent 26801 bffa07722805b17104fa5638abfd63ab4b647fc5
child 26803 7fcbe733ca61c8d5fec3dfd346c112015a18a6d5
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, jorgk
bugs1251783
Bug 1251783 - Retrieve full header to obtain charset. r=mkmelin a=jorgk
mail/test/mozmill/composition/content-utf8-alt-rel.eml
mail/test/mozmill/composition/content-utf8-rel-alt.eml
mail/test/mozmill/composition/content-utf8-rel-only.eml
mail/test/mozmill/composition/test-forward-utf8.js
mailnews/mime/src/mimedrft.cpp
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/content-utf8-alt-rel.eml
@@ -0,0 +1,45 @@
+From: test <test@test.com>
+Subject: test multipart, alternative first
+To: test2 <test2@test.com>
+Date: Sat, 27 Feb 2016 17:11:45 +0100
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="------------alternative"
+
+This is a multi-part message in MIME format.
+--------------alternative
+Content-Type: text/plain; charset=UTF-8; format=flowed
+Content-Transfer-Encoding: 8bit
+
+áóúäöüß
+
+--------------alternative
+Content-Type: multipart/related;
+ boundary="------------related"
+
+
+--------------related
+Content-Type: text/html; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+<html>
+  <head>
+    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    áóúäöüß<br>
+    <img src="cid:part1" alt=""><br>
+  </body>
+</html>
+
+--------------related
+Content-Type: image/png
+Content-Transfer-Encoding: base64
+Content-ID: <part1>
+
+iVBORw0KGgoAAAANSUhEUgAAAAYAAAALCAIAAADTMGvBAAAAEUlEQVQImWPgsi5DQwxDWggA
+lCEwN+YGfiYAAAAASUVORK5CYII=
+--------------related--
+
+--------------alternative--
+
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/content-utf8-rel-alt.eml
@@ -0,0 +1,41 @@
+From: test <test@test.com>
+Subject: test multipart, related first
+To: test2 <test2@test.com>
+Date: Sat, 27 Feb 2016 17:11:45 +0100
+MIME-Version: 1.0
+Content-Type: multipart/related;
+ boundary="------------related"
+
+--------------related
+Content-Type: multipart/alternative;
+ boundary="------------alternative"
+Content-Type: text/plain; charset=UTF-8; format=flowed
+Content-Transfer-Encoding: 8bit
+
+áóúäöüß
+
+--------------alternative
+Content-Type: text/html; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+<html>
+  <head>
+    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    áóúäöüß<br>
+    <img src="cid:part1" alt=""><br>
+  </body>
+</html>
+
+--------------alternative
+
+--------------related
+Content-Type: image/png
+Content-Transfer-Encoding: base64
+Content-ID: <part1>
+
+iVBORw0KGgoAAAANSUhEUgAAAAYAAAALCAIAAADTMGvBAAAAEUlEQVQImWPgsi5DQwxDWggA
+lCEwN+YGfiYAAAAASUVORK5CYII=
+
+--------------related--
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/content-utf8-rel-only.eml
@@ -0,0 +1,31 @@
+From: test <test@test.com>
+Subject: test HTML related only
+To: test2 <test2@test.com>
+Date: Sat, 27 Feb 2016 17:11:45 +0100
+MIME-Version: 1.0
+Content-Type: multipart/related;
+ boundary="------------related"
+
+This is a multi-part message in MIME format.
+--------------related
+Content-Type: text/html; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+  </head>
+  <body bgcolor="#FFFFFF" text="#000000">
+    áóúäöüß<br>
+    <img src="cid:part1" alt="">
+  </body>
+</html>
+
+--------------related
+Content-Type: image/png
+Content-Transfer-Encoding: base64
+Content-ID: <part1>
+
+iVBORw0KGgoAAAANSUhEUgAAAAYAAAALCAIAAADTMGvBAAAAEUlEQVQImWPgsi5DQwxDWggA
+lCEwN+YGfiYAAAAASUVORK5CYII=
+--------------related--
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/test-forward-utf8.js
@@ -0,0 +1,113 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Tests that UTF-8 messages are correctly forwarded.
+ */
+
+// mozmake SOLO_TEST=composition/test-forward-utf8.js mozmill-one
+
+var MODULE_NAME = "test-forward-utf8";
+
+var RELATIVE_ROOT = "../shared-modules";
+var MODULE_REQUIRES = ["folder-display-helpers", "compose-helpers", "window-helpers"];
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource:///modules/mailServices.js");
+var elib = {};
+Cu.import('resource://mozmill/modules/elementslib.js', elib);
+var os = {};
+Cu.import('resource://mozmill/stdlib/os.js', os);
+
+var folderToSendFrom;
+
+function setupModule(module) {
+  for (let lib of MODULE_REQUIRES) {
+    collector.getModule(lib).installInto(module);
+  }
+
+  folderToSendFrom = create_folder("FolderWithUTF8");
+}
+
+function check_content(window) {
+  let mailBody = get_compose_body(window);
+
+  let node = mailBody.firstChild;
+  while (node) {
+    if (node.classList.contains("moz-forward-container")) {
+      // We found the forward container. Let's look for our text.
+      node = node.firstChild;
+      while (node) {
+        // We won't find the exact text in the DOM but we'll find our string.
+        if (node.nodeName == "#text" && node.nodeValue.includes("áóúäöüß")) {
+          return;
+        }
+        node = node.nextSibling;
+      }
+      // Text not found in the forward container.
+      assert_true(false, "Failed to find forwarded text");
+      return;
+    }
+    node = node.nextSibling;
+  }
+
+  assert_true(false, "Failed to find forward container");
+}
+
+function forwardDirect(aFilePath) {
+  let file = os.getFileForPath(os.abspath(aFilePath,
+                               os.getFileForPath(__file__)));
+  let msgc = open_message_from_file(file);
+
+  let cwc = open_compose_with_forward(msgc);
+
+  check_content(cwc);
+
+  close_compose_window(cwc);
+  close_window(msgc);
+}
+
+function forwardViaFolder(aFilePath) {
+  be_in_folder(folderToSendFrom);
+
+  let file = os.getFileForPath(os.abspath(aFilePath,
+                               os.getFileForPath(__file__)));
+  let msgc = open_message_from_file(file);
+
+  // Copy the message to a folder.
+  let documentChild = msgc.e("messagepane").contentDocument.firstChild;
+  msgc.rightClick(new elib.Elem(documentChild));
+  msgc.click_menus_in_sequence(msgc.e("mailContext"), [
+    {id: "mailContext-copyMenu"},
+    {label: "Local Folders"},
+    {label: "FolderWithUTF8"},
+  ]);
+  close_window(msgc);
+
+  let msg = select_click_row(0);
+  assert_selected_and_displayed(mc, msg);
+
+  let fwdWin = open_compose_with_forward();
+
+  check_content(fwdWin);
+
+  close_compose_window(fwdWin);
+
+  press_delete(mc);
+}
+
+function test_utf8_forwarding_from_opened_file() {
+  forwardDirect("./content-utf8-rel-only.eml");
+  forwardDirect("./content-utf8-rel-alt.eml");
+  forwardDirect("./content-utf8-alt-rel.eml");
+}
+
+function test_utf8_forwarding_from_via_folder() {
+  forwardViaFolder("./content-utf8-rel-only.eml");
+  forwardViaFolder("./content-utf8-rel-alt.eml");
+  forwardViaFolder("./content-utf8-alt-rel.eml");
+}
+
+function teardownModule() {
+}
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -1656,17 +1656,17 @@ mime_decompose_file_init_fn ( void *stre
 
   if (mdd->options->decompose_init_count)
   {
     mdd->options->decompose_init_count++;
     NS_ASSERTION(mdd->curAttachment, "missing attachment in mime_decompose_file_init_fn");
     if (mdd->curAttachment)
       mdd->curAttachment->m_type.Adopt(MimeHeaders_get(headers,
                                                        HEADER_CONTENT_TYPE,
-                                                       true, false));
+                                                       false, true));
     return 0;
   }
   else
     mdd->options->decompose_init_count++;
 
   nAttachments = mdd->attachments.Length();
 
   if (!nAttachments && !mdd->messageBody)