From 3dfe86f9b6f10473153f510a5b65df71bd0fd605 Mon Sep 17 00:00:00 2001 From: David Bienvenu Date: Wed, 20 Jan 2010 14:15:44 -0800 Subject: [PATCH] add forward inline filter action, r=rkent, sr=standard8, bug 312025 --- .../base/search/src/nsMsgFilterService.cpp | 23 ++- .../compose/public/nsIMsgComposeService.idl | 18 ++- mailnews/compose/src/nsMsgComposeService.cpp | 143 +++++++++++++----- mailnews/compose/src/nsMsgComposeService.h | 12 +- mailnews/imap/src/nsImapMailFolder.cpp | 11 +- mailnews/local/src/nsParseMailbox.cpp | 9 +- .../mime/public/nsIMimeStreamConverter.idl | 16 +- mailnews/mime/src/mimedrft.cpp | 127 ++++++++++++---- mailnews/mime/src/mimemoz2.h | 2 + mailnews/mime/src/nsStreamConverter.cpp | 42 ++++- mailnews/mime/src/nsStreamConverter.h | 8 +- 11 files changed, 303 insertions(+), 108 deletions(-) diff --git a/mailnews/base/search/src/nsMsgFilterService.cpp b/mailnews/base/search/src/nsMsgFilterService.cpp index 2d0fe62001..cf327c025d 100644 --- a/mailnews/base/search/src/nsMsgFilterService.cpp +++ b/mailnews/base/search/src/nsMsgFilterService.cpp @@ -669,23 +669,22 @@ nsresult nsMsgFilterAfterTheFact::ApplyFilter(PRBool *aApplyMore) { nsCString forwardTo; filterAction->GetStrValue(forwardTo); - nsCOMPtr server; + nsCOMPtr server; rv = m_curFolder->GetServer(getter_AddRefs(server)); NS_ENSURE_SUCCESS(rv, rv); if (!forwardTo.IsEmpty()) { - nsCOMPtr compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ; - if (compService) + nsCOMPtr compService = + do_GetService(NS_MSGCOMPOSESERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + for (PRUint32 msgIndex = 0; msgIndex < m_searchHits.Length(); msgIndex++) { - for (PRUint32 msgIndex = 0; msgIndex < m_searchHits.Length(); msgIndex++) - { - nsCOMPtr msgHdr; - m_searchHitHdrs->QueryElementAt(msgIndex, NS_GET_IID(nsIMsgDBHdr), getter_AddRefs(msgHdr)); - if (msgHdr) - { - rv = compService->ForwardMessage(NS_ConvertASCIItoUTF16(forwardTo), msgHdr, m_msgWindow, server); - } - } + nsCOMPtr msgHdr(do_QueryElementAt(m_searchHitHdrs, + msgIndex)); + if (msgHdr) + rv = compService->ForwardMessage(NS_ConvertASCIItoUTF16(forwardTo), + msgHdr, m_msgWindow, server, + nsIMsgComposeService::kForwardAsDefault); } } } diff --git a/mailnews/compose/public/nsIMsgComposeService.idl b/mailnews/compose/public/nsIMsgComposeService.idl index af9e6d3a90..2a7b9c2f41 100644 --- a/mailnews/compose/public/nsIMsgComposeService.idl +++ b/mailnews/compose/public/nsIMsgComposeService.idl @@ -47,7 +47,7 @@ interface nsIMsgIdentity; interface nsIMsgIncomingServer; interface nsIMsgDBHdr; -[scriptable, uuid(ce5f77c8-f278-4ec7-b8dd-ea9dc84af137)] +[scriptable, uuid(dbf4b3a7-dc38-4362-a620-ff5d22b3777c)] interface nsIMsgComposeService : nsISupports { /* we need a msg window because when we forward inline we may need progress */ @@ -96,15 +96,29 @@ interface nsIMsgComposeService : nsISupports { */ nsIMsgComposeParams getParamsForMailto(in nsIURI aURI); + /** + * @{ + * These constants control how to forward messages in forwardMessage. + * kForwardAsDefault uses value of pref "mail.forward_message_mode". + */ + const unsigned long kForwardAsDefault = 0; + const unsigned long kForwardAsAttachment = 1; + const unsigned long kForwardInline = 2; + /** @} */ + /** * Allow filters to automatically forward a message to the given address(es). * @param forwardTo the address(es) to forward to * @param msgHdr the header of the message being replied to * @param msgWindow message window to use * @param server server to use for determining which account to send from + * @param aForwardType - How to forward the message one of 3 values: + * kForwardAsDefault, kForwardInline, or + * kForwardAsAttachment. */ void forwardMessage(in AString forwardTo, in nsIMsgDBHdr msgHdr, - in nsIMsgWindow msgWindow, in nsIMsgIncomingServer server); + in nsIMsgWindow msgWindow, in nsIMsgIncomingServer server, + in unsigned long aForwardType); /** * Allow filters to automatically reply to a message. The reply message is diff --git a/mailnews/compose/src/nsMsgComposeService.cpp b/mailnews/compose/src/nsMsgComposeService.cpp index 6e5bdc2d3b..6696d85cbd 100644 --- a/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mailnews/compose/src/nsMsgComposeService.cpp @@ -568,7 +568,8 @@ nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, nsIMsgDB return LoadDraftOrTemplate(uriToOpen, type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft ? nsMimeOutput::nsMimeMessageDraftOrTemplate : nsMimeOutput::nsMimeMessageEditorTemplate, - identity, originalMsgURI, origMsgHdr, type == nsIMsgCompType::ForwardInline, format, aMsgWindow); + identity, originalMsgURI, origMsgHdr, type == nsIMsgCompType::ForwardInline, + format == nsIMsgCompFormat::OppositeOfDefault, aMsgWindow); } nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); @@ -1212,12 +1213,56 @@ NS_IMETHODIMP nsMsgComposeService::ReplyWithTemplate(nsIMsgDBHdr *aMsgHdr, const return folder->AddMessageDispositionState(aMsgHdr, nsIMsgFolder::nsMsgDispositionState_Replied); } -NS_IMETHODIMP nsMsgComposeService::ForwardMessage(const nsAString &forwardTo, nsIMsgDBHdr *aMsgHdr, - nsIMsgWindow *aMsgWindow, nsIMsgIncomingServer *aServer) +NS_IMETHODIMP +nsMsgComposeService::ForwardMessage(const nsAString &forwardTo, + nsIMsgDBHdr *aMsgHdr, + nsIMsgWindow *aMsgWindow, + nsIMsgIncomingServer *aServer, + PRUint32 aForwardType) { NS_ENSURE_ARG_POINTER(aMsgHdr); nsresult rv; + if (aForwardType == nsIMsgComposeService::kForwardAsDefault) + { + PRInt32 forwardPref = 0; + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + prefBranch->GetIntPref("mail.forward_message_mode", &forwardPref); + // 0=default as attachment 2=forward as inline with attachments, + // (obsolete 4.x value)1=forward as quoted (mapped to 2 in mozilla) + aForwardType = forwardPref == 0 ? nsIMsgComposeService::kForwardAsAttachment : + nsIMsgComposeService::kForwardInline; + } + nsCString msgUri; + + nsCOMPtr folder; + aMsgHdr->GetFolder(getter_AddRefs(folder)); + if (!folder) + return NS_ERROR_NULL_POINTER; + folder->GetUriForMsg(aMsgHdr, msgUri); + + // get the MsgIdentity for the above key using AccountManager + nsCOMPtr accountManager = + do_GetService (NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr account; + nsCOMPtr identity; + + rv = accountManager->FindAccountForServer(aServer, getter_AddRefs(account)); + NS_ENSURE_SUCCESS(rv, rv); + rv = account->GetDefaultIdentity(getter_AddRefs(identity)); + NS_ENSURE_SUCCESS(rv, rv); + + if (aForwardType == nsIMsgComposeService::kForwardInline) + return RunMessageThroughMimeDraft(msgUri, + nsMimeOutput::nsMimeMessageDraftOrTemplate, + identity, + msgUri.get(), aMsgHdr, + PR_TRUE, forwardTo, + PR_FALSE, aMsgWindow); + nsCOMPtr parentWindow; if (aMsgWindow) { @@ -1227,41 +1272,14 @@ NS_IMETHODIMP nsMsgComposeService::ForwardMessage(const nsAString &forwardTo, ns parentWindow = do_GetInterface(docShell); NS_ENSURE_TRUE(parentWindow, NS_ERROR_FAILURE); } - if ( NS_FAILED(rv) ) return rv ; - // get the MsgIdentity for the above key using AccountManager - nsCOMPtr accountManager = do_GetService (NS_MSGACCOUNTMANAGER_CONTRACTID) ; - if (NS_FAILED(rv) || (!accountManager) ) return rv ; - - nsCOMPtr account; - nsCOMPtr identity; - - rv = accountManager->FindAccountForServer(aServer, getter_AddRefs(account)); - NS_ENSURE_SUCCESS(rv, rv); - account->GetDefaultIdentity(getter_AddRefs(identity)); - NS_ENSURE_SUCCESS(rv, rv); - // create the compose params object nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); - if (NS_FAILED(rv) || (!pMsgComposeParams) ) return rv ; - nsCOMPtr compFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv) ; + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr compFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv); compFields->SetTo(forwardTo); - nsCString msgUri; - PRInt32 forwardType = 0; - - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) - prefBranch->GetIntPref("mail.forward_message_mode", &forwardType); - - nsCOMPtr folder; - aMsgHdr->GetFolder(getter_AddRefs(folder)); - if (!folder) - return NS_ERROR_NULL_POINTER; - folder->GetUriForMsg(aMsgHdr, msgUri); // populate the compose params - // right now, forward inline won't work, since that requires opening a compose window, - // and would require major whackage of the compose code. - pMsgComposeParams->SetType(/* forwardType ? nsIMsgCompType::ForwardInline : */nsIMsgCompType::ForwardAsAttachment); + pMsgComposeParams->SetType(nsIMsgCompType::ForwardAsAttachment); pMsgComposeParams->SetFormat(nsIMsgCompFormat::Default); pMsgComposeParams->SetIdentity(identity); pMsgComposeParams->SetComposeFields(compFields); @@ -1517,23 +1535,66 @@ nsresult nsMsgComposeService::LoadDraftOrTemplate(const nsACString& aMsgURI, nsMimeOutputType aOutType, nsIMsgIdentity * aIdentity, const char * aOriginalMsgURI, nsIMsgDBHdr * aOrigMsgHdr, - PRBool aAddInlineHeaders, - MSG_ComposeFormat format, + PRBool aForwardInline, + PRBool overrideComposeFormat, nsIMsgWindow *aMsgWindow) { - nsresult rv; + return RunMessageThroughMimeDraft(aMsgURI, aOutType, aIdentity, + aOriginalMsgURI, aOrigMsgHdr, + aForwardInline, EmptyString(), + overrideComposeFormat, aMsgWindow); +} + +/** + * Run the aMsgURI message through libmime. We set various attributes of the + * nsIMimeStreamConverter so mimedrft.cpp will know what to do with the message + * when its done streaming. Usually that will be opening a compose window + * with the contents of the message, but if forwardTo is non-empty, mimedrft.cpp + * will forward the contents directly. + * + * @param aMsgURI URI to stream, which is the msgUri + any extra terms, e.g., + * "redirect=true". + * @param aOutType nsMimeOutput::nsMimeMessageDraftOrTemplate or + * nsMimeOutput::nsMimeMessageEditorTemplate + * @param aIdentity identity to use for the new message + * @param aOriginalMsgURI msgURI w/o any extra terms + * @param aOrigMsgHdr nsIMsgDBHdr corresponding to aOriginalMsgURI + * @param aForwardInline true if doing a forward inline + * @param aForwardTo e-mail address to forward msg to. This is used for + * forward inline message filter actions. + * @param aOverrideComposeFormat True if the user had shift key down when + doing a command that opens the compose window, + * which means we switch the compose window used + * from the default. + * @param aMsgWindow msgWindow to pass into DisplayMessage. + */ +nsresult +nsMsgComposeService::RunMessageThroughMimeDraft( + const nsACString& aMsgURI, nsMimeOutputType aOutType, + nsIMsgIdentity * aIdentity, const char * aOriginalMsgURI, + nsIMsgDBHdr * aOrigMsgHdr, + PRBool aForwardInline, + const nsAString &aForwardTo, + PRBool aOverrideComposeFormat, + nsIMsgWindow *aMsgWindow) +{ nsCOMPtr messageService; - rv = GetMessageServiceFromURI(aMsgURI, getter_AddRefs(messageService)); + nsresult rv = GetMessageServiceFromURI(aMsgURI, getter_AddRefs(messageService)); NS_ENSURE_SUCCESS(rv, rv); - // Now, we can create a mime parser (nsIStreamConverter)! + // Create a mime parser (nsIMimeStreamConverter)to do the conversion. nsCOMPtr mimeConverter = do_CreateInstance(NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - mimeConverter->SetMimeOutputType(aOutType); // Set the type of output for libmime - mimeConverter->SetForwardInline(aAddInlineHeaders); - mimeConverter->SetOverrideComposeFormat(format == nsIMsgCompFormat::OppositeOfDefault); + mimeConverter->SetMimeOutputType(aOutType); // Set the type of output for libmime + mimeConverter->SetForwardInline(aForwardInline); + if (!aForwardTo.IsEmpty()) + { + mimeConverter->SetForwardInlineFilter(PR_TRUE); + mimeConverter->SetForwardToAddress(aForwardTo); + } + mimeConverter->SetOverrideComposeFormat(aOverrideComposeFormat); mimeConverter->SetIdentity(aIdentity); mimeConverter->SetOriginalMsgURI(aOriginalMsgURI); mimeConverter->SetOrigMsgHdr(aOrigMsgHdr); diff --git a/mailnews/compose/src/nsMsgComposeService.h b/mailnews/compose/src/nsMsgComposeService.h index 95324dc527..d83210c705 100644 --- a/mailnews/compose/src/nsMsgComposeService.h +++ b/mailnews/compose/src/nsMsgComposeService.h @@ -100,10 +100,20 @@ private: nsresult LoadDraftOrTemplate(const nsACString& aMsgURI, nsMimeOutputType aOutType, nsIMsgIdentity * aIdentity, const char * aOriginalMsgURI, - nsIMsgDBHdr * aOrigMsgHdr, PRBool aAddInlineHeaders, + nsIMsgDBHdr * aOrigMsgHdr, PRBool aForwardInline, MSG_ComposeFormat format, nsIMsgWindow *aMsgWindow); + nsresult RunMessageThroughMimeDraft(const nsACString& aMsgURI, + nsMimeOutputType aOutType, + nsIMsgIdentity * aIdentity, + const char * aOriginalMsgURI, + nsIMsgDBHdr * aOrigMsgHdr, + PRBool aForwardInline, + const nsAString &forwardTo, + PRBool overrideComposeFormat, + nsIMsgWindow *aMsgWindow); + nsresult ShowCachedComposeWindow(nsIDOMWindowInternal *aComposeWindow, PRBool aShow); // hash table mapping dom windows to nsIMsgCompose objects diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index f4caf9a8ae..fbbb4c083d 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -3616,14 +3616,17 @@ NS_IMETHODIMP nsImapMailFolder::ApplyFilterHit(nsIMsgFilter *filter, nsIMsgWindo { nsCString forwardTo; filterAction->GetStrValue(forwardTo); - nsCOMPtr server; + nsCOMPtr server; rv = GetServer(getter_AddRefs(server)); NS_ENSURE_SUCCESS(rv, rv); if (!forwardTo.IsEmpty()) { - nsCOMPtr compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ; - if (compService) - rv = compService->ForwardMessage(NS_ConvertASCIItoUTF16(forwardTo), msgHdr, msgWindow, server); + nsCOMPtr compService = + do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + rv = compService->ForwardMessage(NS_ConvertASCIItoUTF16(forwardTo), + msgHdr, msgWindow, server, + nsIMsgComposeService::kForwardAsDefault); } } break; diff --git a/mailnews/local/src/nsParseMailbox.cpp b/mailnews/local/src/nsParseMailbox.cpp index e76f5d67f9..f68d79ebe9 100644 --- a/mailnews/local/src/nsParseMailbox.cpp +++ b/mailnews/local/src/nsParseMailbox.cpp @@ -2273,9 +2273,12 @@ nsresult nsParseNewMailState::ApplyForwardAndReplyFilter(nsIMsgWindow *msgWindow rv = m_rootFolder->GetServer(getter_AddRefs(server)); NS_ENSURE_SUCCESS(rv, rv); { - nsCOMPtr compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ; - if (compService) - rv = compService->ForwardMessage(forwardStr, m_msgToForwardOrReply, msgWindow, server); + nsCOMPtr compService = + do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + rv = compService->ForwardMessage(forwardStr, m_msgToForwardOrReply, + msgWindow, server, + nsIMsgComposeService::kForwardAsDefault); } } } diff --git a/mailnews/mime/public/nsIMimeStreamConverter.idl b/mailnews/mime/public/nsIMimeStreamConverter.idl index b0ee391f21..1a56cd8dc2 100644 --- a/mailnews/mime/public/nsIMimeStreamConverter.idl +++ b/mailnews/mime/public/nsIMimeStreamConverter.idl @@ -75,7 +75,7 @@ interface nsIMimeStreamConverterListener : nsISupports{ * converters. Most of the code is just stuff that has been moved out * of nsIStreamConverter.idl to make it more generic. */ -[scriptable, uuid(ed861e40-6901-4bb0-b9ec-7a8e7a79bb0e)] +[scriptable, uuid(d894c833-29c5-495b-880c-9a9f847bfdc9)] interface nsIMimeStreamConverter : nsISupports { /** @@ -97,10 +97,20 @@ interface nsIMimeStreamConverter : nsISupports { void SetMimeHeadersListener(in nsIMimeStreamConverterListener listener, in nsMimeOutputType aType); /** - * This is used for forward inline. + * This is used for forward inline, both as a filter action, and from the UI. */ - attribute PRBool forwardInline; + attribute boolean forwardInline; + /** + * This is used for a forward inline filter action. When streaming is done, + * we won't open a compose window with the editor contents. + */ + attribute boolean forwardInlineFilter; + + /** + * Address for the forward inline filter to forward the message to. + */ + attribute AString forwardToAddress; /** * Use the opposite compose format, used for forward inline. */ diff --git a/mailnews/mime/src/mimedrft.cpp b/mailnews/mime/src/mimedrft.cpp index 162fdf1e31..04ca0498f6 100644 --- a/mailnews/mime/src/mimedrft.cpp +++ b/mailnews/mime/src/mimedrft.cpp @@ -181,22 +181,20 @@ mime_dump_attachments ( nsMsgAttachmentData *attachData ) } #endif -nsresult -CreateTheComposeWindow(nsIMsgCompFields * compFields, - nsMsgAttachmentData *attachmentList, - MSG_ComposeType composeType, - MSG_ComposeFormat composeFormat, - nsIMsgIdentity * identity, - const char * originalMsgURI, - nsIMsgDBHdr * origMsgHdr - ) +nsresult CreateComposeParams(nsCOMPtr &pMsgComposeParams, + nsIMsgCompFields * compFields, + nsMsgAttachmentData *attachmentList, + MSG_ComposeType composeType, + MSG_ComposeFormat composeFormat, + nsIMsgIdentity * identity, + const char *originalMsgURI, + nsIMsgDBHdr *origMsgHdr) { - nsresult rv; - #ifdef NS_DEBUG mime_dump_attachments ( attachmentList ); #endif + nsresult rv; nsMsgAttachmentData *curAttachment = attachmentList; if (curAttachment) { @@ -227,11 +225,6 @@ CreateTheComposeWindow(nsIMsgCompFields * compFields, } } - nsCOMPtr msgComposeService = - do_GetService(kCMsgComposeServiceCID, &rv); - if ((NS_FAILED(rv)) || (!msgComposeService)) - return rv; - MSG_ComposeFormat format = composeFormat; // Format to actually use. if (identity && composeType == nsIMsgCompType::ForwardInline) { @@ -245,21 +238,78 @@ CreateTheComposeWindow(nsIMsgCompFields * compFields, nsIMsgCompFormat::HTML : nsIMsgCompFormat::PlainText; } - nsCOMPtr pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && pMsgComposeParams) - { - pMsgComposeParams->SetType(composeType); - pMsgComposeParams->SetFormat(format); - pMsgComposeParams->SetIdentity(identity); - pMsgComposeParams->SetComposeFields(compFields); - if (originalMsgURI) - pMsgComposeParams->SetOriginalMsgURI(originalMsgURI); - if (origMsgHdr) - pMsgComposeParams->SetOrigMsgHdr(origMsgHdr); + pMsgComposeParams = do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); - rv = msgComposeService->OpenComposeWindowWithParams(nsnull /* default chrome */, pMsgComposeParams); - } - return rv; + pMsgComposeParams->SetType(composeType); + pMsgComposeParams->SetFormat(format); + pMsgComposeParams->SetIdentity(identity); + pMsgComposeParams->SetComposeFields(compFields); + if (originalMsgURI) + pMsgComposeParams->SetOriginalMsgURI(originalMsgURI); + if (origMsgHdr) + pMsgComposeParams->SetOrigMsgHdr(origMsgHdr); + return NS_OK; +} + +nsresult +CreateTheComposeWindow(nsIMsgCompFields * compFields, + nsMsgAttachmentData *attachmentList, + MSG_ComposeType composeType, + MSG_ComposeFormat composeFormat, + nsIMsgIdentity * identity, + const char * originalMsgURI, + nsIMsgDBHdr * origMsgHdr + ) +{ + nsCOMPtr pMsgComposeParams; + nsresult rv = CreateComposeParams(pMsgComposeParams, compFields, + attachmentList, + composeType, + composeFormat, + identity, + originalMsgURI, + origMsgHdr); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr msgComposeService = + do_GetService(kCMsgComposeServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + return msgComposeService->OpenComposeWindowWithParams(nsnull /* default chrome */, pMsgComposeParams); +} + +nsresult +SendTheMessage(nsIMsgCompFields * compFields, + nsMsgAttachmentData *attachmentList, + MSG_ComposeType composeType, + MSG_ComposeFormat composeFormat, + nsIMsgIdentity * identity, + const char * originalMsgURI, + nsIMsgDBHdr * origMsgHdr) +{ + nsCOMPtr pMsgComposeParams; + nsresult rv = CreateComposeParams(pMsgComposeParams, compFields, + attachmentList, + composeType, + composeFormat, + identity, + originalMsgURI, + origMsgHdr); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr msgComposeService = + do_GetService(kCMsgComposeServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + // create the nsIMsgCompose object to send the object + nsCOMPtr pMsgCompose (do_CreateInstance(NS_MSGCOMPOSE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + /** initialize nsIMsgCompose, Send the message, wait for send completion response **/ + rv = pMsgCompose->Initialize(nsnull, pMsgComposeParams) ; + NS_ENSURE_SUCCESS(rv,rv); + + return pMsgCompose->SendMsg(nsIMsgSend::nsMsgDeliverNow, identity, nsnull, nsnull, nsnull) ; } nsresult @@ -1463,14 +1513,15 @@ mime_parse_stream_complete (nsMIMESession *stream) bodyLen = strlen(body); } - PRUint32 newbodylen = bodyLen + 12; //+11 chars for
 & 
tags + //+13 chars for
 & 
tags and CRLF + PRUint32 newbodylen = bodyLen + 14; char* newbody = (char *)PR_MALLOC (newbodylen); if (newbody) { *newbody = 0; PL_strcatn(newbody, newbodylen, "
");
                 PL_strcatn(newbody, newbodylen, body);
-                PL_strcatn(newbody, newbodylen, "
"); + PL_strcatn(newbody, newbodylen, ""CRLF); PR_Free(body); body = newbody; } @@ -1529,7 +1580,15 @@ mime_parse_stream_complete (nsMIMESession *stream) fields->ConvertBodyToPlainText(); if (mdd->overrideComposeFormat) composeFormat = nsIMsgCompFormat::OppositeOfDefault; - CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, composeFormat, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr); + if (mdd->forwardInlineFilter) + { + fields->SetTo(mdd->forwardToAddress); + SendTheMessage(fields, newAttachData, nsIMsgCompType::ForwardInline, + composeFormat, mdd->identity, mdd->originalMsgURI, + mdd->origMsgHdr); + } + else + CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, composeFormat, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr); } else { @@ -2040,6 +2099,8 @@ mime_bridge_create_draft_stream( } newPluginObj2->GetForwardInline(&mdd->forwardInline); + newPluginObj2->GetForwardInlineFilter(&mdd->forwardInlineFilter); + newPluginObj2->GetForwardToAddress(mdd->forwardToAddress); newPluginObj2->GetOverrideComposeFormat(&mdd->overrideComposeFormat); newPluginObj2->GetIdentity(getter_AddRefs(mdd->identity)); newPluginObj2->GetOriginalMsgURI(&mdd->originalMsgURI); diff --git a/mailnews/mime/src/mimemoz2.h b/mailnews/mime/src/mimemoz2.h index dff3cecc23..44ed260ef1 100644 --- a/mailnews/mime/src/mimemoz2.h +++ b/mailnews/mime/src/mimemoz2.h @@ -156,7 +156,9 @@ struct mime_draft_data MimeDecoderData *decoder_data; char *mailcharset; // get it from CHARSET of Content-Type PRBool forwardInline; + PRBool forwardInlineFilter; PRBool overrideComposeFormat; // Override compose format (for forward inline). + nsString forwardToAddress; nsCOMPtr identity; char *originalMsgURI; // the original URI of the message we are currently processing nsCOMPtr origMsgHdr; diff --git a/mailnews/mime/src/nsStreamConverter.cpp b/mailnews/mime/src/nsStreamConverter.cpp index dbed58697c..5043dc7581 100644 --- a/mailnews/mime/src/nsStreamConverter.cpp +++ b/mailnews/mime/src/nsStreamConverter.cpp @@ -526,10 +526,11 @@ nsStreamConverter::nsStreamConverter() { // Init member variables... mWrapperOutput = PR_FALSE; - mBridgeStream = NULL; + mBridgeStream = nsnull; mOutputFormat = "text/html"; mAlreadyKnowOutputType = PR_FALSE; mForwardInline = PR_FALSE; + mForwardInlineFilter = PR_FALSE; mOverrideComposeFormat = PR_FALSE; mPendingRequest = nsnull; @@ -787,9 +788,23 @@ nsStreamConverter::SetMimeHeadersListener(nsIMimeStreamConverterListener *listen } NS_IMETHODIMP -nsStreamConverter::SetForwardInline(PRBool forwardInline) +nsStreamConverter::SetForwardInline(PRBool aForwardInline) { - mForwardInline = forwardInline; + mForwardInline = aForwardInline; + return NS_OK; +} + +NS_IMETHODIMP +nsStreamConverter::GetForwardToAddress(nsAString &aAddress) +{ + aAddress = mForwardToAddress; + return NS_OK; +} + +NS_IMETHODIMP +nsStreamConverter::SetForwardToAddress(const nsAString &aAddress) +{ + mForwardToAddress = aAddress; return NS_OK; } @@ -810,10 +825,25 @@ nsStreamConverter::SetOverrideComposeFormat(PRBool aOverrideComposeFormat) } NS_IMETHODIMP -nsStreamConverter::GetForwardInline(PRBool *result) +nsStreamConverter::GetForwardInline(PRBool *aResult) { - if (!result) return NS_ERROR_NULL_POINTER; - *result = mForwardInline; + NS_ENSURE_ARG_POINTER(aResult); + *aResult = mForwardInline; + return NS_OK; +} + +NS_IMETHODIMP +nsStreamConverter::GetForwardInlineFilter(PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + *aResult = mForwardInlineFilter; + return NS_OK; +} + +NS_IMETHODIMP +nsStreamConverter::SetForwardInlineFilter(PRBool aForwardInlineFilter) +{ + mForwardInlineFilter = aForwardInlineFilter; return NS_OK; } diff --git a/mailnews/mime/src/nsStreamConverter.h b/mailnews/mime/src/nsStreamConverter.h index e3426e6b6c..166d4368df 100644 --- a/mailnews/mime/src/nsStreamConverter.h +++ b/mailnews/mime/src/nsStreamConverter.h @@ -48,8 +48,8 @@ #include "nsStringGlue.h" #include "nsCOMPtr.h" -class nsStreamConverter : public nsIStreamConverter, public nsIMimeStreamConverter { -public: +class nsStreamConverter : public nsIStreamConverter, public nsIMimeStreamConverter { +public: nsStreamConverter(); virtual ~nsStreamConverter(); @@ -100,7 +100,9 @@ private: nsCOMPtr mMimeStreamConverterListener; PRBool mForwardInline; + PRBool mForwardInlineFilter; PRBool mOverrideComposeFormat; + nsString mForwardToAddress; nsCOMPtr mIdentity; nsCString mOriginalMsgURI; nsCOMPtr mOrigMsgHdr; @@ -112,6 +114,6 @@ private: #endif nsIRequest * mPendingRequest; // used when we need to delay to fire onStartRequest nsISupports * mPendingContext; // used when we need to delay to fire onStartRequest -}; +}; #endif /* nsStreamConverter_h_ */