Bug 745395 - Replying to attached emails doesn't show the original message. r=bienvenu,a=Standard8
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Tue, 17 Apr 2012 21:17:24 +0300
changeset 11784 d464d18772e8a5d1995cb05f91d47719994b4d07
parent 11783 a4c78c9d4606c271ff4c7d013476183b615440c6
child 11785 dafccb53c4925bdea6731c90fd7bbf24da17b0ab
push id6
push userbienvenu@nventure.com
push dateWed, 16 May 2012 22:24:51 +0000
treeherdertry-comm-central@ac395aea3008 [default view] [failures only]
reviewersbienvenu, Standard8
bugs745395
Bug 745395 - Replying to attached emails doesn't show the original message. r=bienvenu,a=Standard8
mail/test/mozmill/composition/test-forwarded-eml-actions.js
mailnews/compose/src/nsMsgCompose.cpp
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/test-forwarded-eml-actions.js
@@ -0,0 +1,134 @@
+/* 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 actions such as replying and forwarding works correctly from 
+ * an .eml message that's attached to another mail.
+ */
+
+// make SOLO_TEST=composition/test-forwarded-eml-actions.js mozmill-one
+
+const MODULE_NAME = "test-forwarded-eml-actions";
+
+const RELATIVE_ROOT = "../shared-modules";
+const MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
+                         "compose-helpers"];
+
+Cu.import("resource:///modules/mailServices.js");
+var elib = {};
+Cu.import("resource://mozmill/modules/elementslib.js", elib);
+
+var folder;
+
+var msgsubject = "mail client suggestions";
+var msgbodyA = "know of a good email client?";
+var msgbodyB = "hi, i think you may know of an email client to recommend?";
+
+var setupModule = function(module) {
+  collector.getModule("folder-display-helpers").installInto(module);
+  collector.getModule("window-helpers").installInto(module);
+  collector.getModule("compose-helpers").installInto(module);
+
+  folder = create_folder("FwdedEmlTest");
+
+  let source = 
+    "From - Mon Apr  16 22:55:33 2012\n" +
+    "Date: Mon, 16 Apr 2012 22:55:33 +0300\n" +
+    "From: Mr Example <example@invalid>\n" +
+    "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120331 Thunderbird/14.0a1\n" +
+    "MIME-Version: 1.0\n" +
+    "To: example@invalid\n" +
+    "Subject: Fwd: " + msgsubject + "\n" +
+    "References: <4F8C78F5.4000704@invalid>\n" +
+    "In-Reply-To: <4F8C78F5.4000704@invalid>\n" +
+    "X-Forwarded-Message-Id: <4F8C78F5.4000704@invalid>\n" +
+    "Content-Type: multipart/mixed;\n" +
+    " boundary=\"------------080806020206040800000503\"\n" +
+    "\n" +
+    "This is a multi-part message in MIME format.\n" +
+    "--------------080806020206040800000503\n" +
+    "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" +
+    "Content-Transfer-Encoding: 7bit\n" +
+    "\n" +
+    msgbodyB + "\n" +
+    "\n" +
+    "--------------080806020206040800000503\n" +
+    "Content-Type: message/rfc822;\n" +
+    " name=\"mail client suggestions.eml\"\n" +
+    "Content-Transfer-Encoding: 7bit\n" +
+    "Content-Disposition: attachment;\n" +
+    " filename=\"mail client suggestions.eml\"\n" +
+    "\n" +
+    "Return-Path: <example@invalid>\n" +
+    "Received: from xxx (smtpu [10.0.0.51])\n" +
+    "	 by storage (Cyrus v2.3.7-Invoca-RPM-2.3.7-1.1) with LMTPA;\n" +
+    "	 Mon, 16 Apr 2012 22:54:36 +0300\n" +
+    "Message-ID: <4F8C78F5.4000704@invalid>\n" +
+    "Date: Mon, 16 Apr 2012 22:54:29 +0300\n" +
+    "From: Mr Example <example@invalid>\n" +
+    "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120331 Thunderbird/14.0a1\n" +
+    "MIME-Version: 1.0\n" +
+    "To: example@invalid\n" +
+    "Subject: mail client suggestions\n" +
+    "Content-Type: text/plain; charset=ISO-8859-1; format=flowed\n" +
+    "Content-Transfer-Encoding: 7bit\n" +
+    "\n" +
+    msgbodyA + "\n" +
+    "\n" +
+    "--------------080806020206040800000503--\n";
+
+  folder.QueryInterface(Ci.nsIMsgLocalMailFolder);
+  folder.addMessage(source);
+}
+
+/**
+ * Helper to opend an attached .eml file, invoke the hotkey and check some
+ * properties of the composition content we get.
+ */
+function setupWindowAndTest(hotkeyToHit, hotkeyModifiers) {
+  be_in_folder(folder);
+
+  let msg = select_click_row(0);
+  assert_selected_and_displayed(mc, msg);
+
+  plan_for_new_window("mail:messageWindow");
+  mc.click(mc.eid("attachmentName"));
+  let msgWin = wait_for_new_window("mail:messageWindow");
+
+  plan_for_new_window("msgcompose");
+  msgWin.keypress(null, hotkeyToHit, hotkeyModifiers);
+  let compWin = wait_for_compose_window(msgWin);
+  
+  let bodyText= compWin.e("content-frame").contentDocument
+                        .getElementsByTagName("body")[0].textContent;
+  if (bodyText.indexOf("html") != -1)
+    throw new Error("body text contains raw html; bodyText=" + bodyText);
+
+  if (bodyText.indexOf(msgbodyA) == -1)
+    throw new Error("body text didn't contain the body text; msgbodyA=" +
+                    msgbodyB + ", bodyText=" + bodyText);
+
+  let subjectText = compWin.e("msgSubject").value;
+  if (subjectText.indexOf(msgsubject) == -1)
+    throw new Error("subject text didn't contain the original subject; " +
+                    "msgsubject=" +  msgsubject + ", subjectText=" + subjectText);
+
+  close_compose_window(compWin);
+  close_window(msgWin);
+}
+
+/**
+ * Test that replying to an attached .eml contains the expected texts.
+ */
+function test_reply_to_attached_eml() {
+  setupWindowAndTest("R", {shiftKey: false, accelKey: true});
+}
+
+/**
+ * Test that forwarding an attached .eml contains the expected texts.
+ */
+function test_forward_attached_eml() {
+  setupWindowAndTest("L", {shiftKey: false, accelKey: true});
+}
+
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -1595,26 +1595,30 @@ nsresult nsMsgCompose::CreateMessage(con
   nsresult rv = NS_OK;
 
   mType = type;
   mDraftDisposition = nsIMsgFolder::nsMsgDispositionState_None;
 
   mDeleteDraft = (type == nsIMsgCompType::Draft);
   nsCAutoString msgUri(originalMsgURI);
   bool fileUrl = StringBeginsWith(msgUri, NS_LITERAL_CSTRING("file:"));
-  PRInt32 typeIndex = msgUri.Find("?type=application/x-message-display");
-  if (typeIndex != kNotFound)
+  PRInt32 typeIndex = msgUri.Find("type=application/x-message-display");
+  if (typeIndex != kNotFound && typeIndex > 0)
   {
-    // strip out ?type=application/x-message-display because it confuses libmime
-    msgUri.Cut(typeIndex, sizeof("?type=application/x-message-display") - 1);
+    // Strip out type=application/x-message-display because it confuses libmime.
+    msgUri.Cut(typeIndex, sizeof("type=application/x-message-display"));
     if (fileUrl) // we're dealing with an .eml file msg
     {
-      // we also need to replace the next '&' with '?'
+      // We have now removed the type from the uri. Make sure we don't have
+      // an uri with "&&" now. If we do, remove the second '&'.
       if (msgUri.CharAt(typeIndex) == '&')
-        msgUri.SetCharAt('?', typeIndex);
+        msgUri.Cut(typeIndex, 1);
+      // Remove possible trailing '?'.
+      if (msgUri.CharAt(msgUri.Length() - 1) == '?')
+        msgUri.Cut(msgUri.Length() - 1, 1);
     }
     else // we're dealing with a message/rfc822 attachment
     {
       // nsURLFetcher will check for "realtype=message/rfc822" and will set the
       // content type to message/rfc822 in the forwarded message.
       msgUri.Append("&realtype=message/rfc822");
     }
     originalMsgURI = msgUri.get();