Part of Bug 440794 Leverage Offline capabilities to make sending email appear faster - save identity in message header in the database. r/sr=Standard8
authorDavid Bienvenu <bienvenu@nventure.com>
Wed, 27 May 2009 11:23:25 +0100
changeset 2709 38c88455ec35aaec934d043851fad3659c13da66
parent 2708 58cf9794dd27d17807dab3f5610d6958d3535068
child 2710 33d632a3a73916f689019e7ba2886a0e2850478e
push id2202
push userbugzilla@standard8.plus.com
push dateWed, 27 May 2009 18:23:57 +0000
treeherdercomm-central@5816359932c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs440794
Part of Bug 440794 Leverage Offline capabilities to make sending email appear faster - save identity in message header in the database. r/sr=Standard8
mailnews/compose/src/nsMsgCompose.cpp
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -3035,84 +3035,94 @@ void nsMsgCompose::CleanUpRecipients(nsS
   }
   recipients = newRecipient;
 }
 
 NS_IMETHODIMP nsMsgCompose::RememberQueuedDisposition()
 {
   // need to find the msg hdr in the saved folder and then set a property on
   // the header that we then look at when we actually send the message.
+
+  const char *dispositionSetting = nsnull;
+
   if (mType == nsIMsgCompType::Reply ||
-    mType == nsIMsgCompType::ReplyAll ||
-    mType == nsIMsgCompType::ReplyToList ||
-    mType == nsIMsgCompType::ReplyToGroup ||
-    mType == nsIMsgCompType::ReplyToSender ||
-    mType == nsIMsgCompType::ReplyToSenderAndGroup ||
-    mType == nsIMsgCompType::ForwardAsAttachment ||
-    mType == nsIMsgCompType::ForwardInline)
+      mType == nsIMsgCompType::ReplyAll ||
+      mType == nsIMsgCompType::ReplyToList ||
+      mType == nsIMsgCompType::ReplyToGroup ||
+      mType == nsIMsgCompType::ReplyToSender ||
+      mType == nsIMsgCompType::ReplyToSenderAndGroup)
+    dispositionSetting = "replied";
+  else if (mType == nsIMsgCompType::ForwardAsAttachment ||
+           mType == nsIMsgCompType::ForwardInline)
+    dispositionSetting = "forwarded";
+
+  nsMsgKey msgKey;
+  if (mMsgSend)
   {
-    if (!mOriginalMsgURI.IsEmpty())
+    mMsgSend->GetMessageKey(&msgKey);
+    nsCAutoString msgUri(m_folderName);
+    nsCString identityKey;
+
+    m_identity->GetKey(identityKey);
+
+    PRInt32 insertIndex = StringBeginsWith(msgUri, NS_LITERAL_CSTRING("mailbox")) ? 7 : 4;
+    msgUri.Insert("-message", insertIndex); // "mailbox/imap: -> "mailbox/imap-message:"
+    msgUri.Append('#');
+    msgUri.AppendInt(msgKey);
+    nsCOMPtr <nsIMsgDBHdr> msgHdr;
+    nsresult rv = GetMsgDBHdrFromURI(msgUri.get(), getter_AddRefs(msgHdr));
+    NS_ENSURE_SUCCESS(rv, rv);
+    // If we did't find the msg hdr, and it's an IMAP message,
+    // we must not have downloaded the header. So we're going to set some 
+    // pending attributes on the header for the queued disposition, so that
+    // we can associate them with the header, once we've downloaded it from
+    // the imap server.
+    if (!msgHdr && insertIndex == 4)
     {
-      nsMsgKey msgKey;
-      if (mMsgSend)
+      nsCOMPtr<nsIRDFService> rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsCOMPtr <nsIRDFResource> resource;
+      rv = rdfService->GetResource(m_folderName, getter_AddRefs(resource));
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsCOMPtr <nsIMsgFolder> msgFolder(do_QueryInterface(resource));
+      if (msgFolder)
       {
-        mMsgSend->GetMessageKey(&msgKey);
-        const char *dispositionSetting = "replied";
-        if (mType == nsIMsgCompType::ForwardAsAttachment ||
-          mType == nsIMsgCompType::ForwardInline)
-          dispositionSetting = "forwarded";
-        nsCAutoString msgUri(m_folderName);
-
-        PRInt32 insertIndex = StringBeginsWith(msgUri, NS_LITERAL_CSTRING("mailbox")) ? 7 : 4;
-        msgUri.Insert("-message", insertIndex); // "mailbox/imap: -> "mailbox/imap-message:"
-        msgUri.Append('#');
-        msgUri.AppendInt(msgKey);
-        nsCOMPtr <nsIMsgDBHdr> msgHdr;
-        nsresult rv = GetMsgDBHdrFromURI(msgUri.get(), getter_AddRefs(msgHdr));
-        NS_ENSURE_SUCCESS(rv, rv);
-        // If we did't find the msg hdr, and it's an IMAP message,
-        // we must not have downloaded the header. So we're going to set some 
-        // pending attributes on the header for the queued disposition, so that
-        // we can associate them with the header, once we've downloaded it from
-        // the imap server.
-        if (!msgHdr && insertIndex == 4)
+        nsCOMPtr <nsIMsgDatabase> msgDB;
+        msgFolder->GetMsgDatabase(getter_AddRefs(msgDB));
+        if (msgDB)
         {
-          nsCOMPtr<nsIRDFService> rdfService (do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
-          NS_ENSURE_SUCCESS(rv, rv);
-
-          nsCOMPtr <nsIRDFResource> resource;
-          rv = rdfService->GetResource(m_folderName, getter_AddRefs(resource));
-          NS_ENSURE_SUCCESS(rv, rv);
-
-          nsCOMPtr <nsIMsgFolder> msgFolder(do_QueryInterface(resource));
-          if (msgFolder)
+          msgDB->CreateNewHdr(msgKey, getter_AddRefs(msgHdr));
+          if (msgHdr)
           {
-            nsCOMPtr <nsIMsgDatabase> msgDB;
-            msgFolder->GetMsgDatabase(getter_AddRefs(msgDB));
-            if (msgDB)
+            nsCString messageId;
+            mMsgSend->GetMessageId(messageId);
+            msgHdr->SetMessageId(messageId.get());
+            if (!mOriginalMsgURI.IsEmpty())
             {
-              msgDB->CreateNewHdr(msgKey, getter_AddRefs(msgHdr));
-              if (msgHdr)
-              {
-                nsCString messageId;
-                mMsgSend->GetMessageId(messageId);
-                msgHdr->SetMessageId(messageId.get());
-                msgDB->SetAttributeOnPendingHdr(msgHdr, ORIG_URI_PROPERTY, mOriginalMsgURI.get());
+              msgDB->SetAttributeOnPendingHdr(msgHdr, ORIG_URI_PROPERTY, mOriginalMsgURI.get());
+              if (dispositionSetting)
                 msgDB->SetAttributeOnPendingHdr(msgHdr, QUEUED_DISPOSITION_PROPERTY, dispositionSetting);
-                msgDB->RemoveHeaderMdbRow(msgHdr);
-              }
             }
+            msgDB->SetAttributeOnPendingHdr(msgHdr, HEADER_X_MOZILLA_IDENTITY_KEY, identityKey.get());
+            msgDB->RemoveHeaderMdbRow(msgHdr);
           }
         }
-        else if (msgHdr)
-        {
-          msgHdr->SetStringProperty(ORIG_URI_PROPERTY, mOriginalMsgURI.get());
+      }
+    }
+    else if (msgHdr)
+    {
+      if (!mOriginalMsgURI.IsEmpty())
+      {
+        msgHdr->SetStringProperty(ORIG_URI_PROPERTY, mOriginalMsgURI.get());
+        if (dispositionSetting)
           msgHdr->SetStringProperty(QUEUED_DISPOSITION_PROPERTY, dispositionSetting);
-        }
       }
+      msgHdr->SetStringProperty(HEADER_X_MOZILLA_IDENTITY_KEY, identityKey.get());
     }
   }
   return NS_OK;
 }
 
 nsresult nsMsgCompose::ProcessReplyFlags()
 {
   nsresult rv;