Bug 471492 - keep local copy of database to stop crashes, r=bienvenu,a=Standard8
authorKent James <kent@caspia.com>
Mon, 01 Oct 2012 09:33:09 -0700
changeset 13588 ac8795b126f1ca7194413e858483a628e91fff06
parent 13587 3546a1cdce583d1cc5602583afeeada25b44b2f5
child 13589 1d8bcbd5657039b36d3ab785b2deb3083ed1b4cf
push id18
push userbugzilla@standard8.plus.com
push dateSun, 30 Dec 2012 19:50:19 +0000
reviewersbienvenu, Standard8
bugs471492
Bug 471492 - keep local copy of database to stop crashes, r=bienvenu,a=Standard8
mailnews/imap/src/nsImapMailFolder.cpp
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -7101,23 +7101,24 @@ nsresult nsImapMailFolder::CopyMessagesO
   if (sourceMailDB)
   {
     // save the future ops in the source DB, if this is not a imap->local copy/move
     nsCOMPtr <nsITransactionManager> txnMgr;
     if (msgWindow)
       msgWindow->GetTransactionManager(getter_AddRefs(txnMgr));
     if (txnMgr)
       txnMgr->BeginBatch();
-    GetDatabase();
-    if (mDatabase)
+    nsCOMPtr<nsIMsgDatabase> database;
+    GetMsgDatabase(getter_AddRefs(database));
+    if (database)
     {
       // get the highest key in the dest db, so we can make up our fake keys
       nsMsgKey fakeBase = 1;
       nsCOMPtr <nsIDBFolderInfo> folderInfo;
-      rv = mDatabase->GetDBFolderInfo(getter_AddRefs(folderInfo));
+      rv = database->GetDBFolderInfo(getter_AddRefs(folderInfo));
       NS_ENSURE_SUCCESS(rv, rv);
       nsMsgKey highWaterMark = nsMsgKey_None;
       folderInfo->GetHighWater(&highWaterMark);
       fakeBase += highWaterMark;
       nsMsgKey fakeTop = fakeBase + srcCount;
       // Check that we have enough room for the fake headers. If fakeTop
       // is <= highWaterMark, we've overflowed.
       if (fakeTop <= highWaterMark || fakeTop == nsMsgKey_None)
@@ -7230,17 +7231,17 @@ nsresult nsImapMailFolder::CopyMessagesO
         rv = sourceMailDB->GetMsgHdrForKey(originalKey, getter_AddRefs(mailHdr));
         if (NS_SUCCEEDED(rv) && mailHdr)
         {
           bool successfulCopy = false;
           nsMsgKey srcDBhighWaterMark;
           srcDbFolderInfo->GetHighWater(&srcDBhighWaterMark);
 
           nsCOMPtr <nsIMsgDBHdr> newMailHdr;
-          rv = mDatabase->CopyHdrFromExistingHdr(fakeBase + sourceKeyIndex, mailHdr,
+          rv = database->CopyHdrFromExistingHdr(fakeBase + sourceKeyIndex, mailHdr,
             true, getter_AddRefs(newMailHdr));
           if (!newMailHdr || NS_FAILED(rv))
           {
             NS_ASSERTION(false, "failed to copy hdr");
             stopit = rv;
           }
 
           if (NS_SUCCEEDED(stopit))
@@ -7260,26 +7261,26 @@ nsresult nsImapMailFolder::CopyMessagesO
               CopyOfflineMsgBody(srcFolder, newMailHdr, mailHdr, inputStream,
                                  outputStream);
               nsCOMPtr<nsIMsgPluggableStore> offlineStore;
               (void) GetMsgStore(getter_AddRefs(offlineStore));
               if (offlineStore)
                 offlineStore->FinishNewMessage(outputStream, newMailHdr);
             }
             else
-              mDatabase->MarkOffline(fakeBase + sourceKeyIndex, false, nullptr);
+              database->MarkOffline(fakeBase + sourceKeyIndex, false, nullptr);
 
             nsCOMPtr <nsIMsgOfflineImapOperation> destOp;
-            mDatabase->GetOfflineOpForKey(fakeBase + sourceKeyIndex, true, getter_AddRefs(destOp));
+            database->GetOfflineOpForKey(fakeBase + sourceKeyIndex, true, getter_AddRefs(destOp));
             if (destOp)
             {
               // check if this is a move back to the original mailbox, in which case
               // we just delete the offline operation.
               if (messageReturningHome)
-                mDatabase->RemoveOfflineOp(destOp);
+                database->RemoveOfflineOp(destOp);
               else
               {
                 SetFlag(nsMsgFolderFlags::OfflineEvents);
                 destOp->SetSourceFolderURI(originalSrcFolderURI.get());
                 destOp->SetSrcMessageKey(originalKey);
                 addedKeys.AppendElement(fakeBase + sourceKeyIndex);
                 addedHdrs.AppendObject(newMailHdr);
               }
@@ -7349,17 +7350,17 @@ nsresult nsImapMailFolder::CopyMessagesO
         if (txnMgr)
            txnMgr->DoTransaction(undoMsgTxn);
       }
       if (outputStream)
         outputStream->Close();
 
       if (isMove)
         sourceMailDB->Commit(nsMsgDBCommitType::kLargeCommit);
-      mDatabase->Commit(nsMsgDBCommitType::kLargeCommit);
+      database->Commit(nsMsgDBCommitType::kLargeCommit);
       SummaryChanged();
       srcFolder->SummaryChanged();
     }
     if (txnMgr)
       txnMgr->EndBatch();
   }
 
   // Do this before delete, as it destroys the messages