mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 13:45:27 +00:00
fixed bug 11144 - delete messages from imap trash folder not working
This commit is contained in:
parent
9dc55ef31b
commit
511780f71a
@ -821,14 +821,13 @@ NS_IMETHODIMP
|
|||||||
nsImapMailFolder::MarkMessagesRead(nsISupportsArray *messages, PRBool markRead)
|
nsImapMailFolder::MarkMessagesRead(nsISupportsArray *messages, PRBool markRead)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsMsgKeyArray keysToMarkRead;
|
|
||||||
|
|
||||||
// tell the folder to do it, which will mark them read in the db.
|
// tell the folder to do it, which will mark them read in the db.
|
||||||
rv = nsMsgFolder::MarkMessagesRead(messages, markRead);
|
rv = nsMsgFolder::MarkMessagesRead(messages, markRead);
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
nsCString messageIds;
|
nsCString messageIds;
|
||||||
nsMsgKeyArray srcKeyArray;
|
nsMsgKeyArray keysToMarkRead;
|
||||||
rv = BuildIdsAndKeyArray(messages, messageIds, keysToMarkRead);
|
rv = BuildIdsAndKeyArray(messages, messageIds, keysToMarkRead);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
@ -967,104 +966,81 @@ NS_IMETHODIMP nsImapMailFolder::DeleteMessages(nsISupportsArray *messages,
|
|||||||
nsString2 uri("", eOneByte);
|
nsString2 uri("", eOneByte);
|
||||||
char* hostName = nsnull;
|
char* hostName = nsnull;
|
||||||
char *userName = nsnull;
|
char *userName = nsnull;
|
||||||
|
PRBool isTrashFolder = PR_FALSE;
|
||||||
|
nsCString messageIds;
|
||||||
|
nsMsgKeyArray srcKeyArray;
|
||||||
|
|
||||||
rv = GetHostname(&hostName);
|
rv = BuildIdsAndKeyArray(messages, messageIds, srcKeyArray);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
rv = GetUsername(&userName);
|
rv = GetFlag(MSG_FOLDER_FLAG_TRASH, &isTrashFolder);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_SUCCEEDED(rv) && isTrashFolder)
|
||||||
|
|
||||||
uri.Append(kImapRootURI);
|
|
||||||
uri.Append('/');
|
|
||||||
uri.Append(userName);
|
|
||||||
uri.Append('@');
|
|
||||||
uri.Append(hostName);
|
|
||||||
PR_FREEIF(hostName);
|
|
||||||
PR_FREEIF(userName);
|
|
||||||
|
|
||||||
SetTransactionManager(txnMgr);
|
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
|
|
||||||
if(NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
rv = rdf->GetResource(uri.GetBuffer(), getter_AddRefs(res));
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIFolder>hostFolder(do_QueryInterface(res, &rv));
|
|
||||||
if(NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
rv = hostFolder->GetSubFolders(getter_AddRefs(aEnumerator));
|
|
||||||
if(NS_FAILED(rv)) return rv;
|
|
||||||
|
|
||||||
nsCOMPtr<nsISupports> aItem;
|
|
||||||
nsCOMPtr<nsIMsgFolder> trashFolder;
|
|
||||||
|
|
||||||
rv = aEnumerator->First();
|
|
||||||
while(NS_SUCCEEDED(rv))
|
|
||||||
{
|
{
|
||||||
rv = aEnumerator->CurrentItem(getter_AddRefs(aItem));
|
return StoreImapFlags(kImapMsgDeletedFlag, PR_TRUE, srcKeyArray);
|
||||||
if (NS_FAILED(rv)) break;
|
|
||||||
nsCOMPtr<nsIMsgFolder> aMsgFolder(do_QueryInterface(aItem, &rv));
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
{
|
|
||||||
PRUnichar* aName = nsnull;
|
|
||||||
rv = aMsgFolder->GetName(&aName);
|
|
||||||
if (NS_SUCCEEDED(rv) && nsCRT::strcmp(aName, "Trash") == 0)
|
|
||||||
{
|
|
||||||
delete [] aName;
|
|
||||||
trashFolder = aMsgFolder;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
delete [] aName;
|
|
||||||
}
|
|
||||||
rv = aEnumerator->Next();
|
|
||||||
}
|
}
|
||||||
if(NS_SUCCEEDED(rv) && trashFolder)
|
else
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIMsgFolder> srcFolder;
|
SetTransactionManager(txnMgr);
|
||||||
nsCOMPtr<nsISupports>srcSupport;
|
|
||||||
PRUint32 count = 0;
|
|
||||||
rv = messages->Count(&count);
|
|
||||||
|
|
||||||
rv = QueryInterface(nsIMsgFolder::GetIID(),
|
nsCOMPtr<nsIMsgFolder> rootFolder;
|
||||||
getter_AddRefs(srcFolder));
|
rv = GetRootFolder(getter_AddRefs(rootFolder));
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv) && rootFolder)
|
||||||
srcSupport = do_QueryInterface(srcFolder, &rv);
|
|
||||||
|
|
||||||
nsCString messageIds;
|
|
||||||
nsMsgKeyArray srcKeyArray;
|
|
||||||
rv = BuildIdsAndKeyArray(messages, messageIds, srcKeyArray);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
rv = InitCopyState(srcSupport, messages, PR_TRUE, PR_TRUE, nsnull);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
nsCOMPtr<nsISupports> copySupport = do_QueryInterface(m_copyState);
|
|
||||||
m_copyState->m_curIndex = m_copyState->m_totalCount;
|
|
||||||
NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv);
|
|
||||||
if (NS_SUCCEEDED(rv) && imapService)
|
|
||||||
rv = imapService->OnlineMessageCopy(m_eventQueue,
|
|
||||||
this, messageIds.GetBuffer(),
|
|
||||||
trashFolder, PR_TRUE, PR_TRUE,
|
|
||||||
this, nsnull,
|
|
||||||
copySupport);
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
{
|
{
|
||||||
nsImapMoveCopyMsgTxn* undoMsgTxn = new nsImapMoveCopyMsgTxn(
|
nsCOMPtr<nsIMsgFolder> trashFolder;
|
||||||
this, &srcKeyArray, messageIds.GetBuffer(), trashFolder,
|
PRUint32 numFolders = 0;
|
||||||
PR_TRUE, PR_TRUE, m_eventQueue, this);
|
rv = rootFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_TRASH,
|
||||||
|
getter_AddRefs(trashFolder),
|
||||||
|
1, &numFolders);
|
||||||
|
|
||||||
if (undoMsgTxn)
|
if(NS_SUCCEEDED(rv) && trashFolder)
|
||||||
rv = undoMsgTxn->QueryInterface(
|
|
||||||
nsCOMTypeInfo<nsImapMoveCopyMsgTxn>::GetIID(),
|
|
||||||
getter_AddRefs(m_copyState->m_undoMsgTxn) );
|
|
||||||
if (undoMsgTxn)
|
|
||||||
{
|
{
|
||||||
nsString undoString = count > 1 ? "Undo Delete Messages" :
|
nsCOMPtr<nsIMsgFolder> srcFolder;
|
||||||
"Undo Delete Message";
|
nsCOMPtr<nsISupports>srcSupport;
|
||||||
nsString redoString = count > 1 ? "Redo Delete Messages" :
|
PRUint32 count = 0;
|
||||||
"Redo Delete Message";
|
rv = messages->Count(&count);
|
||||||
rv = undoMsgTxn->SetUndoString(&undoString);
|
|
||||||
rv = undoMsgTxn->SetRedoString(&redoString);
|
rv = QueryInterface(nsIMsgFolder::GetIID(),
|
||||||
|
getter_AddRefs(srcFolder));
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
srcSupport = do_QueryInterface(srcFolder, &rv);
|
||||||
|
|
||||||
|
rv = InitCopyState(srcSupport, messages, PR_TRUE, PR_TRUE,
|
||||||
|
nsnull);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
nsCOMPtr<nsISupports> copySupport =
|
||||||
|
do_QueryInterface(m_copyState);
|
||||||
|
m_copyState->m_curIndex = m_copyState->m_totalCount;
|
||||||
|
NS_WITH_SERVICE(nsIImapService, imapService, kCImapService,
|
||||||
|
&rv);
|
||||||
|
if (NS_SUCCEEDED(rv) && imapService)
|
||||||
|
rv = imapService->OnlineMessageCopy(
|
||||||
|
m_eventQueue, this, messageIds.GetBuffer(),
|
||||||
|
trashFolder, PR_TRUE, PR_TRUE, this, nsnull,
|
||||||
|
copySupport);
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
{
|
||||||
|
nsImapMoveCopyMsgTxn* undoMsgTxn = new
|
||||||
|
nsImapMoveCopyMsgTxn(
|
||||||
|
this, &srcKeyArray, messageIds.GetBuffer(),
|
||||||
|
trashFolder, PR_TRUE, PR_TRUE, m_eventQueue, this);
|
||||||
|
|
||||||
|
if (undoMsgTxn)
|
||||||
|
rv = undoMsgTxn->QueryInterface(
|
||||||
|
nsCOMTypeInfo<nsImapMoveCopyMsgTxn>::GetIID(),
|
||||||
|
getter_AddRefs(m_copyState->m_undoMsgTxn) );
|
||||||
|
if (undoMsgTxn)
|
||||||
|
{
|
||||||
|
nsString undoString = count > 1 ?
|
||||||
|
"Undo Delete Messages" :
|
||||||
|
"Undo Delete Message";
|
||||||
|
nsString redoString = count > 1 ?
|
||||||
|
"Redo Delete Messages" :
|
||||||
|
"Redo Delete Message";
|
||||||
|
rv = undoMsgTxn->SetUndoString(&undoString);
|
||||||
|
rv = undoMsgTxn->SetRedoString(&redoString);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1835,22 +1811,28 @@ nsresult nsImapMailFolder::StoreImapFlags(imapMessageFlagsType flags, PRBool add
|
|||||||
if (PR_TRUE/* !NET_IsOffline() */)
|
if (PR_TRUE/* !NET_IsOffline() */)
|
||||||
{
|
{
|
||||||
NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv);
|
NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv);
|
||||||
if (addFlags)
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
nsCString msgIds;
|
if (addFlags)
|
||||||
|
{
|
||||||
AllocateUidStringFromKeyArray(keysToFlag, msgIds);
|
nsCString msgIds;
|
||||||
imapService->AddMessageFlags(m_eventQueue, this, nsnull, nsnull, msgIds, flags, PR_TRUE);
|
|
||||||
}
|
AllocateUidStringFromKeyArray(keysToFlag, msgIds);
|
||||||
else
|
imapService->AddMessageFlags(m_eventQueue, this, nsnull,
|
||||||
{
|
nsnull, msgIds, flags, PR_TRUE);
|
||||||
nsCString msgIds;
|
}
|
||||||
|
else
|
||||||
AllocateUidStringFromKeyArray(keysToFlag, msgIds);
|
{
|
||||||
imapService->SubtractMessageFlags(m_eventQueue, this, nsnull, nsnull, msgIds, flags, PR_TRUE);
|
nsCString msgIds;
|
||||||
}
|
|
||||||
// If we are not offline, we want to add the flag changes to the server
|
AllocateUidStringFromKeyArray(keysToFlag, msgIds);
|
||||||
// use the imap service to add or remove flags.
|
imapService->SubtractMessageFlags(m_eventQueue, this, nsnull,
|
||||||
|
nsnull, msgIds, flags,
|
||||||
|
PR_TRUE);
|
||||||
|
}
|
||||||
|
// force to update the thread pane view
|
||||||
|
rv = imapService->SelectFolder(m_eventQueue, this, this, nsnull);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user