зеркало из https://github.com/mozilla/pjs.git
43411 sr=bienvenu. Implementing expunge inbox on exit for imap servers.
This commit is contained in:
Родитель
0a698067bf
Коммит
83395d1565
|
@ -144,6 +144,10 @@ interface nsIMsgAccountManager : nsISupports {
|
|||
void SetFolderDoingEmptyTrash(in nsIMsgFolder folder);
|
||||
boolean GetEmptyTrashInProgress();
|
||||
|
||||
void CleanupInboxOnExit();
|
||||
void SetFolderDoingCleanupInbox(in nsIMsgFolder folder);
|
||||
boolean GetCleanupInboxInProgress();
|
||||
|
||||
void addRootFolderListener(in nsIFolderListener listener);
|
||||
void removeRootFolderListener(in nsIFolderListener listener);
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne
|
|||
*/
|
||||
void createStorageIfMissing(in nsIUrlListener urlListener);
|
||||
|
||||
void compact();
|
||||
void compact(in nsIUrlListener aListener);
|
||||
void emptyTrash(in nsIMsgWindow aMsgWindow, in nsIUrlListener aListener);
|
||||
|
||||
/**
|
||||
|
|
|
@ -128,6 +128,7 @@ nsMsgAccountManager::nsMsgAccountManager() :
|
|||
m_accountsLoaded(PR_FALSE),
|
||||
m_defaultAccount(null_nsCOMPtr()),
|
||||
m_emptyTrashInProgress(PR_FALSE),
|
||||
m_cleanupInboxInProgress(PR_FALSE),
|
||||
m_haveShutdown(PR_FALSE),
|
||||
m_shutdownInProgress(PR_FALSE),
|
||||
m_prefs(0)
|
||||
|
@ -936,9 +937,92 @@ PRBool PR_CALLBACK nsMsgAccountManager::emptyTrashOnExit(nsHashKey *aKey, void *
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// enumaration for closing cached connections.
|
||||
PRBool nsMsgAccountManager::closeCachedConnections(nsHashKey *aKey, void *aData,
|
||||
PRBool PR_CALLBACK nsMsgAccountManager::cleanupInboxOnExit(nsHashKey *aKey, void *aData,
|
||||
void *closure)
|
||||
{
|
||||
nsCOMPtr<nsIFolder> root;
|
||||
nsIMsgIncomingServer *msgserver = (nsIMsgIncomingServer*)aData;
|
||||
msgserver->GetRootFolder(getter_AddRefs(root));
|
||||
nsXPIDLCString type;
|
||||
msgserver->GetType(getter_Copies(type));
|
||||
if (root)
|
||||
{
|
||||
nsCOMPtr<nsIMsgFolder> folder;
|
||||
folder = do_QueryInterface(root);
|
||||
if (folder)
|
||||
{
|
||||
nsXPIDLCString passwd;
|
||||
PRBool isImap = (type ? PL_strcmp(type, "imap") == 0 :PR_FALSE);
|
||||
if (isImap)
|
||||
{
|
||||
nsImapIncomingServer *imapserver = (nsImapIncomingServer*)aData;
|
||||
PRBool cleanupInboxOnExit = PR_FALSE;
|
||||
|
||||
imapserver->GetCleanupInboxOnExit(&cleanupInboxOnExit);
|
||||
if (cleanupInboxOnExit)
|
||||
{
|
||||
msgserver->GetPassword(getter_Copies(passwd));
|
||||
if (isImap && passwd && nsCRT::strlen((const char*) passwd))
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgFolder> inboxFolder;
|
||||
nsCOMPtr<nsIEnumerator> aEnumerator;
|
||||
folder->GetSubFolders(getter_AddRefs(aEnumerator));
|
||||
nsCOMPtr<nsISupports> aSupport;
|
||||
rv = aEnumerator->First();
|
||||
while (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = aEnumerator->CurrentItem(getter_AddRefs(aSupport));
|
||||
nsCOMPtr<nsIMsgFolder>inboxFolder = do_QueryInterface(aSupport);
|
||||
PRUnichar *folderName = nsnull;
|
||||
inboxFolder->GetName(&folderName);
|
||||
if (folderName && nsCRT::strcasecmp(folderName, "INBOX") ==0)
|
||||
{
|
||||
nsCOMPtr<nsIUrlListener> urlListener;
|
||||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
|
||||
kMsgAccountManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
NS_WITH_SERVICE(nsIEventQueueService, pEventQService,
|
||||
kEventQueueServiceCID, &rv);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIEventQueue> eventQueue;
|
||||
pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,
|
||||
getter_AddRefs(eventQueue));
|
||||
|
||||
accountManager->SetFolderDoingCleanupInbox(inboxFolder);
|
||||
urlListener = do_QueryInterface(accountManager, &rv);
|
||||
|
||||
inboxFolder->Compact(urlListener);
|
||||
if (NS_SUCCEEDED(rv) && isImap && urlListener)
|
||||
{
|
||||
PRBool inProgress = PR_FALSE;
|
||||
accountManager->GetCleanupInboxInProgress(&inProgress);
|
||||
while (inProgress)
|
||||
{
|
||||
accountManager->GetCleanupInboxInProgress(&inProgress);
|
||||
PR_CEnterMonitor(inboxFolder);
|
||||
PR_CWait(folder, 1000UL);
|
||||
PR_CExitMonitor(inboxFolder);
|
||||
if (eventQueue)
|
||||
rv = eventQueue->ProcessPendingEvents();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
rv = aEnumerator->Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// enumaration for closing cached connections.
|
||||
PRBool nsMsgAccountManager::closeCachedConnections(nsHashKey *aKey, void *aData, void *closure)
|
||||
{
|
||||
nsIMsgIncomingServer *server = (nsIMsgIncomingServer*)aData;
|
||||
|
||||
|
@ -1307,6 +1391,13 @@ nsMsgAccountManager::EmptyTrashOnExit()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgAccountManager::CleanupInboxOnExit()
|
||||
{
|
||||
m_incomingServers.Enumerate(cleanupInboxOnExit,nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgAccountManager::WriteToFolderCache(nsIMsgFolderCache *folderCache)
|
||||
{
|
||||
|
@ -1930,6 +2021,13 @@ nsMsgAccountManager::OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode)
|
|||
m_emptyTrashInProgress = PR_FALSE;
|
||||
PR_CExitMonitor(m_folderDoingEmptyTrash);
|
||||
}
|
||||
else if (m_folderDoingCleanupInbox)
|
||||
{
|
||||
PR_CEnterMonitor(m_folderDoingCleanupInbox);
|
||||
PR_CNotifyAll(m_folderDoingCleanupInbox);
|
||||
m_cleanupInboxInProgress = PR_FALSE;
|
||||
PR_CExitMonitor(m_folderDoingCleanupInbox);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1949,6 +2047,21 @@ nsMsgAccountManager::GetEmptyTrashInProgress(PRBool *bVal)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgAccountManager::SetFolderDoingCleanupInbox(nsIMsgFolder *folder)
|
||||
{
|
||||
m_folderDoingCleanupInbox = folder;
|
||||
m_cleanupInboxInProgress = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgAccountManager::GetCleanupInboxInProgress(PRBool *bVal)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(bVal);
|
||||
*bVal = m_cleanupInboxInProgress;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult
|
||||
nsMsgAccountManager::SetLastServerFound(nsIMsgIncomingServer *server, const char *hostname, const char *username, const char *type)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsIUrlListener.h"
|
||||
#include "nsImapIncomingServer.h"
|
||||
|
||||
class nsMsgAccountManager
|
||||
: public nsIMsgAccountManager,
|
||||
|
@ -72,7 +73,9 @@ private:
|
|||
nsCOMPtr<nsIMsgAccount> m_defaultAccount;
|
||||
nsCOMPtr<nsISupportsArray> m_incomingServerListeners;
|
||||
nsCOMPtr<nsIMsgFolder> m_folderDoingEmptyTrash;
|
||||
nsCOMPtr<nsIMsgFolder> m_folderDoingCleanupInbox;
|
||||
PRBool m_emptyTrashInProgress;
|
||||
PRBool m_cleanupInboxInProgress;
|
||||
|
||||
nsCString mAccountKeyList;
|
||||
|
||||
|
@ -127,6 +130,10 @@ private:
|
|||
// empty trash on exit
|
||||
static PRBool PR_CALLBACK emptyTrashOnExit(nsHashKey *aKey, void *aData,
|
||||
void *closure);
|
||||
|
||||
// cleanup inbox on exit
|
||||
static PRBool PR_CALLBACK cleanupInboxOnExit(nsHashKey *aKey, void *aData,
|
||||
void *closure);
|
||||
//
|
||||
// account enumerators
|
||||
// ("element" is always an account)
|
||||
|
|
|
@ -349,6 +349,7 @@ NS_IMETHODIMP nsMsgMailSession::RemoveMsgWindow(nsIMsgWindow *msgWindow)
|
|||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
|
||||
kMsgAccountManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
accountManager->CleanupInboxOnExit();
|
||||
accountManager->EmptyTrashOnExit();
|
||||
}
|
||||
return NS_OK;
|
||||
|
|
|
@ -1162,7 +1162,7 @@ nsresult nsMsgFolder::AddSubfolder(nsAutoString *folderName,
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgFolder::Compact()
|
||||
NS_IMETHODIMP nsMsgFolder::Compact(nsIUrlListener *aListener)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
NS_IMETHOD RecursiveDelete(PRBool deleteStorage);
|
||||
NS_IMETHOD CreateSubfolder(const PRUnichar *folderName, nsIMsgWindow *msgWindow);
|
||||
NS_IMETHOD AddSubfolder(nsAutoString *folderName, nsIMsgFolder **newFolder);
|
||||
NS_IMETHOD Compact(void);
|
||||
NS_IMETHOD Compact(nsIUrlListener *aListener);
|
||||
NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener);
|
||||
NS_IMETHOD Rename(const PRUnichar *name, nsIMsgWindow *msgWindow);
|
||||
NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos);
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
NS_IMETHOD AddSubfolderWithPath(nsAutoString *name, nsIFileSpec *dbPath, nsIMsgFolder **child);
|
||||
NS_IMETHODIMP CreateStorageIfMissing(nsIUrlListener* urlListener);
|
||||
|
||||
NS_IMETHOD Compact();
|
||||
NS_IMETHOD Compact(nsIUrlListener *aListener);
|
||||
NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener);
|
||||
NS_IMETHOD Delete ();
|
||||
NS_IMETHOD Rename (const PRUnichar *newName, nsIMsgWindow *msgWindow);
|
||||
|
|
Загрузка…
Ссылка в новой задаче