add more imap protocol logging in attempt to discover why imap connections are getting stuck (221023), r/sr=mscott

This commit is contained in:
bienvenu%nventure.com 2003-10-07 14:56:36 +00:00
parent 1c4c4c930a
commit 0448145fba
3 changed files with 168 additions and 161 deletions

View File

@ -57,7 +57,7 @@
#include "nsIImapUrl.h"
#include "nsIUrlListener.h"
#include "nsIEventQueue.h"
#include "nsIImapProtocol.h"
#include "nsImapProtocol.h"
#include "nsISupportsArray.h"
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
@ -450,6 +450,7 @@ nsImapIncomingServer::GetImapConnectionAndLoadUrl(nsIEventQueue * aClientEventQu
else
{ // unable to get an imap connection to run the url; add to the url
// queue
nsImapProtocol::LogImapUrl("queuing url", aImapUrl);
PR_CEnterMonitor(this);
nsCOMPtr <nsISupports> supports(do_QueryInterface(aImapUrl));
if (supports)
@ -501,6 +502,7 @@ nsImapIncomingServer::LoadNextQueuedUrl(PRBool *aResult)
nsCOMPtr<nsIURI> url = do_QueryInterface(aImapUrl, &rv);
if (NS_SUCCEEDED(rv) && url)
{
nsImapProtocol::LogImapUrl("playing queued url", aImapUrl);
rv = protocolInstance->LoadUrl(url, aConsumer);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed running queued url");
urlRun = PR_TRUE;
@ -2223,115 +2225,120 @@ NS_IMETHODIMP nsImapIncomingServer::FormatStringWithHostNameByID(PRInt32 aMsgId
nsresult nsImapIncomingServer::ResetFoldersToUnverified(nsIFolder *parentFolder)
{
nsresult rv = NS_OK;
if (!parentFolder) {
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
return ResetFoldersToUnverified(rootFolder);
}
else {
nsCOMPtr<nsIEnumerator> subFolders;
nsCOMPtr<nsIMsgImapMailFolder> imapFolder =
do_QueryInterface(parentFolder, &rv);
if (NS_FAILED(rv)) return rv;
rv = imapFolder->SetVerifiedAsOnlineFolder(PR_FALSE);
rv = parentFolder->GetSubFolders(getter_AddRefs(subFolders));
if (NS_FAILED(rv)) return rv;
nsAdapterEnumerator *simpleEnumerator = new
nsAdapterEnumerator(subFolders);
if (!simpleEnumerator) return NS_ERROR_OUT_OF_MEMORY;
PRBool moreFolders = PR_FALSE;
while (NS_SUCCEEDED(simpleEnumerator->HasMoreElements(&moreFolders))
&& moreFolders) {
nsCOMPtr<nsISupports> child;
rv = simpleEnumerator->GetNext(getter_AddRefs(child));
if (NS_SUCCEEDED(rv) && child) {
nsCOMPtr<nsIFolder> childFolder = do_QueryInterface(child,
&rv);
if (NS_SUCCEEDED(rv) && childFolder) {
rv = ResetFoldersToUnverified(childFolder);
if (NS_FAILED(rv)) break;
}
}
nsresult rv = NS_OK;
if (!parentFolder)
{
nsCOMPtr<nsIFolder> rootFolder;
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (NS_FAILED(rv)) return rv;
return ResetFoldersToUnverified(rootFolder);
}
else
{
nsCOMPtr<nsIEnumerator> subFolders;
nsCOMPtr<nsIMsgImapMailFolder> imapFolder =
do_QueryInterface(parentFolder, &rv);
if (NS_FAILED(rv)) return rv;
rv = imapFolder->SetVerifiedAsOnlineFolder(PR_FALSE);
rv = parentFolder->GetSubFolders(getter_AddRefs(subFolders));
if (NS_FAILED(rv)) return rv;
nsAdapterEnumerator *simpleEnumerator = new
nsAdapterEnumerator(subFolders);
if (!simpleEnumerator) return NS_ERROR_OUT_OF_MEMORY;
PRBool moreFolders = PR_FALSE;
while (NS_SUCCEEDED(simpleEnumerator->HasMoreElements(&moreFolders))
&& moreFolders)
{
nsCOMPtr<nsISupports> child;
rv = simpleEnumerator->GetNext(getter_AddRefs(child));
if (NS_SUCCEEDED(rv) && child)
{
nsCOMPtr<nsIFolder> childFolder = do_QueryInterface(child,
&rv);
if (NS_SUCCEEDED(rv) && childFolder)
{
rv = ResetFoldersToUnverified(childFolder);
if (NS_FAILED(rv)) break;
}
delete simpleEnumerator;
}
}
return rv;
delete simpleEnumerator;
}
return rv;
}
nsresult nsImapIncomingServer::GetUnverifiedFolders(nsISupportsArray *aFoldersArray, PRInt32 *aNumUnverifiedFolders)
{
// can't have both be null, but one null is OK, since the caller
// may just be trying to count the number of unverified folders.
if (!aFoldersArray && !aNumUnverifiedFolders)
return NS_ERROR_NULL_POINTER;
if (aNumUnverifiedFolders)
*aNumUnverifiedFolders = 0;
nsCOMPtr<nsIFolder> rootFolder;
nsresult rv = GetRootFolder(getter_AddRefs(rootFolder));
if(NS_SUCCEEDED(rv) && rootFolder)
// can't have both be null, but one null is OK, since the caller
// may just be trying to count the number of unverified folders.
if (!aFoldersArray && !aNumUnverifiedFolders)
return NS_ERROR_NULL_POINTER;
if (aNumUnverifiedFolders)
*aNumUnverifiedFolders = 0;
nsCOMPtr<nsIFolder> rootFolder;
nsresult rv = GetRootFolder(getter_AddRefs(rootFolder));
if(NS_SUCCEEDED(rv) && rootFolder)
{
nsCOMPtr <nsIMsgImapMailFolder> imapRoot = do_QueryInterface(rootFolder);
if (imapRoot)
imapRoot->SetVerifiedAsOnlineFolder(PR_TRUE); // don't need to verify the root.
rv = GetUnverifiedSubFolders(rootFolder, aFoldersArray, aNumUnverifiedFolders);
rv = GetUnverifiedSubFolders(rootFolder, aFoldersArray, aNumUnverifiedFolders);
}
return rv;
return rv;
}
nsresult nsImapIncomingServer::GetUnverifiedSubFolders(nsIFolder *parentFolder, nsISupportsArray *aFoldersArray, PRInt32 *aNumUnverifiedFolders)
{
nsresult rv = NS_OK;
nsCOMPtr <nsIMsgImapMailFolder> imapFolder = do_QueryInterface(parentFolder);
PRBool verified = PR_FALSE, explicitlyVerify = PR_FALSE;
if (imapFolder)
{
rv = imapFolder->GetVerifiedAsOnlineFolder(&verified);
if (NS_SUCCEEDED(rv))
rv = imapFolder->GetExplicitlyVerify(&explicitlyVerify);
if (NS_SUCCEEDED(rv) && (!verified || explicitlyVerify))
{
if (aFoldersArray)
{
nsCOMPtr <nsISupports> supports = do_QueryInterface(imapFolder);
aFoldersArray->AppendElement(supports);
}
if (aNumUnverifiedFolders)
(*aNumUnverifiedFolders)++;
}
}
nsCOMPtr<nsIEnumerator> subFolders;
rv = parentFolder->GetSubFolders(getter_AddRefs(subFolders));
if(NS_SUCCEEDED(rv))
{
nsAdapterEnumerator *simpleEnumerator = new nsAdapterEnumerator(subFolders);
if (simpleEnumerator == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
PRBool moreFolders;
while (NS_SUCCEEDED(simpleEnumerator->HasMoreElements(&moreFolders)) && moreFolders)
{
nsCOMPtr<nsISupports> child;
rv = simpleEnumerator->GetNext(getter_AddRefs(child));
if (NS_SUCCEEDED(rv) && child)
{
nsCOMPtr <nsIFolder> childFolder = do_QueryInterface(child, &rv);
if (NS_SUCCEEDED(rv) && childFolder)
{
rv = GetUnverifiedSubFolders(childFolder, aFoldersArray, aNumUnverifiedFolders);
if (NS_FAILED(rv))
break;
}
}
}
delete simpleEnumerator;
}
return rv;
nsresult rv = NS_OK;
nsCOMPtr <nsIMsgImapMailFolder> imapFolder = do_QueryInterface(parentFolder);
PRBool verified = PR_FALSE, explicitlyVerify = PR_FALSE;
if (imapFolder)
{
rv = imapFolder->GetVerifiedAsOnlineFolder(&verified);
if (NS_SUCCEEDED(rv))
rv = imapFolder->GetExplicitlyVerify(&explicitlyVerify);
if (NS_SUCCEEDED(rv) && (!verified || explicitlyVerify))
{
if (aFoldersArray)
{
nsCOMPtr <nsISupports> supports = do_QueryInterface(imapFolder);
aFoldersArray->AppendElement(supports);
}
if (aNumUnverifiedFolders)
(*aNumUnverifiedFolders)++;
}
}
nsCOMPtr<nsIEnumerator> subFolders;
rv = parentFolder->GetSubFolders(getter_AddRefs(subFolders));
if(NS_SUCCEEDED(rv))
{
nsAdapterEnumerator *simpleEnumerator = new nsAdapterEnumerator(subFolders);
if (simpleEnumerator == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
PRBool moreFolders;
while (NS_SUCCEEDED(simpleEnumerator->HasMoreElements(&moreFolders)) && moreFolders)
{
nsCOMPtr<nsISupports> child;
rv = simpleEnumerator->GetNext(getter_AddRefs(child));
if (NS_SUCCEEDED(rv) && child)
{
nsCOMPtr <nsIFolder> childFolder = do_QueryInterface(child, &rv);
if (NS_SUCCEEDED(rv) && childFolder)
{
rv = GetUnverifiedSubFolders(childFolder, aFoldersArray, aNumUnverifiedFolders);
if (NS_FAILED(rv))
break;
}
}
}
delete simpleEnumerator;
}
return rv;
}
NS_IMETHODIMP nsImapIncomingServer::ForgetSessionPassword()
@ -2414,22 +2421,22 @@ NS_IMETHODIMP nsImapIncomingServer::PromptForPassword(char ** aPassword,
// for the nsIImapServerSink interface
NS_IMETHODIMP nsImapIncomingServer::SetCapability(PRUint32 capability)
{
m_capability = capability;
SetCapabilityPref(capability);
return NS_OK;
m_capability = capability;
SetCapabilityPref(capability);
return NS_OK;
}
NS_IMETHODIMP nsImapIncomingServer::CommitNamespaces()
{
nsresult rv;
nsCOMPtr<nsIImapHostSessionList> hostSession =
do_GetService(kCImapHostSessionListCID, &rv);
if (NS_FAILED(rv))
return rv;
return hostSession->CommitNamespacesForHost(this);
nsresult rv;
nsCOMPtr<nsIImapHostSessionList> hostSession =
do_GetService(kCImapHostSessionListCID, &rv);
if (NS_FAILED(rv))
return rv;
return hostSession->CommitNamespacesForHost(this);
}
NS_IMETHODIMP nsImapIncomingServer::PseudoInterruptMsgLoad(nsIMsgFolder *aImapFolder, nsIMsgWindow *aMsgWindow, PRBool *interrupted)
@ -2470,13 +2477,6 @@ NS_IMETHODIMP nsImapIncomingServer::ResetNamespaceReferences()
return rv;
}
//void MSG_IMAPFolderInfoMail::InitializeFolderCreatedOffline()
//{
// TIMAPNamespace *ns = IMAPNS_GetNamespaceForFolder(m_host->GetHostName(), GetOnlineName(), '/');
// SetOnlineHierarchySeparator(IMAPNS_GetDelimiterForNamespace(ns));
//}
NS_IMETHODIMP nsImapIncomingServer::SetUserAuthenticated(PRBool aUserAuthenticated)
{
m_userAuthenticated = aUserAuthenticated;

View File

@ -1236,11 +1236,9 @@ PRBool nsImapProtocol::ProcessCurrentURL()
// acknowledge that we are running the url now..
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningUrl, &rv);
#ifdef DEBUG_bienvenu1
nsXPIDLCString urlSpec;
mailnewsurl->GetSpec(getter_Copies(urlSpec));
printf("processing url %s\n", (const char *) urlSpec);
#endif
nsCAutoString urlSpec;
mailnewsurl->GetSpec(urlSpec);
Log("ProcessCurrentURL", urlSpec.get(), " = currentUrl");
if (NS_SUCCEEDED(rv) && mailnewsurl && m_imapMailFolderSink)
m_imapMailFolderSink->SetUrlState(this, mailnewsurl, PR_TRUE, NS_OK);
@ -1309,17 +1307,13 @@ PRBool nsImapProtocol::ProcessCurrentURL()
if (mailnewsurl && m_imapMailFolderSink)
{
rv = GetServerStateParser().LastCommandSuccessful() ? NS_OK :
NS_ERROR_FAILURE;
m_imapMailFolderSink->SetUrlState(this, mailnewsurl, PR_FALSE,
rv); // we are done with this
// url.
if (NS_FAILED(rv) && DeathSignalReceived())
{
// doom the cache entry
if (m_mockChannel)
m_mockChannel->Cancel(rv);
}
rv = GetServerStateParser().LastCommandSuccessful()
? NS_OK : NS_ERROR_FAILURE;
// we are done with this url.
m_imapMailFolderSink->SetUrlState(this, mailnewsurl, PR_FALSE, rv);
// doom the cache entry
if (NS_FAILED(rv) && DeathSignalReceived() && m_mockChannel)
m_mockChannel->Cancel(rv);
}
else
NS_ASSERTION(PR_FALSE, "missing url or sink");
@ -3295,15 +3289,15 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
PR_Free(boxName);
}
// fetch the flags and uids of all existing messages or new ones
if (!DeathSignalReceived() && GetServerStateParser().NumberOfMessages())
// fetch the flags and uids of all existing messages or new ones
if (!DeathSignalReceived() && GetServerStateParser().NumberOfMessages())
{
if (handlePossibleUndo)
{
if (handlePossibleUndo)
{
// undo any delete flags we may have asked to
nsXPIDLCString undoIdsStr;
nsCAutoString undoIds;
// undo any delete flags we may have asked to
nsXPIDLCString undoIdsStr;
nsCAutoString undoIds;
GetCurrentUrl()->CreateListOfMessageIdsString(getter_Copies(undoIdsStr));
undoIds.Assign(undoIdsStr);
if (!undoIds.IsEmpty())
@ -3321,7 +3315,7 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
}
}
// make the parser record these flags
// make the parser record these flags
nsCString fetchStr;
PRInt32 added = 0, deleted = 0;
@ -3351,19 +3345,19 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
// sprintf(fetchStr, "%ld:*", GetServerStateParser().HighestRecordedUID() + 1);
FetchMessage(fetchStr.get(), kFlags, PR_TRUE); // only new messages please
}
}
else if (!DeathSignalReceived())
GetServerStateParser().ResetFlagInfo(0);
}
else if (!DeathSignalReceived())
GetServerStateParser().ResetFlagInfo(0);
if (!DeathSignalReceived())
{
nsImapAction imapAction;
nsresult res = m_runningUrl->GetImapAction(&imapAction);
if (NS_SUCCEEDED(res) && imapAction == nsIImapUrl::nsImapLiteSelectFolder)
return;
}
nsImapMailboxSpec *new_spec = GetServerStateParser().CreateCurrentMailboxSpec();
if (!DeathSignalReceived())
{
nsImapAction imapAction;
nsresult res = m_runningUrl->GetImapAction(&imapAction);
if (NS_SUCCEEDED(res) && imapAction == nsIImapUrl::nsImapLiteSelectFolder)
return;
}
nsImapMailboxSpec *new_spec = GetServerStateParser().CreateCurrentMailboxSpec();
if (new_spec && !DeathSignalReceived())
{
if (!DeathSignalReceived())
@ -3378,11 +3372,11 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
}
else if (!new_spec)
HandleMemoryFailure();
// Block until libmsg decides whether to download headers or not.
PRUint32 *msgIdList = nsnull;
PRUint32 msgCount = 0;
if (!DeathSignalReceived())
{
WaitForPotentialListOfMsgsToFetch(&msgIdList, msgCount);
@ -3399,14 +3393,14 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
// this might be bogus, how are we going to do pane notification and stuff when we fetch bodies without
// headers!
}
// wait for a list of bodies to fetch.
if (!DeathSignalReceived() && GetServerStateParser().LastCommandSuccessful())
// wait for a list of bodies to fetch.
if (!DeathSignalReceived() && GetServerStateParser().LastCommandSuccessful())
{
WaitForPotentialListOfBodysToFetch(&msgIdList, msgCount);
if ( msgCount && !DeathSignalReceived() && GetServerStateParser().LastCommandSuccessful())
{
WaitForPotentialListOfBodysToFetch(&msgIdList, msgCount);
if ( msgCount && !DeathSignalReceived() && GetServerStateParser().LastCommandSuccessful())
{
FolderMsgDump(msgIdList, msgCount, kEveryThingRFC822Peek);
}
FolderMsgDump(msgIdList, msgCount, kEveryThingRFC822Peek);
}
}
if (DeathSignalReceived())
GetServerStateParser().ResetFlagInfo(0);
@ -3633,6 +3627,19 @@ PRBool nsImapProtocol::CheckNewMail()
/* static */ void nsImapProtocol::LogImapUrl(const char *logMsg, nsIImapUrl *imapUrl)
{
if (PR_LOG_TEST(IMAP, PR_LOG_ALWAYS))
{
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(imapUrl);
if (mailnewsUrl)
{
nsCAutoString urlSpec;
mailnewsUrl->GetSpec(urlSpec);
PR_LOG(IMAP, PR_LOG_ALWAYS, ("%s:%s", logMsg, urlSpec.get()));
}
}
}
// log info including current state...
void nsImapProtocol::Log(const char *logSubName, const char *extraInfo, const char *logData)

View File

@ -248,7 +248,7 @@ public:
virtual void ProcessMailboxUpdate(PRBool handlePossibleUndo);
// Send log output...
void Log(const char *logSubName, const char *extraInfo, const char *logData);
static void LogImapUrl(const char *logMsg, nsIImapUrl *imapUrl);
// Comment from 4.5: We really need to break out the thread synchronizer from the
// connection class...Not sure what this means
PRBool GetPseudoInterrupted();