зеркало из https://github.com/mozilla/gecko-dev.git
90186 r=bienvenu sr=mscott; Sort the keys but keep the hdrs in sync with the keys so that
copying messages works correctly
This commit is contained in:
Родитель
548e6eb3dd
Коммит
3e1cdfbad5
|
@ -1638,6 +1638,31 @@ nsMsgLocalMailFolder::ClearCopyState(PRBool moveCopySucceeded)
|
||||||
if(NS_SUCCEEDED(result) && haveSemaphore)
|
if(NS_SUCCEEDED(result) && haveSemaphore)
|
||||||
ReleaseSemaphore(NS_STATIC_CAST(nsIMsgLocalMailFolder*, this));
|
ReleaseSemaphore(NS_STATIC_CAST(nsIMsgLocalMailFolder*, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsMsgLocalMailFolder::SortMessagesBasedOnKey(nsISupportsArray *messages, nsMsgKeyArray *aKeyArray, nsIMsgFolder *srcFolder)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
PRUint32 numMessages = 0;
|
||||||
|
rv = messages->Count(&numMessages);
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
NS_ASSERTION ((numMessages == aKeyArray->GetSize()), "message array and key array size are not same");
|
||||||
|
rv = messages->Clear();
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
nsCOMPtr <nsIMsgDBHdr> msgHdr;
|
||||||
|
nsCOMPtr<nsIDBFolderInfo> folderInfo;
|
||||||
|
nsCOMPtr<nsIMsgDatabase> db;
|
||||||
|
rv = srcFolder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db));
|
||||||
|
if (NS_SUCCEEDED(rv) && db)
|
||||||
|
for (PRUint32 i=0;i < numMessages; i++)
|
||||||
|
{
|
||||||
|
rv = db->GetMsgHdrForKey(aKeyArray->GetAt(i), getter_AddRefs(msgHdr));
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
if (msgHdr)
|
||||||
|
messages->AppendElement(msgHdr);
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMsgLocalMailFolder::CopyMessages(nsIMsgFolder* srcFolder, nsISupportsArray*
|
nsMsgLocalMailFolder::CopyMessages(nsIMsgFolder* srcFolder, nsISupportsArray*
|
||||||
|
@ -1732,16 +1757,16 @@ nsMsgLocalMailFolder::CopyMessages(nsIMsgFolder* srcFolder, nsISupportsArray*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PRUint32 numMsgs = 0;
|
PRUint32 numMsgs = 0;
|
||||||
messages->Count(&numMsgs);
|
mCopyState->m_messages->Count(&numMsgs);
|
||||||
if (numMsgs > 1 && (protocolType.EqualsIgnoreCase("imap") || protocolType.EqualsIgnoreCase("mailbox")))
|
if (numMsgs > 1 && (protocolType.EqualsIgnoreCase("imap") || protocolType.EqualsIgnoreCase("mailbox")))
|
||||||
{
|
{
|
||||||
mCopyState->m_copyingMultipleMessages = PR_TRUE;
|
mCopyState->m_copyingMultipleMessages = PR_TRUE;
|
||||||
rv = CopyMessagesTo(messages, msgWindow, this, isMove);
|
rv = CopyMessagesTo(mCopyState->m_messages, msgWindow, this, isMove);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsISupports> msgSupport;
|
nsCOMPtr<nsISupports> msgSupport;
|
||||||
msgSupport = getter_AddRefs(messages->ElementAt(0));
|
msgSupport = getter_AddRefs(mCopyState->m_messages->ElementAt(0));
|
||||||
if (msgSupport)
|
if (msgSupport)
|
||||||
{
|
{
|
||||||
rv = CopyMessageTo(msgSupport, this, msgWindow, isMove);
|
rv = CopyMessageTo(msgSupport, this, msgWindow, isMove);
|
||||||
|
@ -2074,7 +2099,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetNewMessages(nsIMsgWindow *aWindow)
|
||||||
nsresult nsMsgLocalMailFolder::WriteStartOfNewMessage()
|
nsresult nsMsgLocalMailFolder::WriteStartOfNewMessage()
|
||||||
{
|
{
|
||||||
mCopyState->m_curDstKey = mCopyState->m_fileStream->tell();
|
mCopyState->m_curDstKey = mCopyState->m_fileStream->tell();
|
||||||
|
|
||||||
// CopyFileMessage() and CopyMessages() from servers other than pop3
|
// CopyFileMessage() and CopyMessages() from servers other than pop3
|
||||||
if (mCopyState->m_parseMsgState)
|
if (mCopyState->m_parseMsgState)
|
||||||
{
|
{
|
||||||
|
@ -2151,7 +2176,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::BeginCopy(nsIMsgDBHdr *message)
|
||||||
if (!mCopyState) return NS_ERROR_NULL_POINTER;
|
if (!mCopyState) return NS_ERROR_NULL_POINTER;
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
mCopyState->m_fileStream->seek(PR_SEEK_END, 0);
|
mCopyState->m_fileStream->seek(PR_SEEK_END, 0);
|
||||||
|
|
||||||
PRInt32 messageIndex = (mCopyState->m_copyingMultipleMessages) ? mCopyState->m_curCopyIndex - 1 : mCopyState->m_curCopyIndex;
|
PRInt32 messageIndex = (mCopyState->m_copyingMultipleMessages) ? mCopyState->m_curCopyIndex - 1 : mCopyState->m_curCopyIndex;
|
||||||
NS_ASSERTION(!mCopyState->m_copyingMultipleMessages || mCopyState->m_curCopyIndex > 0, "mCopyState->m_curCopyIndex invalid");
|
NS_ASSERTION(!mCopyState->m_copyingMultipleMessages || mCopyState->m_curCopyIndex > 0, "mCopyState->m_curCopyIndex invalid");
|
||||||
// by the time we get here, m_curCopyIndex is 1 relative because WriteStartOfNewMessage increments it
|
// by the time we get here, m_curCopyIndex is 1 relative because WriteStartOfNewMessage increments it
|
||||||
|
@ -2196,7 +2221,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::CopyData(nsIInputStream *aIStream, PRInt32 a
|
||||||
mCopyState->m_leftOver += readCount;
|
mCopyState->m_leftOver += readCount;
|
||||||
mCopyState->m_dataBuffer[mCopyState->m_leftOver] ='\0';
|
mCopyState->m_dataBuffer[mCopyState->m_leftOver] ='\0';
|
||||||
start = mCopyState->m_dataBuffer;
|
start = mCopyState->m_dataBuffer;
|
||||||
|
|
||||||
end = PL_strstr(start, "\r");
|
end = PL_strstr(start, "\r");
|
||||||
if (!end)
|
if (!end)
|
||||||
end = PL_strstr(start, "\n");
|
end = PL_strstr(start, "\n");
|
||||||
|
@ -2322,7 +2346,10 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded)
|
||||||
mCopyState->m_fromLineSeen = PR_FALSE;
|
mCopyState->m_fromLineSeen = PR_FALSE;
|
||||||
// flush the copied message.
|
// flush the copied message.
|
||||||
if (mCopyState->m_fileStream)
|
if (mCopyState->m_fileStream)
|
||||||
mCopyState->m_fileStream->flush();
|
{
|
||||||
|
rv = mCopyState->m_fileStream->flush();
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Copy the header to the new database
|
//Copy the header to the new database
|
||||||
if(copySucceeded && mCopyState->m_message)
|
if(copySucceeded && mCopyState->m_message)
|
||||||
|
@ -2625,6 +2652,10 @@ nsresult nsMsgLocalMailFolder::CopyMessagesTo(nsISupportsArray *messages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
keyArray.QuickSort();
|
||||||
|
rv = SortMessagesBasedOnKey(messages, &keyArray, srcFolder);
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
nsCOMPtr<nsIStreamListener>
|
nsCOMPtr<nsIStreamListener>
|
||||||
streamListener(do_QueryInterface(copyStreamListener));
|
streamListener(do_QueryInterface(copyStreamListener));
|
||||||
if(!streamListener)
|
if(!streamListener)
|
||||||
|
|
|
@ -181,6 +181,7 @@ protected:
|
||||||
|
|
||||||
// copy message helper
|
// copy message helper
|
||||||
nsresult DisplayMoveCopyStatusMsg();
|
nsresult DisplayMoveCopyStatusMsg();
|
||||||
|
nsresult SortMessagesBasedOnKey(nsISupportsArray *messages, nsMsgKeyArray *aKeyArray, nsIMsgFolder *srcFolder);
|
||||||
|
|
||||||
nsresult CopyMessageTo(nsISupports *message, nsIMsgFolder *dstFolder,
|
nsresult CopyMessageTo(nsISupports *message, nsIMsgFolder *dstFolder,
|
||||||
nsIMsgWindow *msgWindow, PRBool isMove);
|
nsIMsgWindow *msgWindow, PRBool isMove);
|
||||||
|
|
|
@ -133,7 +133,6 @@ nsresult nsMailboxService::CopyMessages(nsMsgKeyArray *msgKeys,
|
||||||
nsCOMPtr<nsIMsgMailNewsUrl> msgUrl (do_QueryInterface(url));
|
nsCOMPtr<nsIMsgMailNewsUrl> msgUrl (do_QueryInterface(url));
|
||||||
nsCOMPtr<nsIMailboxUrl> mailboxUrl (do_QueryInterface(url));
|
nsCOMPtr<nsIMailboxUrl> mailboxUrl (do_QueryInterface(url));
|
||||||
msgUrl->SetMsgWindow(aMsgWindow);
|
msgUrl->SetMsgWindow(aMsgWindow);
|
||||||
msgKeys->QuickSort(); // sort the keys, which might reduce seeking while move/copying
|
|
||||||
|
|
||||||
mailboxUrl->SetMoveCopyMsgKeys(msgKeys->GetArray(), msgKeys->GetSize());
|
mailboxUrl->SetMoveCopyMsgKeys(msgKeys->GetArray(), msgKeys->GetSize());
|
||||||
rv = RunMailboxUrl(url, aMailboxCopyHandler);
|
rv = RunMailboxUrl(url, aMailboxCopyHandler);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче