Bug 745919 - TB 11.0.forwarding plain-text (non-MIME) emails creates empty "Attached Message Part" even when forward messages is set Inline, if no Content-Type header, no parameter in Content-Type:. r=mconley
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Tue, 30 Apr 2013 12:45:25 +0300
changeset 12374 eabed5c2dfe1699cbff291553797d25e81d3ce10
parent 12373 1dd4af110c7bb36392f8a7d1444c3b26e940dc6d
child 12375 24722af6fb8b2a2836052a7d6b47c397d67e5e50
push id9131
push usermkmelin@iki.fi
push dateTue, 30 Apr 2013 09:45:48 +0000
treeherdercomm-central@eabed5c2dfe1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs745919
Bug 745919 - TB 11.0.forwarding plain-text (non-MIME) emails creates empty "Attached Message Part" even when forward messages is set Inline, if no Content-Type header, no parameter in Content-Type:. r=mconley
mail/components/compose/content/MsgComposeCommands.js
mail/test/mozmill/composition/test-save-changes-on-quit.js
mailnews/mime/src/mimedrft.cpp
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -2574,17 +2574,18 @@ function SetDocumentCharacterSet(aCharse
     dump("Compose has not been created!\n");
 }
 
 function UpdateMailEditCharset()
 {
   var send_default_charset = gMsgCompose.compFields.defaultCharacterSet;
 //  dump("send_default_charset is " + send_default_charset + "\n");
 
-  var compFieldsCharset = gMsgCompose.compFields.characterSet;
+  let compFieldsCharset = gMsgCompose.compFields.characterSet ||
+                          "ISO-8859-1";
 //  dump("gMsgCompose.compFields is " + compFieldsCharset + "\n");
 
   if (gCharsetConvertManager) {
     var charsetAlias = gCharsetConvertManager.getCharsetAlias(compFieldsCharset);
     if (charsetAlias == "us-ascii")
       compFieldsCharset = "ISO-8859-1";   // no menu item for "us-ascii"
   }
 
@@ -2614,17 +2615,17 @@ function InitCharsetMenuCheckMark()
 function GetCharsetUIString()
 {
   var charset = gMsgCompose.compFields.characterSet;
   if (gSendDefaultCharset == null) {
     gSendDefaultCharset = gMsgCompose.compFields.defaultCharacterSet;
   }
 
   charset = charset.toUpperCase();
-  if (charset == "US-ASCII")
+  if (!charset || 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);
--- a/mail/test/mozmill/composition/test-save-changes-on-quit.js
+++ b/mail/test/mozmill/composition/test-save-changes-on-quit.js
@@ -30,19 +30,42 @@ var folder = null;
 
 var setupModule = function (module) {
   collector.getModule("folder-display-helpers").installInto(module);
   collector.getModule("compose-helpers").installInto(module);
   collector.getModule("prompt-helpers").installInto(module);
   collector.getModule("window-helpers").installInto(module);
 
   folder = create_folder("PromptToSaveTest");
-  add_message_to_folder(folder, create_message());
+
+  add_message_to_folder(folder, create_message()); // row 0
+
+  folder.addMessage(msgSource("content type: text", "text")); // row 1
+  folder.addMessage(msgSource("content type missing", null)); // row 2
 };
 
+function msgSource(aSubject, aContentType) {
+  let msgId = Components.classes["@mozilla.org/uuid-generator;1"]
+                        .getService(Components.interfaces.nsIUUIDGenerator)
+                        .generateUUID() + "@invalid";
+
+  return "From - Sun Apr 07 22:47:11 2013\r\n" +
+         "X-Mozilla-Status: 0001\r\n" +
+         "X-Mozilla-Status2: 00000000\r\n" +
+         "Message-ID: <" + msgId + ">\r\n" +
+         "Date: Sun, 07 Apr 2013 22:47:11 +0300\r\n" +
+         "From: Someone <some.one@invalid>\r\n" +
+         "To: someone.else@invalid\r\n" +
+         "Subject: " + aSubject + "\r\n" +
+         "MIME-Version: 1.0\r\n" +
+         (aContentType ? "Content-Type: " + aContentType + "\r\n" : "") +
+         "Content-Transfer-Encoding: 7bit\r\n\r\n" +
+         "A msg with contentType " + aContentType + "\r\n";
+}
+
 /**
  * Test that when a compose window is open with changes, and
  * a Quit is requested (for example, from File > Quit from the
  * 3pane), that the user gets a confirmation dialog to discard
  * the changes. This also tests that the user can cancel the
  * quit request.
  */
 function test_can_cancel_quit_on_changes() {
@@ -216,8 +239,44 @@ function test_prompt_on_close_for_modifi
   rwc.type(rwc.eid("content-frame"), "Howdy!");
   close_compose_window(rwc, true);
 
   let fwc = open_compose_with_forward();
   fwc.type(fwc.eid("content-frame"), "Greetings!");
   close_compose_window(fwc, true);
 }
 
+/**
+ * Test there's no prompt on close when no changes was made in reply/forward
+ * windows - for the case the original msg had content type "text".
+ */
+function test_no_prompt_on_close_for_unmodified_content_type_text() {
+  be_in_folder(folder);
+  let msg = select_click_row(1); // row 1 is the one with content type text
+  assert_selected_and_displayed(mc, msg);
+
+  let rwc = open_compose_with_reply();
+  close_compose_window(rwc, false);
+
+  let fwc = open_compose_with_forward();
+  assert_equals(fwc.e("attachmentBucket").getRowCount(), 0,
+                "forwarding msg created attachment");
+  close_compose_window(fwc, false);
+}
+
+/**
+ * Test there's no prompt on close when no changes was made in reply/forward
+ * windows - for the case the original msg had no content type.
+ */
+function test_no_prompt_on_close_for_unmodified_no_content_type() {
+  be_in_folder(folder);
+  let msg = select_click_row(2); // row 2 is the one with no content type
+  assert_selected_and_displayed(mc, msg);
+
+  let rwc = open_compose_with_reply();
+  close_compose_window(rwc, false);
+
+  let fwc = open_compose_with_forward();
+  assert_equals(fwc.e("attachmentBucket").getRowCount(), 0,
+                "forwarding msg created attachment");
+  close_compose_window(fwc, false);
+}
+
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -475,16 +475,17 @@ mime_draft_process_attachments(mime_draf
     return nullptr;
 
   nsMsgAttachmentData         *attachData = NULL, *tmp = NULL;
   nsMsgAttachedFile           *tmpFile = NULL;
 
   //It's possible we must treat the message body as attachment!
   bool bodyAsAttachment = false;
   if (mdd->messageBody &&
+      !mdd->messageBody->m_type.IsEmpty() &&
       mdd->messageBody->m_type.Find("text/html", CaseInsensitiveCompare) == -1 &&
       mdd->messageBody->m_type.Find("text/plain", CaseInsensitiveCompare) == -1 &&
       !mdd->messageBody->m_type.LowerCaseEqualsLiteral("text"))
      bodyAsAttachment = true;
 
   if (!mdd->attachments.Length() && !bodyAsAttachment)
     return nullptr;