fix problems with auto forward filter action when quaranting incoming pop3 messages, or when message is moved by filter, sr=mscott, a=bsmedberg 299982

This commit is contained in:
bienvenu%nventure.com 2005-07-26 00:18:01 +00:00
parent 8c84ba7125
commit 16101a97a6
3 changed files with 63 additions and 24 deletions

View File

@ -1491,7 +1491,6 @@ nsParseNewMailState::Init(nsIMsgFolder *serverFolder, nsIMsgFolder *downloadFold
if (m_filterList)
{
rv = server->ConfigureTemporaryFilters(m_filterList);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to configure temp filters");
}
// check if this server defers to another server, in which case
// we'll use that server's filters as well.
@ -1814,36 +1813,18 @@ NS_IMETHODIMP nsParseNewMailState::ApplyFilterHit(nsIMsgFilter *filter, nsIMsgWi
{
nsXPIDLCString forwardTo;
filterAction->GetStrValue(getter_Copies(forwardTo));
nsCOMPtr <nsIMsgIncomingServer> server;
rv = m_rootFolder->GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv, rv);
if (!forwardTo.IsEmpty())
{
nsCOMPtr <nsIMsgComposeService> compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ;
if (compService)
{
nsAutoString forwardStr;
forwardStr.AssignWithConversion(forwardTo.get());
rv = compService->ForwardMessage(forwardStr, msgHdr, msgWindow, server);
}
}
m_forwardTo.AppendCString(forwardTo);
m_msgToForwardOrReply = msgHdr;
}
break;
case nsMsgFilterAction::Reply:
{
nsXPIDLCString replyTemplateUri;
filterAction->GetStrValue(getter_Copies(replyTemplateUri));
nsCOMPtr <nsIMsgIncomingServer> server;
rv = m_rootFolder->GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv, rv);
if (!replyTemplateUri.IsEmpty())
{
nsCOMPtr <nsIMsgComposeService> compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ;
if (compService)
rv = compService->ReplyWithTemplate(msgHdr, replyTemplateUri, msgWindow, server);
}
m_replyTemplateUri.AppendCString(replyTemplateUri);
m_msgToForwardOrReply = msgHdr;
}
break;
case nsMsgFilterAction::DeleteFromPop3Server:
{
PRUint32 flags = 0;
@ -1912,6 +1893,51 @@ NS_IMETHODIMP nsParseNewMailState::ApplyFilterHit(nsIMsgFilter *filter, nsIMsgWi
return rv;
}
// this gets run in a second pass, after apply filters to a header.
nsresult nsParseNewMailState::ApplyForwardAndReplyFilter(nsIMsgWindow *msgWindow)
{
nsresult rv = NS_OK;
nsCOMPtr <nsIMsgIncomingServer> server;
for (PRInt32 i = 0; i < m_forwardTo.Count(); i++)
{
if (!m_forwardTo[i]->IsEmpty())
{
nsAutoString forwardStr;
forwardStr.AssignWithConversion(m_forwardTo[i]->get());
rv = m_rootFolder->GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv, rv);
{
nsCOMPtr <nsIMsgComposeService> compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ;
if (compService)
rv = compService->ForwardMessage(forwardStr, m_msgToForwardOrReply, msgWindow, server);
}
}
}
m_forwardTo.Clear();
for (i = 0; i < m_replyTemplateUri.Count(); i++)
{
if (!m_replyTemplateUri[i]->IsEmpty())
{
// copy this and truncate the original, so we don't accidentally re-use it on the next hdr.
nsCAutoString replyTemplateUri(*m_replyTemplateUri[i]);
rv = m_rootFolder->GetServer(getter_AddRefs(server));
if (server && !replyTemplateUri.IsEmpty())
{
nsCOMPtr <nsIMsgComposeService> compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ;
if (compService)
rv = compService->ReplyWithTemplate(m_msgToForwardOrReply, replyTemplateUri.get(), msgWindow, server);
}
}
}
m_replyTemplateUri.Clear();
m_msgToForwardOrReply = nsnull;
return rv;
}
int nsParseNewMailState::MarkFilteredMessageRead(nsIMsgDBHdr *msgHdr)
{
PRUint32 newFlags;
@ -2121,6 +2147,7 @@ nsresult nsParseNewMailState::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr,
}
}
destMailDB->AddNewHdrToDB(newHdr, PR_TRUE);
m_msgToForwardOrReply = newHdr;
}
}
else

View File

@ -248,6 +248,7 @@ public:
PRUint32 length, nsFileSpec &destFileSpec);
virtual void ApplyFilters(PRBool *pMoved, nsIMsgWindow *msgWindow, PRUint32 msgOffset);
nsresult ApplyForwardAndReplyFilter(nsIMsgWindow *msgWindow);
protected:
virtual nsresult GetTrashFolder(nsIMsgFolder **pTrashFolder);
@ -278,6 +279,14 @@ protected:
// used for applying move filters, because in the case of using a temporary
// download file, the offset/key in the msg hdr is not right.
PRUint32 m_curHdrOffset;
// we have to apply the reply/forward filters in a second pass, after
// msg quarantining and moving to other local folders, so we remember the
// info we'll need to apply them with these vars.
// these need to be arrays in case we have multiple reply/forward filters.
nsCStringArray m_forwardTo;
nsCStringArray m_replyTemplateUri;
nsCOMPtr <nsIMsgDBHdr> m_msgToForwardOrReply;
};
#endif

View File

@ -877,6 +877,9 @@ nsPop3Sink::IncorporateComplete(nsIMsgWindow *aMsgWindow, PRInt32 aSize)
m_outFileStream->seek(PR_SEEK_END, 0);
} else
m_newMailParser->PublishMsgHeader(aMsgWindow);
// run any reply/forward filter after we've finished with the
// temp quarantine file, and/or moved the message to another folder.
m_newMailParser->ApplyForwardAndReplyFilter(aMsgWindow);
if (aSize)
hdr->SetUint32Property("onlineSize", aSize);