From 45c1cd44cba0000c726da9faadb9544738369fa6 Mon Sep 17 00:00:00 2001 From: "dbragg%netscape.com" Date: Thu, 19 Jul 2001 23:56:34 +0000 Subject: [PATCH] Checking in for smeredith@netscape.com. Fix for bug 18266. Check all IMAP folders for new messages when getMessage is pressed. Added function GetNewMessagesAllFolders. r=bienvenu, sr=mscott. --- .../imap/public/nsIImapIncomingServer.idl | 2 + mailnews/imap/src/nsImapIncomingServer.cpp | 46 +++++++++++++ mailnews/imap/src/nsImapMailFolder.cpp | 65 ++++++++++++------- 3 files changed, 89 insertions(+), 24 deletions(-) diff --git a/mailnews/imap/public/nsIImapIncomingServer.idl b/mailnews/imap/public/nsIImapIncomingServer.idl index a2d152284053..a530351909fa 100644 --- a/mailnews/imap/public/nsIImapIncomingServer.idl +++ b/mailnews/imap/public/nsIImapIncomingServer.idl @@ -29,6 +29,7 @@ interface nsIEventQueue; interface nsIImapProtocol; interface nsISupportsArray; interface nsIMsgFolder; +interface nsIMsgWindow; typedef long nsMsgImapDeleteModel; @@ -81,6 +82,7 @@ interface nsIImapIncomingServer : nsISupports { void reDiscoverAllFolders(); nsIMsgFolder GetReadMailPFC(in boolean createIfMissing); nsIMsgFolder GetSentMailPFC(in boolean createIfMissing); + void GetNewMessagesAllFolders(in nsIMsgFolder aRootFolder, in nsIMsgWindow aWindow); attribute boolean doingLsub; void allowFolderConversion(out boolean allowConversion); diff --git a/mailnews/imap/src/nsImapIncomingServer.cpp b/mailnews/imap/src/nsImapIncomingServer.cpp index 01f0a945468a..fce2be8a4faa 100644 --- a/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mailnews/imap/src/nsImapIncomingServer.cpp @@ -3284,3 +3284,49 @@ nsImapIncomingServer::GetSearchScope(nsMsgSearchScopeValue *searchScope) return NS_OK; } +// Gets new messages (imap /Select) for this folder and all subfolders except +// Trash. This is a recursive function. Gets new messages for current folder +// first, then calls self recursively for each subfolder. +NS_IMETHODIMP +nsImapIncomingServer::GetNewMessagesAllFolders(nsIMsgFolder *aRootFolder, nsIMsgWindow *aWindow) +{ + nsresult retval = NS_OK; + + if (!aRootFolder) + return retval; + + // If this is the trash folder, we don't need to do anything here or with + // any subfolders. + PRUint32 flags = 0; + aRootFolder->GetFlags(&flags); + if (flags & MSG_FOLDER_FLAG_TRASH) + return retval; + + // Get new messages for this folder. + aRootFolder->UpdateFolder(aWindow); + + // Loop through all subfolders to get new messages for them. + nsCOMPtr aEnumerator; + retval = aRootFolder->GetSubFolders(getter_AddRefs(aEnumerator)); + NS_ASSERTION((NS_SUCCEEDED(retval) && aEnumerator), "GetSubFolders() failed to return enumerator."); + if (NS_FAILED(retval)) + return retval; + + nsresult more = aEnumerator->First(); + + while (NS_SUCCEEDED(more)) + { + nsCOMPtr aSupport; + nsresult rv = aEnumerator->CurrentItem(getter_AddRefs(aSupport)); + NS_ASSERTION((NS_SUCCEEDED(rv) && aSupport), "CurrentItem() failed."); + + nsCOMPtr msgFolder = do_QueryInterface(aSupport, &rv); + NS_ASSERTION((NS_SUCCEEDED(rv) && msgFolder), "nsIMsgFolder service not found."); + + retval = GetNewMessagesAllFolders(msgFolder, aWindow); + + more = aEnumerator->Next(); + } + + return retval; +} \ No newline at end of file diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 08925bebbd56..6cadb8665a8f 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -2024,42 +2024,59 @@ nsImapMailFolder::DeleteSubFolders(nsISupportsArray* folders, nsIMsgWindow *msgW return rv; } +// Called by Biff, or when user presses GetMsg button. NS_IMETHODIMP nsImapMailFolder::GetNewMessages(nsIMsgWindow *aWindow, nsIUrlListener *aListener) { - nsresult rv = NS_ERROR_FAILURE; - NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr inbox; nsCOMPtr rootFolder; - rv = GetRootFolder(getter_AddRefs(rootFolder)); - if(NS_SUCCEEDED(rv) && rootFolder) - { - PRUint32 numFolders; - rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox)); - } - if (inbox) - { - nsCOMPtr eventQ; - NS_WITH_SERVICE(nsIEventQueueService, pEventQService, kEventQueueServiceCID, &rv); - if (NS_SUCCEEDED(rv) && pEventQService) - pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD, - getter_AddRefs(eventQ)); + nsresult rv = GetRootFolder(getter_AddRefs(rootFolder)); + + if(NS_SUCCEEDED(rv) && rootFolder) { nsCOMPtr imapServer; nsresult rv = GetImapIncomingServer(getter_AddRefs(imapServer)); - + if (NS_SUCCEEDED(rv) && imapServer) imapServer->GetDownloadBodiesOnGetNewMail(&m_downloadingFolderForOfflineUse); - inbox->SetGettingNewMessages(PR_TRUE); - m_urlListener = aListener; - rv = imapService->SelectFolder(eventQ, inbox, this, aWindow, nsnull); - if (rv == NS_BINDING_ABORTED) + // Check preferences to see if we should check all folders for new + // messages, or just the inbox. + PRBool checkAllFolders = PR_FALSE; + + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && prefs) { - inbox->NotifyFolderEvent(mFolderLoadedAtom); - rv = NS_OK; + + nsCOMPtr prefBranch; + rv = prefs->GetBranch("", getter_AddRefs(prefBranch)); + + + // This pref might not exist, which is OK. We'll only check INBOX in that + // case. + if (NS_SUCCEEDED(rv) && prefBranch) + rv = prefBranch->GetBoolPref("mail.check_all_imap_folders_for_new", &checkAllFolders); } + + m_urlListener = aListener; + + if (checkAllFolders) { + + // Get new messages in all folders (except trash). + if (imapServer) + imapServer->GetNewMessagesAllFolders(rootFolder, aWindow); + } + + else { + + // Get new messages in inbox only. + PRUint32 numFolders; + nsCOMPtr inbox; + rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox)); + if (inbox) + rv = inbox->UpdateFolder(aWindow); + + } + } return rv;