diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp index 5285985d2f2d..960173b860d7 100644 --- a/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mailnews/base/util/nsMsgDBFolder.cpp @@ -1026,8 +1026,8 @@ NS_IMETHODIMP nsMsgDBFolder::ReadFromFolderCacheElem(nsIMsgFolderCacheElement *e mFlags |= MSG_FOLDER_FLAG_ELIDED; } - element->GetInt32Property("totalMsgs", &mNumTotalMessages); - element->GetInt32Property("totalUnreadMsgs", &mNumUnreadMessages); + element->GetInt32Property("totalMsgs", &mNumTotalMessages); + element->GetInt32Property("totalUnreadMsgs", &mNumUnreadMessages); element->GetInt32Property("pendingUnreadMsgs", &mNumPendingUnreadMessages); element->GetInt32Property("pendingMsgs", &mNumPendingTotalMessages); element->GetInt32Property("expungedBytes", (PRInt32 *) &mExpungedBytes); @@ -1211,8 +1211,6 @@ nsMsgDBFolder::MarkAllMessagesRead(void) EnableNotifications(allMessageCountNotifications, PR_FALSE, PR_TRUE /*dbBatching*/); rv = mDatabase->MarkAllRead(nsnull); EnableNotifications(allMessageCountNotifications, PR_TRUE, PR_TRUE /*dbBatching*/); - mDatabase->SetSummaryValid(PR_TRUE); - mDatabase->Commit(nsMsgDBCommitType::kLargeCommit); } return rv; } @@ -3154,6 +3152,7 @@ void nsMsgDBFolder::ChangeNumPendingUnread(PRInt32 delta) PRInt32 oldUnreadMessages = mNumUnreadMessages + mNumPendingUnreadMessages; mNumPendingUnreadMessages += delta; PRInt32 newUnreadMessages = mNumUnreadMessages + mNumPendingUnreadMessages; + NS_ASSERTION(newUnreadMessages >= 0, "shouldn't have negative unread message count"); nsCOMPtr db; nsCOMPtr folderInfo; nsresult rv = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db)); @@ -4389,6 +4388,21 @@ NS_IMETHODIMP nsMsgDBFolder::NotifyCompactCompleted() return NS_ERROR_NOT_IMPLEMENTED; } +nsresult nsMsgDBFolder::CloseDBIfFolderNotOpen() +{ + nsresult rv; + nsCOMPtr session = + do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && session) // don't use NS_ENSURE_SUCCESS here - we need to release semaphore below + { + PRBool folderOpen; + session->IsFolderOpenInWindow(this, &folderOpen); + if (!folderOpen && ! (mFlags & (MSG_FOLDER_FLAG_TRASH | MSG_FOLDER_FLAG_INBOX))) + SetMsgDatabase(nsnull); + } + return rv; +} + NS_IMETHODIMP nsMsgDBFolder::SetSortOrder(PRInt32 order) { NS_ASSERTION(PR_FALSE, "not implemented"); diff --git a/mailnews/base/util/nsMsgDBFolder.h b/mailnews/base/util/nsMsgDBFolder.h index 57cdddd1d042..4e581f7c69df 100644 --- a/mailnews/base/util/nsMsgDBFolder.h +++ b/mailnews/base/util/nsMsgDBFolder.h @@ -146,6 +146,7 @@ protected: nsresult GetPurgeThreshold(PRInt32 *aThreshold); nsresult PerformBiffNotifications(void); // if there are new, non spam messages, do biff + nsresult CloseDBIfFolderNotOpen(); virtual nsresult SpamFilterClassifyMessage(const char *aURI, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin); virtual nsresult SpamFilterClassifyMessages(const char **aURIArray, PRUint32 aURICount, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin); diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index 34b850e95b8a..7c023928cb00 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -801,6 +801,7 @@ nsresult nsMsgLocalMailFolder::CreateDirectoryForFolder(nsFileSpec &path) //otherwise we need to create a new directory. else { + nsFileSpec tempPath(path.GetNativePathCString(), PR_TRUE); // create intermediate directories path.CreateDirectory(); //Above doesn't return an error value so let's see if //it was created. @@ -1624,14 +1625,9 @@ nsMsgLocalMailFolder::DeleteMessages(nsISupportsArray *messages, ThrowAlertMsg("deletingMsgsFailed", msgWindow); // we are the source folder here for a move or shift delete - //enable notifications first, because that will close the file stream - // we've been caching, and truly make the summary valid. + //enable notifications because that will close the file stream + // we've been caching, mark the db as valid, and commit it. EnableNotifications(allMessageCountNotifications, PR_TRUE, PR_TRUE /*dbBatching*/); - if (NS_SUCCEEDED(rv)) - { - mDatabase->SetSummaryValid(PR_TRUE); - mDatabase->Commit(nsMsgDBCommitType::kLargeCommit); - } if(!isMove) NotifyFolderEvent(NS_SUCCEEDED(rv) ? mDeleteOrMoveMsgCompletedAtom : mDeleteOrMoveMsgFailedAtom); } @@ -1727,16 +1723,7 @@ nsMsgLocalMailFolder::OnCopyCompleted(nsISupports *srcSupport, PRBool moveCopySu { mDatabase->SetSummaryValid(PR_TRUE); mDatabase->Commit(nsMsgDBCommitType::kLargeCommit); - nsresult rv; - nsCOMPtr session = - do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv) && session) // don't use NS_ENSURE_SUCCESS here - we need to release semaphore below - { - PRBool folderOpen; - session->IsFolderOpenInWindow(this, &folderOpen); - if (!folderOpen && ! (mFlags & (MSG_FOLDER_FLAG_TRASH | MSG_FOLDER_FLAG_INBOX))) - SetMsgDatabase(nsnull); - } + (void) CloseDBIfFolderNotOpen(); } PRBool haveSemaphore; @@ -3390,6 +3377,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::NotifyCompactCompleted() { (void) RefreshSizeOnDisk(); + (void) CloseDBIfFolderNotOpen(); nsCOMPtr compactCompletedAtom; compactCompletedAtom = do_GetAtom("CompactCompleted"); NotifyFolderEvent(compactCompletedAtom);