mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 09:19:28 +00:00
hook up some of the stuff for syncing folders
This commit is contained in:
parent
37eb214e56
commit
3a28d48c25
@ -29,6 +29,7 @@ EXPORTS = \
|
||||
nsIImapMiscellaneous.h \
|
||||
nsIImapService.h \
|
||||
nsIImapIncomingServer.h \
|
||||
nsIImapFlagAndUidState.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE= mailnews
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
NS_IMETHOD GetThreadEventQueue(PLEventQueue **aEventQueue) = 0;
|
||||
|
||||
NS_IMETHOD NotifyFEEventCompletion() = 0;
|
||||
|
||||
NS_IMETHOD NotifyHdrsToDownload(PRUint32 *keys, PRUint32 keyCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIImapProtocol_h___ */
|
||||
|
@ -21,6 +21,40 @@
|
||||
#include "nsImapCore.h"
|
||||
#include "nsImapFlagAndUidState.h"
|
||||
|
||||
NS_IMETHODIMP nsImapFlagAndUidState::GetNumberOfMessages(PRInt32 *result)
|
||||
{
|
||||
if (!result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*result = fNumberOfMessagesAdded;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImapFlagAndUidState::GetUidOfMessage(PRInt32 zeroBasedIndex, PRUint32 *result)
|
||||
{
|
||||
if (!result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (zeroBasedIndex < fNumberOfMessagesAdded)
|
||||
*result = fUids[zeroBasedIndex];
|
||||
else
|
||||
*result = -1; // so that value is non-zero and we don't ask for bad msgs
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImapFlagAndUidState::GetMessageFlags(PRInt32 zeroBasedIndex, imapMessageFlagsType *result)
|
||||
{
|
||||
if (!result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
imapMessageFlagsType returnFlags = kNoImapMsgFlag;
|
||||
if (zeroBasedIndex < fNumberOfMessagesAdded)
|
||||
returnFlags = fFlags[zeroBasedIndex];
|
||||
|
||||
*result = returnFlags;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* amount to expand for imap entry flags when we need more */
|
||||
|
||||
nsImapFlagAndUidState::nsImapFlagAndUidState(PRInt32 numberOfMessages, PRUint16 flags)
|
||||
@ -146,11 +180,6 @@ void nsImapFlagAndUidState::AddUidFlagPair(PRUint32 uid, imapMessageFlagsType fl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsImapFlagAndUidState::GetNumberOfMessages()
|
||||
{
|
||||
return fNumberOfMessagesAdded;
|
||||
}
|
||||
|
||||
PRInt32 nsImapFlagAndUidState::GetNumberOfDeletedMessages()
|
||||
{
|
||||
@ -176,7 +205,7 @@ PRUint32 nsImapFlagAndUidState::GetHighestNonDeletedUID()
|
||||
// Has the user read the last message here ? Used when we first open the inbox to see if there
|
||||
// really is new mail there.
|
||||
|
||||
XP_Bool nsImapFlagAndUidState::IsLastMessageUnseen()
|
||||
PRBool nsImapFlagAndUidState::IsLastMessageUnseen()
|
||||
{
|
||||
PRUint32 index = fNumberOfMessagesAdded;
|
||||
|
||||
@ -190,19 +219,12 @@ XP_Bool nsImapFlagAndUidState::IsLastMessageUnseen()
|
||||
}
|
||||
|
||||
|
||||
PRUint32 nsImapFlagAndUidState::GetUidOfMessage(PRInt32 zeroBasedIndex)
|
||||
{
|
||||
if (zeroBasedIndex < fNumberOfMessagesAdded)
|
||||
return fUids[zeroBasedIndex];
|
||||
return (-1); // so that value is non-zero and we don't ask for bad msgs
|
||||
}
|
||||
|
||||
|
||||
// find a message flag given a key with non-recursive binary search, since some folders
|
||||
// may have thousand of messages, once we find the key set its index, or the index of
|
||||
// where the key should be inserted
|
||||
|
||||
imapMessageFlagsType nsImapFlagAndUidState::GetMessageFlagsFromUID(PRUint32 uid, XP_Bool *foundIt, PRInt32 *ndx)
|
||||
imapMessageFlagsType nsImapFlagAndUidState::GetMessageFlagsFromUID(PRUint32 uid, PRBool *foundIt, PRInt32 *ndx)
|
||||
{
|
||||
PRInt32 index = 0;
|
||||
PRInt32 hi = fNumberOfMessagesAdded - 1;
|
||||
@ -235,60 +257,3 @@ imapMessageFlagsType nsImapFlagAndUidState::GetMessageFlagsFromUID(PRUint32 uid,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
imapMessageFlagsType nsImapFlagAndUidState::GetMessageFlags(PRInt32 zeroBasedIndex)
|
||||
{
|
||||
imapMessageFlagsType returnFlags = kNoImapMsgFlag;
|
||||
if (zeroBasedIndex < fNumberOfMessagesAdded)
|
||||
returnFlags = fFlags[zeroBasedIndex];
|
||||
|
||||
return returnFlags;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
nsImapFlagAndUidState *IMAP_CreateFlagState(PRInt32 numberOfMessages)
|
||||
{
|
||||
return new nsImapFlagAndUidState(numberOfMessages);
|
||||
}
|
||||
|
||||
|
||||
void IMAP_DeleteFlagState(nsImapFlagAndUidState *state)
|
||||
{
|
||||
delete state;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 IMAP_GetFlagStateNumberOfMessages(nsImapFlagAndUidState *state)
|
||||
{
|
||||
return state->GetNumberOfMessages();
|
||||
}
|
||||
|
||||
|
||||
PRUint32 IMAP_GetUidOfMessage(PRInt32 zeroBasedIndex, nsImapFlagAndUidState *state)
|
||||
{
|
||||
return state->GetUidOfMessage(zeroBasedIndex);
|
||||
}
|
||||
|
||||
|
||||
imapMessageFlagsType IMAP_GetMessageFlags(PRInt32 zeroBasedIndex, nsImapFlagAndUidState *state)
|
||||
{
|
||||
return state->GetMessageFlags(zeroBasedIndex);
|
||||
}
|
||||
|
||||
|
||||
imapMessageFlagsType IMAP_GetMessageFlagsFromUID(PRUint32 uid, XP_Bool *foundIt, nsImapFlagAndUidState *state)
|
||||
{
|
||||
PRInt32 index = -1;
|
||||
return state->GetMessageFlagsFromUID(uid, foundIt, &index);
|
||||
}
|
||||
|
||||
XP_Bool IMAP_SupportMessageFlags(nsImapFlagAndUidState *state,
|
||||
imapMessageFlagsType flags)
|
||||
{
|
||||
return (state->GetSupportedUserFlags() & flags);
|
||||
}
|
||||
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
@ -20,20 +20,23 @@
|
||||
#define nsImapFlagAndUidState_h___
|
||||
|
||||
#include "nsMsgKeyArray.h"
|
||||
#include "nsIImapFlagAndUidState.h"
|
||||
|
||||
const PRInt32 kImapFlagAndUidStateSize = 100;
|
||||
|
||||
class nsImapFlagAndUidState {
|
||||
class nsImapFlagAndUidState : public nsIImapFlagAndUidState
|
||||
{
|
||||
public:
|
||||
nsImapFlagAndUidState(int numberOfMessages, PRUint16 flags = 0);
|
||||
nsImapFlagAndUidState(const nsImapFlagAndUidState& state, PRUint16 flags = 0);
|
||||
virtual ~nsImapFlagAndUidState();
|
||||
|
||||
PRInt32 GetNumberOfMessages();
|
||||
PRInt32 GetNumberOfDeletedMessages();
|
||||
NS_IMETHOD GetNumberOfMessages(PRInt32 *result);
|
||||
NS_IMETHOD GetUidOfMessage(PRInt32 zeroBasedIndex, PRUint32 *result);
|
||||
NS_IMETHOD GetMessageFlags(PRInt32 zeroBasedIndex, imapMessageFlagsType *result);
|
||||
|
||||
PRInt32 GetNumberOfDeletedMessages();
|
||||
|
||||
PRUint32 GetUidOfMessage(PRInt32 zeroBasedIndex);
|
||||
imapMessageFlagsType GetMessageFlags(PRInt32 zeroBasedIndex);
|
||||
imapMessageFlagsType GetMessageFlagsFromUID(PRUint32 uid, PRBool *foundIt, PRInt32 *ndx);
|
||||
PRBool IsLastMessageUnseen(void);
|
||||
void ExpungeByIndex(PRUint32 index);
|
||||
|
@ -1405,9 +1405,9 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
|
||||
|
||||
// make the parser record these flags
|
||||
nsString2 fetchStr;
|
||||
PRUint32 added = 0, deleted = 0;
|
||||
PRInt32 added = 0, deleted = 0;
|
||||
|
||||
added = m_flagState.GetNumberOfMessages();
|
||||
nsresult res = m_flagState.GetNumberOfMessages(&added);
|
||||
deleted = m_flagState.GetNumberOfDeletedMessages();
|
||||
|
||||
if (!added || (added == deleted))
|
||||
@ -1438,28 +1438,15 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
|
||||
mailbox_spec *new_spec = GetServerStateParser().CreateCurrentMailboxSpec();
|
||||
if (new_spec && !DeathSignalReceived())
|
||||
{
|
||||
#if 0
|
||||
MWContext *ct = NULL;
|
||||
|
||||
LIBNET_LOCK();
|
||||
if (!DeathSignalReceived())
|
||||
{
|
||||
// if this is an expunge url, libmsg will not ask for headers
|
||||
if (fCurrentUrl->GetIMAPurlType() == TIMAPUrl::kExpungeFolder)
|
||||
nsIImapUrl::nsImapAction imapAction;
|
||||
nsresult res = m_runningUrl->GetImapAction(&imapAction);
|
||||
if (NS_SUCCEEDED(res) && imapAction == nsIImapUrl::nsImapExpungeFolder)
|
||||
new_spec->box_flags |= kJustExpunged;
|
||||
|
||||
ct = new_spec->connection->fCurrentEntry->window_id;
|
||||
ct->imapURLPane = MSG_FindPane(fCurrentEntry->window_id, MSG_ANYPANE);
|
||||
}
|
||||
LIBNET_UNLOCK();
|
||||
if (ct)
|
||||
{
|
||||
if (!ct->currentIMAPfolder)
|
||||
ct->currentIMAPfolder = (MSG_IMAPFolderInfoMail *) MSG_FindImapFolder(ct->imapURLPane, fCurrentUrl->GetUrlHost(), "INBOX"); // use real folder name
|
||||
PR_EnterMonitor(fWaitForBodyIdsMonitor);
|
||||
PR_EnterMonitor(m_waitForBodyIdsMonitor);
|
||||
UpdatedMailboxSpec(new_spec);
|
||||
}
|
||||
#endif // 0
|
||||
}
|
||||
else if (!new_spec)
|
||||
HandleMemoryFailure();
|
||||
@ -1497,6 +1484,10 @@ void nsImapProtocol::ProcessMailboxUpdate(PRBool handlePossibleUndo)
|
||||
GetServerStateParser().ResetFlagInfo(0);
|
||||
}
|
||||
|
||||
void nsImapProtocol::UpdatedMailboxSpec(mailbox_spec *aSpec)
|
||||
{
|
||||
m_imapMailfolder->UpdateImapMailboxInfo(this, aSpec);
|
||||
}
|
||||
|
||||
void nsImapProtocol::FolderHeaderDump(PRUint32 *msgUids, PRUint32 msgCount)
|
||||
{
|
||||
@ -1545,8 +1536,10 @@ void nsImapProtocol::WaitForPotentialListOfMsgsToFetch(PRUint32 **msgIdList, PRU
|
||||
PR_ExitMonitor(m_fetchMsgListMonitor);
|
||||
}
|
||||
|
||||
|
||||
void nsImapProtocol::NotifyKeyList(PRUint32 *keys, PRUint32 keyCount)
|
||||
// libmsg uses this to notify a running imap url about the message headers it should
|
||||
// download while opening a folder. Generally, the imap thread will be blocked
|
||||
// in WaitForPotentialListOfMsgsToFetch waiting for this notification.
|
||||
NS_IMETHODIMP nsImapProtocol::NotifyHdrsToDownload(PRUint32 *keys, PRUint32 keyCount)
|
||||
{
|
||||
PR_EnterMonitor(m_fetchMsgListMonitor);
|
||||
m_fetchMsgIdList = keys;
|
||||
@ -1554,6 +1547,7 @@ void nsImapProtocol::NotifyKeyList(PRUint32 *keys, PRUint32 keyCount)
|
||||
m_fetchMsgListIsNew = TRUE;
|
||||
PR_Notify(m_fetchMsgListMonitor);
|
||||
PR_ExitMonitor(m_fetchMsgListMonitor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsImapProtocol::FolderMsgDumpLoop(PRUint32 *msgUids, PRUint32 msgCount, nsIMAPeFetchFields fields)
|
||||
|
@ -79,6 +79,10 @@ public:
|
||||
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax) { return NS_OK;}
|
||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg) { return NS_OK;}
|
||||
|
||||
// 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);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// End of nsIStreamListenerSupport
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -247,12 +251,12 @@ private:
|
||||
virtual void ProcessCurrentURL();
|
||||
virtual void ParseIMAPandCheckForNewMail(char* commandString = nsnull);
|
||||
|
||||
// listing header functions
|
||||
// folder opening and listing header functions
|
||||
void UpdatedMailboxSpec(mailbox_spec *aSpec);
|
||||
void FolderHeaderDump(PRUint32 *msgUids, PRUint32 msgCount);
|
||||
void FolderMsgDump(PRUint32 *msgUids, PRUint32 msgCount, nsIMAPeFetchFields fields);
|
||||
void FolderMsgDumpLoop(PRUint32 *msgUids, PRUint32 msgCount, nsIMAPeFetchFields fields);
|
||||
void WaitForPotentialListOfMsgsToFetch(PRUint32 **msgIdList, PRUint32 &msgCount);
|
||||
void NotifyKeyList(PRUint32 *keys, PRUint32 keyCount);
|
||||
void AllocateImapUidString(PRUint32 *msgUids, PRUint32 msgCount, nsString2 &returnString);
|
||||
void HeaderFetchCompleted();
|
||||
|
||||
|
@ -919,6 +919,8 @@ void nsImapServerResponseParser::numeric_mailbox_data()
|
||||
|
||||
void nsImapServerResponseParser::msg_fetch()
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
// we have not seen a uid response or flags for this fetch, yet
|
||||
fCurrentResponseUID = 0;
|
||||
fCurrentLineContainedFlagInfo = PR_FALSE;
|
||||
@ -934,7 +936,7 @@ void nsImapServerResponseParser::msg_fetch()
|
||||
if (!PL_strcasecmp(fNextToken, "FLAGS"))
|
||||
{
|
||||
if (fCurrentResponseUID == 0)
|
||||
fCurrentResponseUID = fFlagState->GetUidOfMessage(fFetchResponseIndex - 1);
|
||||
res = fFlagState->GetUidOfMessage(fFetchResponseIndex - 1, &fCurrentResponseUID);
|
||||
|
||||
fNextToken = GetNextToken();
|
||||
if (ContinueParse())
|
||||
@ -976,7 +978,7 @@ void nsImapServerResponseParser::msg_fetch()
|
||||
)
|
||||
{
|
||||
if (fCurrentResponseUID == 0)
|
||||
fCurrentResponseUID = fFlagState->GetUidOfMessage(fFetchResponseIndex - 1);
|
||||
fFlagState->GetUidOfMessage(fFetchResponseIndex - 1, &fCurrentResponseUID);
|
||||
|
||||
if (!PL_strcasecmp(fNextToken, "RFC822.HEADER") ||
|
||||
!PL_strcasecmp(fNextToken, "BODY[HEADER]"))
|
||||
@ -1112,7 +1114,7 @@ void nsImapServerResponseParser::msg_fetch()
|
||||
else if (!PL_strcasecmp(fNextToken, "BODYSTRUCTURE"))
|
||||
{
|
||||
if (fCurrentResponseUID == 0)
|
||||
fCurrentResponseUID = fFlagState->GetUidOfMessage(fFetchResponseIndex - 1);
|
||||
fFlagState->GetUidOfMessage(fFetchResponseIndex - 1, &fCurrentResponseUID);
|
||||
bodystructure_data();
|
||||
}
|
||||
else if (!PL_strncasecmp(fNextToken, "BODY[", 5) && PL_strncasecmp(fNextToken, "BODY[]", 6))
|
||||
|
@ -52,6 +52,11 @@
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsXPComCIID.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsMsgDBCID.h"
|
||||
|
||||
#include "nsMsgDatabase.h"
|
||||
|
||||
#include "nsImapFlagAndUidState.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#define NETLIB_DLL "netlib.dll"
|
||||
@ -79,6 +84,7 @@ static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
|
||||
static NS_DEFINE_CID(kImapProtocolCID, NS_IMAPPROTOCOL_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kCImapService, NS_IMAPSERVICE_CID);
|
||||
static NS_DEFINE_CID(kCImapDB, NS_IMAPDB_CID);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@ -257,6 +263,10 @@ protected:
|
||||
PRBool m_protocolInitialized;
|
||||
PLEventQueue *m_eventQueue;
|
||||
|
||||
void FindKeysToAdd(const nsMsgKeyArray &existingKeys, nsMsgKeyArray &keysToFetch, nsImapFlagAndUidState *flagState);
|
||||
void FindKeysToDelete(const nsMsgKeyArray &existingKeys, nsMsgKeyArray &keysToFetch, nsImapFlagAndUidState *flagState);
|
||||
void PrepareToAddHeadersToMailDB(const nsMsgKeyArray &keysToFetch, mailbox_spec *boxSpec);
|
||||
|
||||
};
|
||||
|
||||
nsIMAP4TestDriver::nsIMAP4TestDriver(PLEventQueue *queue)
|
||||
@ -340,15 +350,265 @@ nsIMAP4TestDriver::MailboxDiscoveryDone(nsIImapProtocol* aProtocol)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Tell mail master about the newly selected mailbox
|
||||
// Tell msglib about the newly selected mailbox
|
||||
NS_IMETHODIMP
|
||||
nsIMAP4TestDriver::UpdateImapMailboxInfo(nsIImapProtocol* aProtocol,
|
||||
mailbox_spec* aSpec)
|
||||
{
|
||||
printf("**** nsIMAP4TestDriver::UpdateImapMailboxInfo\r\n");
|
||||
|
||||
nsIMsgDatabase * mailDB = nsnull;
|
||||
nsIMsgDatabase * mailDBFactory;
|
||||
nsresult rv = nsComponentManager::CreateInstance(kCImapDB, nsnull, nsIMsgDatabase::GetIID(), (void **) &mailDBFactory);
|
||||
nsFileSpec dbName(aSpec->allocatedPathName);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && mailDBFactory)
|
||||
{
|
||||
rv = mailDBFactory->Open(dbName, PR_TRUE, (nsIMsgDatabase **) &mailDB, PR_FALSE);
|
||||
}
|
||||
// rv = nsMailDatabase::Open(folder, PR_TRUE, &m_mailDB, PR_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
if (mailDBFactory)
|
||||
NS_RELEASE(mailDBFactory);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aSpec->folderSelected)
|
||||
{
|
||||
nsMsgKeyArray existingKeys;
|
||||
nsMsgKeyArray keysToDelete;
|
||||
nsMsgKeyArray keysToFetch;
|
||||
nsIDBFolderInfo *dbFolderInfo = nsnull;
|
||||
PRInt32 imapUIDValidity = 0;
|
||||
|
||||
rv = mailDB->GetDBFolderInfo(&dbFolderInfo);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && dbFolderInfo)
|
||||
dbFolderInfo->GetImapUidValidity(&imapUIDValidity);
|
||||
mailDB->ListAllKeys(existingKeys);
|
||||
if (mailDB->ListAllOfflineDeletes(&existingKeys) > 0)
|
||||
existingKeys.QuickSort();
|
||||
if ((imapUIDValidity != aSpec->folder_UIDVALIDITY) /* && // if UIDVALIDITY Changed
|
||||
!NET_IsOffline() */)
|
||||
{
|
||||
|
||||
nsIMsgDatabase *saveMailDB = mailDB;
|
||||
#if TRANSFER_INFO
|
||||
TNeoFolderInfoTransfer *originalInfo = NULL;
|
||||
originalInfo = new TNeoFolderInfoTransfer(dbFolderInfo);
|
||||
#endif // 0
|
||||
mailDB->ForceClosed();
|
||||
mailDB = NULL;
|
||||
|
||||
// Remove summary file.
|
||||
dbName.Delete(PR_FALSE);
|
||||
|
||||
// Create a new summary file, update the folder message counts, and
|
||||
// Close the summary file db.
|
||||
rv = mailDBFactory->Open(dbName, PR_TRUE, &mailDB, PR_FALSE);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
#if TRANSFER_INFO
|
||||
if (originalInfo)
|
||||
{
|
||||
originalInfo->TransferFolderInfo(*mailDB->m_dbFolderInfo);
|
||||
delete originalInfo;
|
||||
}
|
||||
SummaryChanged();
|
||||
#endif
|
||||
}
|
||||
// store the new UIDVALIDITY value
|
||||
rv = mailDB->GetDBFolderInfo(&dbFolderInfo);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && dbFolderInfo)
|
||||
dbFolderInfo->SetImapUidValidity(aSpec->folder_UIDVALIDITY);
|
||||
// delete all my msgs, the keys are bogus now
|
||||
// add every message in this folder
|
||||
existingKeys.RemoveAll();
|
||||
// keysToDelete.CopyArray(&existingKeys);
|
||||
|
||||
if (aSpec->flagState)
|
||||
{
|
||||
nsMsgKeyArray no_existingKeys;
|
||||
FindKeysToAdd(no_existingKeys, keysToFetch, aSpec->flagState);
|
||||
}
|
||||
}
|
||||
else if (!aSpec->flagState /*&& !NET_IsOffline() */) // if there are no messages on the server
|
||||
{
|
||||
keysToDelete.CopyArray(&existingKeys);
|
||||
}
|
||||
else /* if ( !NET_IsOffline()) */
|
||||
{
|
||||
FindKeysToDelete(existingKeys, keysToDelete, aSpec->flagState);
|
||||
|
||||
// if this is the result of an expunge then don't grab headers
|
||||
if (!(aSpec->box_flags & kJustExpunged))
|
||||
FindKeysToAdd(existingKeys, keysToFetch, aSpec->flagState);
|
||||
}
|
||||
|
||||
|
||||
if (keysToDelete.GetSize())
|
||||
{
|
||||
PRUint32 total;
|
||||
|
||||
PRBool highWaterDeleted = FALSE;
|
||||
// It would be nice to notify RDF or whoever of a mass delete here.
|
||||
mailDB->DeleteMessages(&keysToDelete,NULL);
|
||||
total = keysToDelete.GetSize();
|
||||
nsMsgKey highWaterMark = nsMsgKey_None;
|
||||
}
|
||||
if (keysToFetch.GetSize())
|
||||
{
|
||||
PrepareToAddHeadersToMailDB(keysToFetch, aSpec);
|
||||
}
|
||||
else
|
||||
{
|
||||
// let the imap libnet module know that we don't need headers
|
||||
m_IMAP4Protocol->NotifyHdrsToDownload(NULL, 0);
|
||||
// wait until we can get body id monitor before continuing.
|
||||
// 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
|
||||
// NotifyFetchAnyNeededBodies(aSpec->connection, mailDB);
|
||||
// IMAP_BodyIdMonitor(adoptedBoxSpec->connection, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
|
||||
{
|
||||
dbName.Delete(PR_FALSE);
|
||||
}
|
||||
if (mailDBFactory)
|
||||
NS_RELEASE(mailDBFactory);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// both of these algorithms assume that key arrays and flag states are sorted by increasing key.
|
||||
void nsIMAP4TestDriver::FindKeysToDelete(const nsMsgKeyArray &existingKeys, nsMsgKeyArray &keysToDelete, nsImapFlagAndUidState *flagState)
|
||||
{
|
||||
PRBool imapDeleteIsMoveToTrash = /* DeleteIsMoveToTrash() */ PR_TRUE;
|
||||
PRUint32 total = existingKeys.GetSize();
|
||||
PRInt32 index;
|
||||
|
||||
int onlineIndex=0; // current index into flagState
|
||||
for (PRUint32 keyIndex=0; keyIndex < total; keyIndex++)
|
||||
{
|
||||
PRUint32 uidOfMessage;
|
||||
|
||||
flagState->GetNumberOfMessages(&index);
|
||||
while ((onlineIndex < index) &&
|
||||
(flagState->GetUidOfMessage(onlineIndex, &uidOfMessage), (existingKeys[keyIndex] > uidOfMessage) ))
|
||||
{
|
||||
onlineIndex++;
|
||||
}
|
||||
|
||||
imapMessageFlagsType flags;
|
||||
flagState->GetUidOfMessage(onlineIndex, &uidOfMessage);
|
||||
flagState->GetMessageFlags(onlineIndex, &flags);
|
||||
// delete this key if it is not there or marked deleted
|
||||
if ( (onlineIndex >= index ) ||
|
||||
(existingKeys[keyIndex] != uidOfMessage) ||
|
||||
((flags & kImapMsgDeletedFlag) && imapDeleteIsMoveToTrash) )
|
||||
{
|
||||
nsMsgKey doomedKey = existingKeys[keyIndex];
|
||||
if ((PRInt32) doomedKey < 0 && doomedKey != nsMsgKey_None)
|
||||
continue;
|
||||
else
|
||||
keysToDelete.Add(existingKeys[keyIndex]);
|
||||
}
|
||||
|
||||
flagState->GetUidOfMessage(onlineIndex, &uidOfMessage);
|
||||
if (existingKeys[keyIndex] == uidOfMessage)
|
||||
onlineIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
void nsIMAP4TestDriver::FindKeysToAdd(const nsMsgKeyArray &existingKeys, nsMsgKeyArray &keysToFetch, nsImapFlagAndUidState *flagState)
|
||||
{
|
||||
PRBool showDeletedMessages = PR_FALSE /* ShowDeletedMessages() */;
|
||||
|
||||
int dbIndex=0; // current index into existingKeys
|
||||
PRInt32 existTotal, numberOfKnownKeys;
|
||||
PRInt32 index;
|
||||
|
||||
existTotal = numberOfKnownKeys = existingKeys.GetSize();
|
||||
flagState->GetNumberOfMessages(&index);
|
||||
for (PRInt32 flagIndex=0; flagIndex < index; flagIndex++)
|
||||
{
|
||||
PRUint32 uidOfMessage;
|
||||
flagState->GetUidOfMessage(flagIndex, &uidOfMessage);
|
||||
while ( (flagIndex < numberOfKnownKeys) && (dbIndex < existTotal) &&
|
||||
existingKeys[dbIndex] < uidOfMessage)
|
||||
dbIndex++;
|
||||
|
||||
if ( (flagIndex >= numberOfKnownKeys) ||
|
||||
(dbIndex >= existTotal) ||
|
||||
(existingKeys[dbIndex] != uidOfMessage ) )
|
||||
{
|
||||
numberOfKnownKeys++;
|
||||
|
||||
imapMessageFlagsType flags;
|
||||
flagState->GetMessageFlags(flagIndex, &flags);
|
||||
if (showDeletedMessages || ! (flags & kImapMsgDeletedFlag))
|
||||
{
|
||||
keysToFetch.Add(uidOfMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsIMAP4TestDriver::PrepareToAddHeadersToMailDB(const nsMsgKeyArray &keysToFetch,
|
||||
mailbox_spec *boxSpec)
|
||||
{
|
||||
PRUint32 *theKeys = (PRUint32 *) PR_Malloc( keysToFetch.GetSize() * sizeof(PRUint32) );
|
||||
if (theKeys)
|
||||
{
|
||||
PRUint32 total = keysToFetch.GetSize();
|
||||
|
||||
for (int keyIndex=0; keyIndex < total; keyIndex++)
|
||||
theKeys[keyIndex] = keysToFetch[keyIndex];
|
||||
|
||||
// m_DownLoadState = kDownLoadingAllMessageHeaders;
|
||||
|
||||
nsresult res = NS_OK; /*ImapMailDB::Open(m_pathName,
|
||||
TRUE, // create if necessary
|
||||
&mailDB,
|
||||
m_master,
|
||||
&dbWasCreated); */
|
||||
|
||||
// don't want to download headers in a composition pane
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
#if 0
|
||||
SetParseMailboxState(new ParseIMAPMailboxState(m_master, m_host, this,
|
||||
urlQueue,
|
||||
boxSpec->flagState));
|
||||
boxSpec->flagState = NULL; // adopted by ParseIMAPMailboxState
|
||||
GetParseMailboxState()->SetPane(url_pane);
|
||||
|
||||
GetParseMailboxState()->SetDB(mailDB);
|
||||
GetParseMailboxState()->SetIncrementalUpdate(TRUE);
|
||||
GetParseMailboxState()->SetMaster(m_master);
|
||||
GetParseMailboxState()->SetContext(url_pane->GetContext());
|
||||
GetParseMailboxState()->SetFolder(this);
|
||||
|
||||
GetParseMailboxState()->BeginParsingFolder(0);
|
||||
#endif // 0 hook up parsing later.
|
||||
// the imap libnet module will start downloading message headers imap.h
|
||||
m_IMAP4Protocol->NotifyHdrsToDownload(theKeys, total /*keysToFetch.GetSize() */);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_IMAP4Protocol->NotifyHdrsToDownload(NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIMAP4TestDriver::UpdateImapMailboxStatus(nsIImapProtocol* aProtocol,
|
||||
mailbox_spec* aSpec)
|
||||
|
@ -69,6 +69,8 @@ LCFLAGS=-DNETSCAPE
|
||||
LLIBS= $(LLIBS) ole32.lib \
|
||||
$(LIBNSPR)\
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\msgcoreutil.lib \
|
||||
$(DIST)\lib\xpcom32.lib
|
||||
|
||||
|
||||
@ -78,6 +80,8 @@ LINCS=$(LINCS) -I. \
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\rdfutil \
|
||||
-I$(PUBLIC)\rdf \
|
||||
-I$(PUBLIC)\xpcom
|
||||
|
||||
# clobber and clobber_all will remove the following garbage:
|
||||
|
Loading…
x
Reference in New Issue
Block a user