get set up for folder parsingof msg headers

This commit is contained in:
bienvenu%netscape.com 1999-04-17 03:40:14 +00:00
Родитель e4e56299a0
Коммит d031dfa689
7 изменённых файлов: 383 добавлений и 4 удалений

Просмотреть файл

@ -60,6 +60,16 @@ public:
PRBool* aBool) = 0;
NS_IMETHOD FolderIsNoSelect(nsIImapProtocol* aProtocol,
FolderQueryInfo* aInfo) = 0;
NS_IMETHOD SetupHeaderParseStream(nsIImapProtocol* aProtocol,
StreamInfo* aStreamInfo) = 0;
NS_IMETHOD ParseAdoptedHeaderLine(nsIImapProtocol* aProtocol,
msg_line_info* aMsgLineInfo) = 0;
NS_IMETHOD NormalEndHeaderParseStream(nsIImapProtocol* aProtocol) = 0;
NS_IMETHOD AbortHeaderParseStream(nsIImapProtocol* aProtocol) = 0;
};

Просмотреть файл

@ -68,6 +68,7 @@ public:
NS_IMETHOD NotifyFEEventCompletion() = 0;
NS_IMETHOD NotifyHdrsToDownload(PRUint32 *keys, PRUint32 keyCount) = 0;
NS_IMETHOD NotifyBodysToDownload(PRUint32 *keys, PRUint32 keyCount) = 0;
};
#endif /* nsIImapProtocol_h___ */

Просмотреть файл

@ -174,6 +174,7 @@ nsImapProtocol::nsImapProtocol() :
m_eventCompletionMonitor = nsnull;
m_waitForBodyIdsMonitor = nsnull;
m_fetchMsgListMonitor = nsnull;
m_fetchBodyListMonitor = nsnull;
m_imapThreadIsRunning = PR_FALSE;
m_consumer = nsnull;
m_currentServerCommandTagNumber = 0;
@ -207,6 +208,7 @@ nsImapProtocol::nsImapProtocol() :
m_promoteNoopToCheckCount = 0;
m_mailToFetch = PR_FALSE;
m_fetchMsgListIsNew = PR_FALSE;
m_fetchBodyListIsNew = PR_FALSE;
m_checkForNewMailDownloadsHeaders = PR_TRUE; // this should be on by default
m_hierarchyNameState = kNoOperationInProgress;
@ -250,6 +252,7 @@ nsresult nsImapProtocol::Initialize(nsIImapHostSessionList * aHostSessionList, P
m_eventCompletionMonitor = PR_NewMonitor();
m_waitForBodyIdsMonitor = PR_NewMonitor();
m_fetchMsgListMonitor = PR_NewMonitor();
m_fetchBodyListMonitor = PR_NewMonitor();
m_thread = PR_CreateThread(PR_USER_THREAD, ImapThreadMain, (void*)
this, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
@ -327,6 +330,11 @@ nsImapProtocol::~nsImapProtocol()
PR_DestroyMonitor(m_fetchMsgListMonitor);
m_fetchMsgListMonitor = nsnull;
}
if (m_fetchBodyListMonitor)
{
PR_DestroyMonitor(m_fetchBodyListMonitor);
m_fetchBodyListMonitor = nsnull;
}
}
const char*
@ -2425,7 +2433,7 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
// wait for a list of bodies to fetch.
if (!DeathSignalReceived() && GetServerStateParser().LastCommandSuccessful())
{
WaitForPotentialListOfMsgsToFetch(&msgIdList, msgCount);
WaitForPotentialListOfBodysToFetch(&msgIdList, msgCount);
if ( msgCount && !DeathSignalReceived() && GetServerStateParser().LastCommandSuccessful())
{
FolderMsgDump(msgIdList, msgCount, kEveryThingRFC822Peek);
@ -2488,6 +2496,21 @@ void nsImapProtocol::WaitForPotentialListOfMsgsToFetch(PRUint32 **msgIdList, PRU
PR_ExitMonitor(m_fetchMsgListMonitor);
}
void nsImapProtocol::WaitForPotentialListOfBodysToFetch(PRUint32 **msgIdList, PRUint32 &msgCount)
{
PRIntervalTime sleepTime = kImapSleepTime;
PR_EnterMonitor(m_fetchBodyListMonitor);
while(!m_fetchBodyListIsNew && !DeathSignalReceived())
PR_Wait(m_fetchBodyListMonitor, sleepTime);
m_fetchBodyListIsNew = FALSE;
*msgIdList = m_fetchBodyIdList;
msgCount = m_fetchBodyCount;
PR_ExitMonitor(m_fetchBodyListMonitor);
}
#if 0
void nsImapProtocol::NotifyKeyList(PRUint32 *keys, PRUint32 keyCount)
@ -2507,6 +2530,20 @@ NS_IMETHODIMP nsImapProtocol::NotifyHdrsToDownload(PRUint32 *keys, PRUint32 keyC
return NS_OK;
}
// libmsg uses this to notify a running imap url about message bodies it should download.
// why not just have libmsg explicitly download the message bodies?
NS_IMETHODIMP nsImapProtocol::NotifyBodysToDownload(PRUint32 *keys, PRUint32 keyCount)
{
PR_EnterMonitor(m_fetchBodyListMonitor);
m_fetchBodyIdList = keys;
m_fetchBodyCount = keyCount;
m_fetchBodyListIsNew = TRUE;
PR_Notify(m_fetchBodyListMonitor);
PR_ExitMonitor(m_fetchBodyListMonitor);
return NS_OK;
}
void nsImapProtocol::FolderMsgDumpLoop(PRUint32 *msgUids, PRUint32 msgCount, nsIMAPeFetchFields fields)
{
// PastPasswordCheckEvent();

Просмотреть файл

@ -92,7 +92,7 @@ public:
// This is evil, I guess, but this is used by libmsg to tell a running imap url
// about headers it should download to update a local database.
NS_IMETHOD NotifyHdrsToDownload(PRUint32 *keys, PRUint32 keyCount);
NS_IMETHOD NotifyBodysToDownload(PRUint32 *keys, PRUint32 keyCount);
////////////////////////////////////////////////////////////////////////////////////////
// End of nsIStreamListenerSupport
////////////////////////////////////////////////////////////////////////////////////////
@ -282,6 +282,7 @@ private:
PRMonitor *m_eventCompletionMonitor;
PRMonitor *m_waitForBodyIdsMonitor;
PRMonitor *m_fetchMsgListMonitor;
PRMonitor *m_fetchBodyListMonitor;
PRBool m_imapThreadIsRunning;
static void ImapThreadMain(void *aParm);
@ -322,6 +323,7 @@ private:
void FolderMsgDump(PRUint32 *msgUids, PRUint32 msgCount, nsIMAPeFetchFields fields);
void FolderMsgDumpLoop(PRUint32 *msgUids, PRUint32 msgCount, nsIMAPeFetchFields fields);
void WaitForPotentialListOfMsgsToFetch(PRUint32 **msgIdList, PRUint32 &msgCount);
void WaitForPotentialListOfBodysToFetch(PRUint32 **msgIdList, PRUint32 &msgCount);
void AllocateImapUidString(PRUint32 *msgUids, PRUint32 msgCount, nsString2 &returnString);
void HeaderFetchCompleted();
@ -332,6 +334,9 @@ private:
PRBool m_fetchMsgListIsNew;
PRUint32 m_fetchCount;
PRUint32 *m_fetchMsgIdList;
PRBool m_fetchBodyListIsNew;
PRUint32 m_fetchBodyCount;
PRUint32 *m_fetchBodyIdList;
// initialization function given a new url and transport layer
void SetupWithUrl(nsIURL * aURL);

Просмотреть файл

@ -479,6 +479,107 @@ nsImapMailFolderProxy::FolderIsNoSelect(nsIImapProtocol* aProtocol,
return res;
}
NS_IMETHODIMP
nsImapMailFolderProxy::SetupHeaderParseStream(nsIImapProtocol* aProtocol,
StreamInfo* aStreamInfo)
{
nsresult res = NS_OK;
NS_PRECONDITION (aStreamInfo, "Oops... null aStreamInfo");
if(!aStreamInfo)
return NS_ERROR_NULL_POINTER;
NS_ASSERTION (m_protocol == aProtocol, "Ooh ooh, wrong protocol");
if (PR_GetCurrentThread() == m_thread)
{
SetupHeaderParseStreamProxyEvent *ev =
new SetupHeaderParseStreamProxyEvent(this, aStreamInfo);
if(nsnull == ev)
res = NS_ERROR_OUT_OF_MEMORY;
else
ev->PostEvent(m_eventQueue);
}
else
{
res = m_realImapMailFolder->SetupHeaderParseStream(aProtocol, aStreamInfo);
aProtocol->NotifyFEEventCompletion();
}
return res;
}
NS_IMETHODIMP
nsImapMailFolderProxy::ParseAdoptedHeaderLine(nsIImapProtocol* aProtocol,
msg_line_info* aMsgLineInfo)
{
nsresult res = NS_OK;
NS_PRECONDITION (aMsgLineInfo, "Oops... null aMsgLineInfo");
if(!aMsgLineInfo)
return NS_ERROR_NULL_POINTER;
NS_ASSERTION (m_protocol == aProtocol, "Ooh ooh, wrong protocol");
if (PR_GetCurrentThread() == m_thread)
{
ParseAdoptedHeaderLineProxyEvent *ev =
new ParseAdoptedHeaderLineProxyEvent(this, aMsgLineInfo);
if(nsnull == ev)
res = NS_ERROR_OUT_OF_MEMORY;
else
ev->PostEvent(m_eventQueue);
}
else
{
res = m_realImapMailFolder->ParseAdoptedHeaderLine(aProtocol, aMsgLineInfo);
aProtocol->NotifyFEEventCompletion();
}
return res;
}
NS_IMETHODIMP
nsImapMailFolderProxy::NormalEndHeaderParseStream(nsIImapProtocol* aProtocol)
{
nsresult res = NS_OK;
NS_ASSERTION (m_protocol == aProtocol, "Ooh ooh, wrong protocol");
if (PR_GetCurrentThread() == m_thread)
{
NormalEndHeaderParseStreamProxyEvent *ev =
new NormalEndHeaderParseStreamProxyEvent(this);
if(nsnull == ev)
res = NS_ERROR_OUT_OF_MEMORY;
else
ev->PostEvent(m_eventQueue);
}
else
{
res = m_realImapMailFolder->NormalEndHeaderParseStream(aProtocol);
aProtocol->NotifyFEEventCompletion();
}
return res;
}
NS_IMETHODIMP
nsImapMailFolderProxy::AbortHeaderParseStream(nsIImapProtocol* aProtocol)
{
nsresult res = NS_OK;
NS_ASSERTION (m_protocol == aProtocol, "Ooh ooh, wrong protocol");
if (PR_GetCurrentThread() == m_thread)
{
AbortHeaderParseStreamProxyEvent *ev =
new AbortHeaderParseStreamProxyEvent(this);
if(nsnull == ev)
res = NS_ERROR_OUT_OF_MEMORY;
else
ev->PostEvent(m_eventQueue);
}
else
{
res = m_realImapMailFolder->AbortHeaderParseStream(aProtocol);
aProtocol->NotifyFEEventCompletion();
}
return res;
}
nsImapMessageProxy::nsImapMessageProxy(nsIImapMessage* aImapMessage,
nsIImapProtocol* aProtocol,
PLEventQueue* aEventQ,
@ -1920,6 +2021,144 @@ FolderIsNoSelectProxyEvent::HandleEvent()
return res;
}
///
SetupHeaderParseStreamProxyEvent::SetupHeaderParseStreamProxyEvent(
nsImapMailFolderProxy* aImapFolderProxy,
StreamInfo* aStreamInfo) :
nsImapMailFolderProxyEvent(aImapFolderProxy)
{
NS_ASSERTION (aStreamInfo, "Oops... null stream info");
if (aStreamInfo)
{
m_streamInfo.size = aStreamInfo->size;
m_streamInfo.content_type = PL_strdup(aStreamInfo->content_type);
if (aStreamInfo->boxSpec)
{
m_streamInfo.boxSpec = (mailbox_spec*)
PR_CALLOC(sizeof(mailbox_spec));
*m_streamInfo.boxSpec = *aStreamInfo->boxSpec;
if (aStreamInfo->boxSpec->allocatedPathName)
m_streamInfo.boxSpec->allocatedPathName =
PL_strdup(aStreamInfo->boxSpec->allocatedPathName);
if (aStreamInfo->boxSpec->namespaceForFolder)
m_streamInfo.boxSpec->namespaceForFolder =
new nsIMAPNamespace(
aStreamInfo->boxSpec->namespaceForFolder->GetType(),
aStreamInfo->boxSpec->namespaceForFolder->GetPrefix(),
aStreamInfo->boxSpec->namespaceForFolder->GetDelimiter(),
aStreamInfo->boxSpec->namespaceForFolder->GetIsNamespaceFromPrefs());
}
else
{
m_streamInfo.boxSpec = nsnull;
}
}
else
{
m_streamInfo.size = 0;
m_streamInfo.content_type = nsnull;
m_streamInfo.boxSpec = nsnull;
}
}
SetupHeaderParseStreamProxyEvent::~SetupHeaderParseStreamProxyEvent()
{
if (m_streamInfo.content_type)
PL_strfree(m_streamInfo.content_type);
if (m_streamInfo.boxSpec)
{
if (m_streamInfo.boxSpec->allocatedPathName)
PL_strfree(m_streamInfo.boxSpec->allocatedPathName);
if (m_streamInfo.boxSpec->namespaceForFolder)
delete m_streamInfo.boxSpec->namespaceForFolder;
delete m_streamInfo.boxSpec;
}
}
NS_IMETHODIMP
SetupHeaderParseStreamProxyEvent::HandleEvent()
{
nsresult res = m_proxy->m_realImapMailFolder->SetupHeaderParseStream(
m_proxy->m_protocol, &m_streamInfo);
m_proxy->m_protocol->NotifyFEEventCompletion();
return res;
}
ParseAdoptedHeaderLineProxyEvent::ParseAdoptedHeaderLineProxyEvent(
nsImapMailFolderProxy* aImapFolderProxy,
msg_line_info* aMsgLineInfo) :
nsImapMailFolderProxyEvent(aImapFolderProxy)
{
NS_ASSERTION (aMsgLineInfo, "Oops... null msg_line_info");
if (aMsgLineInfo)
{
m_msgLineInfo.adoptedMessageLine =
PL_strdup(aMsgLineInfo->adoptedMessageLine);
m_msgLineInfo.uidOfMessage = aMsgLineInfo->uidOfMessage;
}
else
{
m_msgLineInfo.adoptedMessageLine = nsnull;
m_msgLineInfo.uidOfMessage = 0xffffffff;
}
}
ParseAdoptedHeaderLineProxyEvent::~ParseAdoptedHeaderLineProxyEvent()
{
if (m_msgLineInfo.adoptedMessageLine)
PL_strfree(m_msgLineInfo.adoptedMessageLine);
}
NS_IMETHODIMP
ParseAdoptedHeaderLineProxyEvent::HandleEvent()
{
nsresult res = m_proxy->m_realImapMailFolder->ParseAdoptedHeaderLine(
m_proxy->m_protocol, &m_msgLineInfo);
m_proxy->m_protocol->NotifyFEEventCompletion();
return res;
}
NormalEndHeaderParseStreamProxyEvent::NormalEndHeaderParseStreamProxyEvent(
nsImapMailFolderProxy* aImapFolderProxy) :
nsImapMailFolderProxyEvent(aImapFolderProxy)
{
}
NormalEndHeaderParseStreamProxyEvent::~NormalEndHeaderParseStreamProxyEvent()
{
}
NS_IMETHODIMP
NormalEndHeaderParseStreamProxyEvent::HandleEvent()
{
nsresult res = m_proxy->m_realImapMailFolder->NormalEndHeaderParseStream(
m_proxy->m_protocol);
m_proxy->m_protocol->NotifyFEEventCompletion();
return res;
}
AbortHeaderParseStreamProxyEvent::AbortHeaderParseStreamProxyEvent(
nsImapMailFolderProxy* aImapFolderProxy) :
nsImapMailFolderProxyEvent(aImapFolderProxy)
{
}
AbortHeaderParseStreamProxyEvent::~AbortHeaderParseStreamProxyEvent()
{
}
NS_IMETHODIMP
AbortHeaderParseStreamProxyEvent::HandleEvent()
{
nsresult res = m_proxy->m_realImapMailFolder->AbortHeaderParseStream(
m_proxy->m_protocol);
m_proxy->m_protocol->NotifyFEEventCompletion();
return res;
}
////
nsImapMessageProxyEvent::nsImapMessageProxyEvent(nsImapMessageProxy* aProxy)
{
NS_ASSERTION (aProxy, "fatal null proxy object");

Просмотреть файл

@ -94,6 +94,16 @@ public:
NS_IMETHOD FolderIsNoSelect(nsIImapProtocol* aProtocol,
FolderQueryInfo* aInfo);
NS_IMETHOD SetupHeaderParseStream(nsIImapProtocol* aProtocol,
StreamInfo* aStreamInfo);
NS_IMETHOD ParseAdoptedHeaderLine(nsIImapProtocol* aProtocol,
msg_line_info* aMsgLineInfo);
NS_IMETHOD NormalEndHeaderParseStream(nsIImapProtocol* aProtocol);
NS_IMETHOD AbortHeaderParseStream(nsIImapProtocol* aProtocol);
nsIImapMailFolder* m_realImapMailFolder;
};
@ -355,6 +365,38 @@ struct FolderIsNoSelectProxyEvent : public nsImapMailFolderProxyEvent
FolderQueryInfo m_folderQueryInfo;
};
struct SetupHeaderParseStreamProxyEvent : public nsImapMailFolderProxyEvent
{
SetupHeaderParseStreamProxyEvent(nsImapMailFolderProxy* aProxy,
StreamInfo* aStreamInfo);
virtual ~SetupHeaderParseStreamProxyEvent();
NS_IMETHOD HandleEvent();
StreamInfo m_streamInfo;
};
struct NormalEndHeaderParseStreamProxyEvent : public nsImapMailFolderProxyEvent
{
NormalEndHeaderParseStreamProxyEvent(nsImapMailFolderProxy* aProxyo);
virtual ~NormalEndHeaderParseStreamProxyEvent();
NS_IMETHOD HandleEvent();
};
struct ParseAdoptedHeaderLineProxyEvent : public nsImapMailFolderProxyEvent
{
ParseAdoptedHeaderLineProxyEvent(nsImapMailFolderProxy* aProxy,
msg_line_info* aMsgLineInfo);
virtual ~ParseAdoptedHeaderLineProxyEvent();
NS_IMETHOD HandleEvent();
msg_line_info m_msgLineInfo;
};
struct AbortHeaderParseStreamProxyEvent : public nsImapMailFolderProxyEvent
{
AbortHeaderParseStreamProxyEvent(nsImapMailFolderProxy* aProxy);
virtual ~AbortHeaderParseStreamProxyEvent();
NS_IMETHOD HandleEvent();
};
struct nsImapMessageProxyEvent : nsImapEvent
{
nsImapMessageProxyEvent(nsImapMessageProxy* aImapMessageProxy);

Просмотреть файл

@ -135,6 +135,16 @@ public:
NS_IMETHOD FolderIsNoSelect(nsIImapProtocol* aProtocol,
FolderQueryInfo* aInfo);
NS_IMETHOD SetupHeaderParseStream(nsIImapProtocol* aProtocol,
StreamInfo* aStreamInfo);
NS_IMETHOD ParseAdoptedHeaderLine(nsIImapProtocol* aProtocol,
msg_line_info* aMsgLineInfo);
NS_IMETHOD NormalEndHeaderParseStream(nsIImapProtocol* aProtocol);
NS_IMETHOD AbortHeaderParseStream(nsIImapProtocol* aProtocol);
// nsIImapMessage support
NS_IMETHOD SetupMsgWriteStream(nsIImapProtocol* aProtocol,
StreamInfo* aStreamInfo);
@ -465,6 +475,8 @@ nsIMAP4TestDriver::UpdateImapMailboxInfo(nsIImapProtocol* aProtocol,
if (keysToFetch.GetSize())
{
PrepareToAddHeadersToMailDB(aProtocol, keysToFetch, aSpec);
if (aProtocol)
aProtocol->NotifyBodysToDownload(NULL, 0/*keysToFetch.GetSize() */);
}
else
{
@ -475,6 +487,8 @@ nsIMAP4TestDriver::UpdateImapMailboxInfo(nsIImapProtocol* aProtocol,
// IMAP_BodyIdMonitor(adoptedBoxSpec->connection, TRUE);
// I think the real fix for this is to seperate the header ids from body id's.
// this is for fetching bodies for offline use
if (aProtocol)
aProtocol->NotifyBodysToDownload(NULL, 0/*keysToFetch.GetSize() */);
// NotifyFetchAnyNeededBodies(aSpec->connection, mailDB);
// IMAP_BodyIdMonitor(adoptedBoxSpec->connection, FALSE);
}
@ -606,11 +620,14 @@ void nsIMAP4TestDriver::PrepareToAddHeadersToMailDB(nsIImapProtocol* aProtocol,
// the imap libnet module will start downloading message headers imap.h
if (aProtocol)
aProtocol->NotifyHdrsToDownload(theKeys, total /*keysToFetch.GetSize() */);
// now, tell it we don't need any bodies.
if (aProtocol)
aProtocol->NotifyHdrsToDownload(NULL, 0);
}
else
{
if (m_IMAP4Protocol)
m_IMAP4Protocol->NotifyHdrsToDownload(NULL, 0);
if (aProtocol)
aProtocol->NotifyHdrsToDownload(NULL, 0);
}
}
}
@ -679,6 +696,34 @@ nsIMAP4TestDriver::FolderIsNoSelect(nsIImapProtocol* aProtocol,
return NS_OK;
}
NS_IMETHODIMP nsIMAP4TestDriver::SetupHeaderParseStream(nsIImapProtocol* aProtocol,
StreamInfo* aStreamInfo)
{
printf("**** nsIMAP4TestDriver::SetupHeaderParseStream\r\n");
return NS_OK;
}
NS_IMETHODIMP nsIMAP4TestDriver::ParseAdoptedHeaderLine(nsIImapProtocol* aProtocol,
msg_line_info* aMsgLineInfo)
{
printf("**** nsIMAP4TestDriver::ParseAdoptedHeaderLine\r\n");
return NS_OK;
}
NS_IMETHODIMP nsIMAP4TestDriver::NormalEndHeaderParseStream(nsIImapProtocol* aProtocol)
{
printf("**** nsIMAP4TestDriver::NormalEndHeaderParseStream\r\n");
return NS_OK;
}
NS_IMETHODIMP nsIMAP4TestDriver::AbortHeaderParseStream(nsIImapProtocol* aProtocol)
{
printf("**** nsIMAP4TestDriver::AbortHeaderParseStream\r\n");
return NS_OK;
}
// nsIImapMessage support
NS_IMETHODIMP