Bug 321355 - Do not overwrite the original message when editing a draft message as new. r=aceman,mkmelin a=rkent THUNDERBIRD452b1_2016051723_RELBRANCH
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Fri, 11 Mar 2016 15:39:25 -0800
branchTHUNDERBIRD452b1_2016051723_RELBRANCH
changeset 27073 f1769d0615ab22449ecb4c27a3edffc57e2b8031
parent 27072 f43ff88549b08489892b6aeb2858a2a876b6f751
child 27074 4c9a6d612b107d01c23e86a22c8a00dec559cf34
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)
reviewersaceman, mkmelin, rkent
bugs321355
Bug 321355 - Do not overwrite the original message when editing a draft message as new. r=aceman,mkmelin a=rkent In case of editing as new in drafts (i.e. nsMimeOutput::nsMimeMessageEditorTemplate), do not set draftId so that the message is regarded as a new draft msg.
mail/test/mozmill/composition/test-charset-edit.js
mail/test/mozmill/composition/test-drafts.js
mailnews/mime/src/mimedrft.cpp
--- a/mail/test/mozmill/composition/test-charset-edit.js
+++ b/mail/test/mozmill/composition/test-charset-edit.js
@@ -7,17 +7,18 @@
  * replying to messages.
  */
 
 // make SOLO_TEST=composition/test-charset-edit.js mozmill-one
 
 var MODULE_NAME = "test-charset-upgrade";
 
 var RELATIVE_ROOT = "../shared-modules";
-var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers", "compose-helpers"];
+var MODULE_REQUIRES = ["folder-display-helpers", "compose-helpers",
+                       "window-helpers", "notificationbox-helpers"];
 
 var os = {};
 Cu.import("resource://mozmill/stdlib/os.js", os);
 Cu.import('resource://gre/modules/Services.jsm');
 Cu.import("resource:///modules/mailServices.js");
 Cu.import("resource:///modules/mimeParser.jsm");
 var elib = {};
 Cu.import("resource://mozmill/modules/elementslib.js", elib);
@@ -109,18 +110,22 @@ function test_wrong_reply_charset() {
   close_compose_window(rwc);
 
   let draftMsg = select_click_row(1);
   assert_equals(getMsgHeaders(draftMsg).get("").charset, "windows-1252");
   press_delete(mc); // Delete message
 
   // Edit the original message. Charset should be windows-1252 now.
   msg = select_click_row(0);
+
+  // Wait for the notification with the Edit button.
+  wait_for_notification_to_show(mc, "msgNotificationBar", "draftMsgContent");
+
   plan_for_new_window("msgcompose");
-  mc.click(mc.eid("menu_editMsgAsNew"));
+  mc.click(mc.eid("msgNotificationBar", {tagName: "button", label: "Edit"}));
   rwc = wait_for_compose_window();
   rwc.keypress(null, "s", {shiftKey: false, accelKey: true});
   close_compose_window(rwc);
   msg = select_click_row(0);
   assert_equals(getMsgHeaders(msg).get("").charset, "windows-1252");
   press_delete(mc); // Delete message
 }
 
@@ -150,18 +155,22 @@ function test_no_mojibake() {
   assert_equals(getMsgHeaders(draftMsg).get("").charset, "UTF-8");
   let text = getMsgHeaders(draftMsg, true).get("");
   if (!text.includes(nonASCII))
     throw new Error("Expected to find " + nonASCII + " in " + text);
   press_delete(mc); // Delete message
 
   // Edit the original message. Charset should be UTF-8 now.
   msg = select_click_row(0);
+
+  // Wait for the notification with the Edit button.
+  wait_for_notification_to_show(mc, "msgNotificationBar", "draftMsgContent");
+
   plan_for_new_window("msgcompose");
-  mc.click(mc.eid("menu_editMsgAsNew"));
+  mc.click(mc.eid("msgNotificationBar", {tagName: "button", label: "Edit"}));
   rwc = wait_for_compose_window();
   rwc.keypress(null, "s", {shiftKey: false, accelKey: true});
   close_compose_window(rwc);
   msg = select_click_row(0);
   assert_equals(getMsgHeaders(msg).get("").charset, "UTF-8");
   assert_equals(getMsgHeaders(msg, true).get("").trim(), nonASCII);
   press_delete(mc); // Delete message
 }
--- a/mail/test/mozmill/composition/test-drafts.js
+++ b/mail/test/mozmill/composition/test-drafts.js
@@ -72,18 +72,52 @@ function test_open_draft_again() {
   let e2 = Services.wm.getEnumerator("msgcompose");
   while (e2.hasMoreElements()) {
     e2.getNext();
     cwins2++;
   }
 
   assert_true(cwins2 > 0, "No compose window open!");
   assert_equals(cwins, cwins2, "The number of compose windows changed!");
-
-  close_compose_window(cwc); // close compose window
+ 
+  // Type something and save, then check that we only have one draft.
+  cwc.type(cwc.eid("content-frame"), "Hello!");
+  cwc.keypress(null, "s", {shiftKey: false, accelKey: true});
+  close_compose_window(cwc);
+  assert_equals(draftsFolder.getTotalMessages(false), 1);
 
   press_delete(mc); // clean up after ourselves
 }
 
+/**
+ * Tests that 'Edit as New' leaves the original message in drafts folder.
+ */
+function test_edit_as_new_in_draft() {
+  make_new_sets_in_folder(draftsFolder, [{count: 1}]);
+  be_in_folder(draftsFolder);
+
+  assert_equals(draftsFolder.getTotalMessages(false), 1);
+
+  let draftMsg = select_click_row(0);
+
+  // Wait for the notification with the Edit button.
+  wait_for_notification_to_show(mc, kBoxId, "draftMsgContent");
+
+  plan_for_new_window("msgcompose");
+  mc.keypress(null, "e", {shiftKey: false, accelKey: true});
+  let cwc = wait_for_compose_window();
+
+  cwc.type(cwc.eid("content-frame"), "Hello!");
+  cwc.keypress(null, "s", {shiftKey: false, accelKey: true});
+
+  close_compose_window(cwc);
+  assert_equals(draftsFolder.getTotalMessages(false), 2);
+
+  // Clean up the created drafts and count again.
+  press_delete(mc);
+  press_delete(mc);
+  assert_equals(draftsFolder.getTotalMessages(false), 0);
+}
+
 function teardownModule() {
   MailServices.accounts.localFoldersServer.rootFolder
               .propagateDelete(draftsFolder, true, null);
 }
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -1443,17 +1443,16 @@ mime_parse_stream_complete (nsMIMESessio
 
       //
       // At this point, we need to create a message compose window or editor
       // window via XP-COM with the information that we have retrieved from
       // the message store.
       //
       if (mdd->format_out == nsMimeOutput::nsMimeMessageEditorTemplate)
       {
-        fields->SetDraftId(mdd->url_name);
         MSG_ComposeType msgComposeType = PL_strstr(mdd->url_name,
                                                    "&redirect=true") ?
                                          nsIMsgCompType::Redirect :
                                          nsIMsgCompType::Template;
         CreateTheComposeWindow(fields, newAttachData, msgComposeType,
                                composeFormat, mdd->identity,
                                mdd->originalMsgURI, mdd->origMsgHdr);
       }