Bug 209189 - Don't do transaction on non-existent message. r=rkent
authorR Kent James <rkent@caspia.com>
Sat, 25 Jul 2015 16:33:00 +0200
changeset 18193 cc47880f2301
parent 18192 479e2eb5a8cd
child 18194 415fa4ec0535
push id11187
push useraleth@instantbird.org
push dateThu, 06 Aug 2015 21:31:49 +0000
treeherdercomm-central@4a3dca917204 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent
bugs209189
Bug 209189 - Don't do transaction on non-existent message. r=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;