Fix for bug 18266.  Check all IMAP folders for new messages when getMessage is pressed.
Added function GetNewMessagesAllFolders.  r=bienvenu, sr=mscott.
This commit is contained in:
dbragg%netscape.com 2001-07-19 23:56:34 +00:00
parent a02e4a6de0
commit 45c1cd44cb
3 changed files with 89 additions and 24 deletions

View File

@ -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);

View File

@ -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<nsIEnumerator> 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<nsISupports> aSupport;
nsresult rv = aEnumerator->CurrentItem(getter_AddRefs(aSupport));
NS_ASSERTION((NS_SUCCEEDED(rv) && aSupport), "CurrentItem() failed.");
nsCOMPtr<nsIMsgFolder> msgFolder = do_QueryInterface(aSupport, &rv);
NS_ASSERTION((NS_SUCCEEDED(rv) && msgFolder), "nsIMsgFolder service not found.");
retval = GetNewMessagesAllFolders(msgFolder, aWindow);
more = aEnumerator->Next();
}
return retval;
}

View File

@ -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<nsIMsgFolder> inbox;
nsCOMPtr<nsIMsgFolder> 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 <nsIEventQueue> 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<nsIImapIncomingServer> 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 <nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
{
inbox->NotifyFolderEvent(mFolderLoadedAtom);
rv = NS_OK;
nsCOMPtr<nsIPrefBranch> 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<nsIMsgFolder> inbox;
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox));
if (inbox)
rv = inbox->UpdateFolder(aWindow);
}
}
return rv;