From 4fd4322ac4c97f4e7cf0adfaf26415667f5ea8da Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Sat, 13 Aug 2005 18:50:38 +0000 Subject: [PATCH] Bug 301084 Option to file replies in folder of original message (backend part) patch by Emil Hesslow r=dmose sr=bienvenu --- mailnews/base/public/nsIMsgIdentity.idl | 3 +- mailnews/base/util/nsMsgIdentity.cpp | 3 + mailnews/compose/public/nsIMsgSend.idl | 7 +- mailnews/compose/src/nsMsgCompose.cpp | 4 +- mailnews/compose/src/nsMsgSend.cpp | 99 ++++++++++++++++--- mailnews/compose/src/nsMsgSend.h | 9 +- .../import/eudora/src/nsEudoraCompose.cpp | 8 +- .../import/outlook/src/nsOutlookCompose.cpp | 4 +- mailnews/mailnews.js | 1 + 9 files changed, 114 insertions(+), 24 deletions(-) diff --git a/mailnews/base/public/nsIMsgIdentity.idl b/mailnews/base/public/nsIMsgIdentity.idl index f2d64df4b48f..15851aec8e25 100644 --- a/mailnews/base/public/nsIMsgIdentity.idl +++ b/mailnews/base/public/nsIMsgIdentity.idl @@ -49,7 +49,7 @@ */ -[scriptable, uuid(2b165a14-1ac1-4c32-8cc5-72e2937d5be9)] +[scriptable, uuid(e823535a-66b8-4bd4-99cd-cb1cafbfedb6)] interface nsIMsgIdentity : nsISupports { /* internal preferences ID */ attribute string key; @@ -102,6 +102,7 @@ interface nsIMsgIdentity : nsISupports { attribute string fccFolder; attribute string fccFolderPickerMode; + attribute boolean fccReplyFollowsParent; attribute string draftsFolderPickerMode; attribute string tmplFolderPickerMode; diff --git a/mailnews/base/util/nsMsgIdentity.cpp b/mailnews/base/util/nsMsgIdentity.cpp index 8e1c8fa8bd44..aa1104dc3b53 100644 --- a/mailnews/base/util/nsMsgIdentity.cpp +++ b/mailnews/base/util/nsMsgIdentity.cpp @@ -474,6 +474,7 @@ NS_IMPL_IDPREF_BOOL(DoFcc, "fcc") NS_IMPL_FOLDERPREF_STR(FccFolder, "fcc_folder") NS_IMPL_IDPREF_STR(FccFolderPickerMode, "fcc_folder_picker_mode") +NS_IMPL_IDPREF_BOOL(FccReplyFollowsParent, "fcc_reply_follows_parent") NS_IMPL_IDPREF_STR(DraftsFolderPickerMode, "drafts_folder_picker_mode") NS_IMPL_IDPREF_STR(TmplFolderPickerMode, "tmpl_folder_picker_mode") @@ -798,6 +799,8 @@ nsMsgIdentity::Copy(nsIMsgIdentity *identity) COPY_IDENTITY_WSTR_VALUE(identity,GetOrganization,SetOrganization) COPY_IDENTITY_STR_VALUE(identity,GetDraftFolder,SetDraftFolder) COPY_IDENTITY_STR_VALUE(identity,GetFccFolder,SetFccFolder) + COPY_IDENTITY_BOOL_VALUE(identity,GetFccReplyFollowsParent, + SetFccReplyFollowsParent) COPY_IDENTITY_STR_VALUE(identity,GetStationeryFolder,SetStationeryFolder) COPY_IDENTITY_BOOL_VALUE(identity,GetAttachSignature,SetAttachSignature) COPY_IDENTITY_FILE_VALUE(identity,GetSignature,SetSignature) diff --git a/mailnews/compose/public/nsIMsgSend.idl b/mailnews/compose/public/nsIMsgSend.idl index 3dafe2d2c379..08db0bcc0daa 100644 --- a/mailnews/compose/public/nsIMsgSend.idl +++ b/mailnews/compose/public/nsIMsgSend.idl @@ -53,6 +53,7 @@ #include "domstubs.idl" #include "nsIPrompt.idl" #include "MailNewsTypes2.idl" +#include "nsIMsgComposeParams.idl" %{C++ #include "nsIURL.h" @@ -164,7 +165,7 @@ typedef struct nsMsgAttachedFile [ptr] native nsOutputFileStream(nsOutputFileStream); [ptr] native nsCString(nsCString); -[scriptable, uuid(9E9BD970-C5D6-11d2-8297-000000000000)] +[scriptable, uuid(39876de6-207f-43f4-99a7-d60f1c49ea48)] interface nsIMsgSend : nsISupports { // @@ -203,7 +204,9 @@ interface nsIMsgSend : nsISupports in nsIDOMWindowInternal parentWindow, in nsIMsgProgress progress, in nsIMsgSendListener aListener, - in string password + in string password, + in AUTF8String aOriginalMsgURI, + in MSG_ComposeType aType ); diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index 01890654977f..5f165ecbd669 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -926,7 +926,9 @@ nsresult nsMsgCompose::_SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity *ide m_window, // nsIDOMWindowInternal *parentWindow; mProgress, // nsIMsgProgress *progress, sendListener, // listener - mSmtpPassword.get()); + mSmtpPassword.get(), + mOriginalMsgURI, + mType); // Cleanup converted body... if (newBody) diff --git a/mailnews/compose/src/nsMsgSend.cpp b/mailnews/compose/src/nsMsgSend.cpp index 23992bf07791..1e087dc05fd0 100644 --- a/mailnews/compose/src/nsMsgSend.cpp +++ b/mailnews/compose/src/nsMsgSend.cpp @@ -108,6 +108,9 @@ #include "nsNativeCharsetUtils.h" #include "nsIAbCard.h" #include "nsIMsgProgress.h" +#include "nsIMsgMessageService.h" +#include "nsIMsgHdr.h" +#include "nsIMsgFolder.h" static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); @@ -2832,7 +2835,9 @@ int nsMsgComposeAndSend::SetMimeHeader(nsMsgCompFields::MsgHeaderID header, cons } nsresult -nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields) +nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields, + const nsACString &aOriginalMsgURI, + MSG_ComposeType aType) { nsresult rv = NS_OK; const char *pStr = nsnull; @@ -2915,17 +2920,77 @@ nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields) // We use default FCC setting if it's not set or was set to an invalid folder. if (useDefaultFCC) { - char *uri = GetFolderURIFromUserPrefs(nsMsgDeliverNow, mUserIdentity); - if ( (uri) && (*uri) ) + // Only check whether the user wants the message in the original message + // folder if the msgcomptype is some kind of a reply. + if (!aOriginalMsgURI.IsEmpty() && ( + aType == nsIMsgCompType::Reply || + aType == nsIMsgCompType::ReplyAll || + aType == nsIMsgCompType::ReplyToGroup || + aType == nsIMsgCompType::ReplyToSender || + aType == nsIMsgCompType::ReplyToSenderAndGroup || + aType == nsIMsgCompType::ReplyWithTemplate ) + ) { - if (PL_strcasecmp(uri, "nocopy://") == 0) - mCompFields->SetFcc(""); - else - mCompFields->SetFcc(uri); - PL_strfree(uri); + nsCOMPtr accountManager = + do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr msgHdr; + rv = GetMsgDBHdrFromURI(PromiseFlatCString(aOriginalMsgURI).get(), + getter_AddRefs(msgHdr)); + if (NS_SUCCEEDED(rv)) + { + nsCOMPtr folder; + msgHdr->GetFolder(getter_AddRefs(folder)); + if (NS_SUCCEEDED(rv)) + { + PRBool canFileMessages; + rv = folder->GetCanFileMessages(&canFileMessages); + if (NS_SUCCEEDED(rv) && canFileMessages) + { + nsCOMPtr incomingServer; + rv = folder->GetServer(getter_AddRefs(incomingServer)); + if (NS_SUCCEEDED(rv)) + { + nsXPIDLCString incomingServerType; + rv = incomingServer->GetCharValue("type", + getter_Copies(incomingServerType)); + // Exclude RSS accounts, as they falsely report + // 'canFileMessages' = true + if (NS_SUCCEEDED(rv) && !incomingServerType.Equals("rss")) + { + PRBool fccReplyFollowsParent; + rv = mUserIdentity->GetFccReplyFollowsParent( + &fccReplyFollowsParent); + if (NS_SUCCEEDED(rv) && fccReplyFollowsParent) + { + nsXPIDLCString folderURI; + rv = folder->GetURI(getter_Copies(folderURI)); + if (NS_SUCCEEDED(rv)) + { + mCompFields->SetFcc(folderURI.get()); + useDefaultFCC = PR_FALSE; + } + } + } + } + } + } + } + } + } + + if (useDefaultFCC) + { + char *uri = GetFolderURIFromUserPrefs(nsMsgDeliverNow, mUserIdentity); + if ( (uri) && (*uri) ) + { + mCompFields->SetFcc(PL_strcasecmp(uri, "nocopy://") ? uri : ""); + PL_strfree(uri); + } + else + mCompFields->SetFcc(""); } - else - mCompFields->SetFcc(""); } } @@ -3138,7 +3203,9 @@ nsMsgComposeAndSend::Init( PRUint32 attachment1_body_length, const nsMsgAttachmentData *attachments, const nsMsgAttachedFile *preloaded_attachments, - const char *password) + const char *password, + const nsACString &aOriginalMsgURI, + MSG_ComposeType aType) { nsresult rv = NS_OK; @@ -3181,7 +3248,7 @@ nsMsgComposeAndSend::Init( if (!fields) return NS_ERROR_OUT_OF_MEMORY; - rv = InitCompositionFields(fields); + rv = InitCompositionFields(fields, aOriginalMsgURI, aType); if (NS_FAILED(rv)) return rv; @@ -4055,7 +4122,9 @@ nsMsgComposeAndSend::CreateAndSendMessage( nsIDOMWindowInternal *parentWindow, nsIMsgProgress *progress, nsIMsgSendListener *aListener, - const char *password + const char *password, + const nsACString &aOriginalMsgURI, + MSG_ComposeType aType ) { nsresult rv; @@ -4084,7 +4153,7 @@ nsMsgComposeAndSend::CreateAndSendMessage( attachment1_type, attachment1_body, attachment1_body_length, attachments, preloaded_attachments, - password); + password, aOriginalMsgURI, aType); if (NS_FAILED(rv) && mSendReport) mSendReport->SetError(nsIMsgSendReport::process_Current, rv, PR_FALSE); @@ -4155,7 +4224,7 @@ nsMsgComposeAndSend::SendMessageFile( digest_p, PR_FALSE, mode, msgToReplace, nsnull, nsnull, nsnull, nsnull, nsnull, - password); + password, EmptyCString(), nsnull); if (NS_SUCCEEDED(rv)) rv = DeliverMessage(); diff --git a/mailnews/compose/src/nsMsgSend.h b/mailnews/compose/src/nsMsgSend.h index 4aaa9d64693e..becbaa7e37d6 100644 --- a/mailnews/compose/src/nsMsgSend.h +++ b/mailnews/compose/src/nsMsgSend.h @@ -256,12 +256,17 @@ public: PRUint32 attachment1_body_length, const nsMsgAttachmentData *attachments, const nsMsgAttachedFile *preloaded_attachments, - const char *password); + const char *password, + const nsACString &aOriginalMsgURI, + MSG_ComposeType aType); // // Setup the composition fields // - nsresult InitCompositionFields(nsMsgCompFields *fields); + nsresult InitCompositionFields(nsMsgCompFields *fields, + const nsACString &aOriginalMsgURI, + MSG_ComposeType aType); + int SetMimeHeader(nsMsgCompFields::MsgHeaderID header, const char *value); NS_IMETHOD GetBodyFromEditor(); diff --git a/mailnews/import/eudora/src/nsEudoraCompose.cpp b/mailnews/import/eudora/src/nsEudoraCompose.cpp index e003cc9b1033..e9b49a9f8ec7 100644 --- a/mailnews/import/eudora/src/nsEudoraCompose.cpp +++ b/mailnews/import/eudora/src/nsEudoraCompose.cpp @@ -717,7 +717,9 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) nsnull, // parent window nsnull, // progress listener m_pListener, // listener - nsnull); // password + nsnull, // password + EmptyCString(), // originalMsgURI + nsnull); // message compose type } else { @@ -739,7 +741,9 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) nsnull, // parent window nsnull, // progress listener m_pListener, // listener - nsnull); // password + nsnull, // password + EmptyCString(), // originalMsgURI + nsnull); // message compose type } diff --git a/mailnews/import/outlook/src/nsOutlookCompose.cpp b/mailnews/import/outlook/src/nsOutlookCompose.cpp index e90918df857f..cd7d47a0c1d0 100644 --- a/mailnews/import/outlook/src/nsOutlookCompose.cpp +++ b/mailnews/import/outlook/src/nsOutlookCompose.cpp @@ -685,7 +685,9 @@ nsresult nsOutlookCompose::SendTheMessage( nsIFileSpec *pMsg, nsMsgDeliverMode m nsnull, // parent window nsnull, // progress listener m_pListener, // listener - nsnull); // password + nsnull, // password + EmptyCString(), // originalMsgURI + nsnull); // message compose type // IMPORT_LOG0( "Returned from CreateAndSendMessage\n"); diff --git a/mailnews/mailnews.js b/mailnews/mailnews.js index 5813f31eddee..0f99bc67f901 100644 --- a/mailnews/mailnews.js +++ b/mailnews/mailnews.js @@ -365,6 +365,7 @@ pref("mail.identity.default.compose_html", true); pref("mail.identity.default.valid", true); pref("mail.identity.default.fcc",true); pref("mail.identity.default.fcc_folder","mailbox://nobody@Local%20Folders/Sent"); +pref("mail.identity.default.fcc_reply_follows_parent", false); pref("mail.identity.default.autocompleteToMyDomain", false); // keep these defaults for backwards compatibility and migration