Bug 1379912 - Back out bug 1322103 and fix it differently. Solves original not marked as replied/forwarded. r=frg
authorJorg K <jorgk@jorgk.com>
Mon, 17 Jul 2017 21:31:57 +0200
changeset 28454 a9afce55b09e805d7b095c8ae9f06a20c40c0ab5
parent 28453 0170000376576d23e86bd8faa3e51c4e659f85c2
child 28455 25b49e872ac53975737e857be31f5c676c586007
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg
bugs1379912, 1322103
Bug 1379912 - Back out bug 1322103 and fix it differently. Solves original not marked as replied/forwarded. r=frg
mail/components/compose/content/MsgComposeCommands.js
mailnews/compose/src/nsMsgCompose.cpp
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -51,16 +51,17 @@ var gMessenger;
 
 var gSpellChecker = new InlineSpellChecker();
 
 /**
  * Global variables, need to be re-initialized every time mostly because
  * we need to release them when the window closes.
  */
 var gMsgCompose;
+var gOriginalMsgURI;
 var gWindowLocked;
 var gSendLocked;
 var gContentChanged;
 var gSubjectChanged;
 var gAutoSaving;
 var gCurrentIdentity;
 var defaultSaveOperation;
 var gSendOperationInProgress;
@@ -113,16 +114,17 @@ var gNumUploadingAttachments;
 var kComposeAttachDirPrefName = "mail.compose.attach.dir";
 
 function InitializeGlobalVariables()
 {
   gMessenger = Components.classes["@mozilla.org/messenger;1"]
                          .createInstance(Components.interfaces.nsIMessenger);
 
   gMsgCompose = null;
+  gOriginalMsgURI = null;
   gWindowLocked = false;
   gContentChanged = false;
   gSubjectChanged = false;
   gCurrentIdentity = null;
   defaultSaveOperation = "draft";
   gSendOperationInProgress = false;
   gSaveOperationInProgress = false;
   gAutoSaving = false;
@@ -146,16 +148,17 @@ function InitializeGlobalVariables()
 }
 InitializeGlobalVariables();
 
 function ReleaseGlobalVariables()
 {
   gCurrentIdentity = null;
   gCharsetConvertManager = null;
   gMsgCompose = null;
+  gOriginalMsgURI = null;
   gMessenger = null;
   gDisableAttachmentReminder = false;
   _gComposeBundle = null;
   MailServices.mailSession.RemoveMsgWindow(msgWindow);
   msgWindow = null;
 }
 
 /**
@@ -2620,16 +2623,23 @@ function ComposeStartup(aParams)
       MakeFromFieldEditable(true);
       identityList.value = from;
     }
   }
   LoadIdentity(true);
 
   // Get the <editor> element to startup an editor
   var editorElement = GetCurrentEditorElement();
+
+  // Remember the original message URI. When editing a draft which is a reply
+  // or forwarded message, this gets overwritten by the ancestor's message URI so
+  // the disposition flags ("replied" or "forwarded") can be set on the ancestor.
+  // For our purposes we need the URI of the message being processed, not its
+  // original ancestor.
+  gOriginalMsgURI = params.originalMsgURI;
   gMsgCompose = MailServices.compose.initCompose(params, window, editorElement.docShell);
 
   gMsgCompose.addMsgSendListener(gSendListener);
 
   document.getElementById("returnReceiptMenu")
           .setAttribute('checked', gMsgCompose.compFields.returnReceipt);
   document.getElementById("dsnMenu")
           .setAttribute("checked", gMsgCompose.compFields.DSN);
@@ -5405,22 +5415,22 @@ function InitEditor()
         return;
       }
     }
 
     if (event.target.classList.contains("loading-internal")) {
       // We're already loading this, or tried so unsuccesfully.
       return;
     }
-    if (gMsgCompose.originalMsgURI) {
+    if (gOriginalMsgURI) {
       let msgSvc = Components.classes["@mozilla.org/messenger;1"]
         .createInstance(Components.interfaces.nsIMessenger)
-        .messageServiceFromURI(gMsgCompose.originalMsgURI);
+        .messageServiceFromURI(gOriginalMsgURI);
       let originalMsgNeckoURI = {};
-      msgSvc.GetUrlForUri(gMsgCompose.originalMsgURI, originalMsgNeckoURI, null);
+      msgSvc.GetUrlForUri(gOriginalMsgURI, originalMsgNeckoURI, null);
       if (src.startsWith(originalMsgNeckoURI.value.spec)) {
         // Reply/Forward/Edit Draft/Edit as New can contain references to
         // images in the original message. Load those and make them data: URLs
         // now.
         event.target.classList.add("loading-internal");
         try {
           loadBlockedImage(src);
         } catch (e) {
@@ -5437,23 +5447,23 @@ function InitEditor()
       // For file:, and references to parts of random messages, show the
       // blocked content notification.
       gComposeNotificationBar.setBlockedContent(src);
     }
   }, true);
 
   // Convert mailnews URL back to data: URL.
   let background = editor.document.body.background;
-  if (background && gMsgCompose.originalMsgURI) {
+  if (background && gOriginalMsgURI) {
     // Check that background has the same URL as the message itself.
     let msgSvc = Components.classes["@mozilla.org/messenger;1"]
       .createInstance(Components.interfaces.nsIMessenger)
-      .messageServiceFromURI(gMsgCompose.originalMsgURI);
+      .messageServiceFromURI(gOriginalMsgURI);
     let originalMsgNeckoURI = {};
-    msgSvc.GetUrlForUri(gMsgCompose.originalMsgURI, originalMsgNeckoURI, null);
+    msgSvc.GetUrlForUri(gOriginalMsgURI, originalMsgNeckoURI, null);
     if (background.startsWith(originalMsgNeckoURI.value.spec)) {
       try {
         editor.document.body.background = loadBlockedImage(background, true);
       } catch (e) {
         // Couldn't load the referenced image.
         Components.utils.reportError(e);
       }
     }
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -1883,17 +1883,21 @@ nsresult nsMsgCompose::CreateMessage(con
     {
       nsCOMPtr <nsIMsgDBHdr> msgDBHdr;
       rv = GetMsgDBHdrFromURI(curDraftIdURL.get(), getter_AddRefs(msgDBHdr));
       NS_ASSERTION(NS_SUCCEEDED(rv), "CreateMessage can't get msg header DB interface pointer.");
       if (msgDBHdr)
       {
         nsCString queuedDisposition;
         msgDBHdr->GetStringProperty(QUEUED_DISPOSITION_PROPERTY, getter_Copies(queuedDisposition));
-        mOriginalMsgURI.Assign(originalMsgURI);
+        // We need to retrieve the original URI from the database so we can
+        // set the disposition flags correctly if the draft is a reply or forwarded message.
+        nsCString originalMsgURIfromDB;
+        msgDBHdr->GetStringProperty(ORIG_URI_PROPERTY, getter_Copies(originalMsgURIfromDB));
+        mOriginalMsgURI = originalMsgURIfromDB;
         if (!queuedDisposition.IsEmpty())
         {
           if (queuedDisposition.Equals("replied"))
              mDraftDisposition = nsIMsgFolder::nsMsgDispositionState_Replied;
           else if (queuedDisposition.Equals("forward"))
              mDraftDisposition = nsIMsgFolder::nsMsgDispositionState_Forwarded;
         }
       }