Bug 209189 - Don't do transaction on non-existent message. r=jorgk, a=rkent
authorR Kent James <rkent@caspia.com>
Sat, 25 Jul 2015 16:33:00 +0200
changeset 22893 1d6740a71280b3e045fa5d42ecc6b1982b050083
parent 22892 661436d7a39d4e557cf611c35eae4a7e59ddd0cb
child 22894 3db4218c150aa0882a95c66b63ab3c1221d5bc6c
push id1467
push userkent@caspia.com
push dateTue, 15 Sep 2015 01:43:32 +0000
treeherdercomm-beta@3db4218c150a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk, rkent
bugs209189
Bug 209189 - Don't do transaction on non-existent message. r=jorgk, a=rkent
mailnews/local/src/nsLocalUndoTxn.cpp
--- a/mailnews/local/src/nsLocalUndoTxn.cpp
+++ b/mailnews/local/src/nsLocalUndoTxn.cpp
@@ -283,36 +283,51 @@ nsLocalMoveCopyMsgTxn::UndoTransactionIn
       nsCOMPtr <nsIMsgLocalMailFolder> localFolder = do_QueryInterface(srcFolder);
       if (localFolder)
         localFolder->MarkMsgsOnPop3Server(srcMessages, POP3_NONE /*deleteMsgs*/);
     }
     else // undoing a move means moving the messages back.
     {
       nsCOMPtr<nsIMutableArray> dstMessages =
         do_CreateInstance(NS_ARRAY_CONTRACTID);
-      nsCOMPtr<nsIMsgDBHdr> dstHdr;
       m_numHdrsCopied = 0;
       m_srcKeyArray.Clear();
       for (i = 0; i < count; i++)
       {
-        dstDB->GetMsgHdrForKey(m_dstKeyArray[i], getter_AddRefs(dstHdr));
-        NS_ASSERTION(dstHdr, "fatal ... cannot get old msg header\n");
+        // GetMsgHdrForKey is not a test for whether the key exists, so check.
+        bool hasKey = false;
+        dstDB->ContainsKey(m_dstKeyArray[i], &hasKey);
+        nsCOMPtr<nsIMsgDBHdr> dstHdr;
+        if (hasKey)
+          dstDB->GetMsgHdrForKey(m_dstKeyArray[i], getter_AddRefs(dstHdr));
         if (dstHdr)
         {
           nsCString messageId;
           dstHdr->GetMessageId(getter_Copies(messageId));
           dstMessages->AppendElement(dstHdr, false);
           m_copiedMsgIds.AppendElement(messageId);
         }
+        else
+        {
+          NS_WARNING("Cannot get old msg header");
+        }
       }
-      srcFolder->AddFolderListener(this);
-      m_undoing = true;
-      return srcFolder->CopyMessages(dstFolder, dstMessages,
-                                     true, nullptr, nullptr, false,
-                                     false);
+      if (m_copiedMsgIds.Length())
+      {
+        srcFolder->AddFolderListener(this);
+        m_undoing = true;
+        return srcFolder->CopyMessages(dstFolder, dstMessages,
+                                       true, nullptr, nullptr, false,
+                                       false);
+      }
+      else
+      {
+        // Nothing to do, probably because original messages were deleted.
+        NS_WARNING("Undo did not find any messages to move");
+      }
     }
     srcDB->SetSummaryValid(true);
   }
 
   dstDB->DeleteMessages(m_dstKeyArray.Length(), m_dstKeyArray.Elements(), nullptr);
   dstDB->SetSummaryValid(true);
 
   return rv;