diff options
author | Jeremy Andrews <athenian200@outlook.com> | 2022-06-01 19:32:33 -0500 |
---|---|---|
committer | Jeremy Andrews <athenian200@outlook.com> | 2022-06-04 16:13:32 -0500 |
commit | 9c395967cc6726158cf34c977f6c4da4cce742d1 (patch) | |
tree | de1b03d73b65e513ab9ec143176cef99236adaef /mailnews | |
parent | 64e3f4118a430706046f5757da73ed0081807df7 (diff) | |
download | uxp-9c395967cc6726158cf34c977f6c4da4cce742d1.tar.gz |
[MailNews] Allow shift-clicking on Edit As New to edit a message as plaintext.
Ref: BZ 731688
Diffstat (limited to 'mailnews')
-rw-r--r-- | mailnews/compose/public/nsIMsgComposeParams.idl | 6 | ||||
-rw-r--r-- | mailnews/compose/src/nsMsgCompose.cpp | 4 | ||||
-rw-r--r-- | mailnews/compose/src/nsMsgComposeService.cpp | 12 | ||||
-rw-r--r-- | mailnews/mime/src/mimedrft.cpp | 122 |
4 files changed, 115 insertions, 29 deletions
diff --git a/mailnews/compose/public/nsIMsgComposeParams.idl b/mailnews/compose/public/nsIMsgComposeParams.idl index 87c15eac37..bed6fb4dbf 100644 --- a/mailnews/compose/public/nsIMsgComposeParams.idl +++ b/mailnews/compose/public/nsIMsgComposeParams.idl @@ -40,6 +40,12 @@ interface nsIMsgCompType { const long Redirect = 14; /** + * Used to compose a new message from an existing message. Links + * are sanitized since the message could be from external sources. + */ + const long EditAsNew = 15; + + /** * Add this value to a reply type to suppress quoting the current selection * which may not belong to the message being replied to. */ diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index a7c2140ad7..040d9a4f0d 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -1070,7 +1070,8 @@ nsMsgCompose::Initialize(nsIMsgComposeParams *aParams, // by checking the identity prefs - but don't clobber the values for // drafts and templates as they were set up already by mime when // initializing the message. - if (m_identity && draftId.IsEmpty() && type != nsIMsgCompType::Template) + if (m_identity && draftId.IsEmpty() && type != nsIMsgCompType::Template + && type != nsIMsgCompType::EditAsNew) { bool requestReturnReceipt = false; rv = m_identity->GetRequestReturnReceipt(&requestReturnReceipt); @@ -4766,6 +4767,7 @@ nsMsgCompose::BuildBodyMessageAndSignature() case nsIMsgCompType::Draft : case nsIMsgCompType::Template : case nsIMsgCompType::Redirect : + case nsIMsgCompType::EditAsNew : addSignature = false; break; diff --git a/mailnews/compose/src/nsMsgComposeService.cpp b/mailnews/compose/src/nsMsgComposeService.cpp index bec88f8fe3..dfd2d75b61 100644 --- a/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mailnews/compose/src/nsMsgComposeService.cpp @@ -387,14 +387,22 @@ nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, nsIMsgDB /* Actually, the only way to implement forward inline is to simulate a template message. Maybe one day when we will have more time we can change that */ - if (type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft || type == nsIMsgCompType::Template - || type == nsIMsgCompType::ReplyWithTemplate || type == nsIMsgCompType::Redirect) + if (type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft || + type == nsIMsgCompType::Template || + type == nsIMsgCompType::ReplyWithTemplate || + type == nsIMsgCompType::Redirect || + type == nsIMsgCompType::EditAsNew) { nsAutoCString uriToOpen(originalMsgURI); uriToOpen += (uriToOpen.FindChar('?') == kNotFound) ? '?' : '&'; uriToOpen.Append("fetchCompleteMessage=true"); + // The compose type that gets transmitted to a compose window open in mime + // is communicated using url query parameters here. + if (type == nsIMsgCompType::Redirect) uriToOpen.Append("&redirect=true"); + else if (type == nsIMsgCompType::EditAsNew) + uriToOpen.Append("&editasnew=true"); return LoadDraftOrTemplate(uriToOpen, type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft ? nsMimeOutput::nsMimeMessageDraftOrTemplate : nsMimeOutput::nsMimeMessageEditorTemplate, diff --git a/mailnews/mime/src/mimedrft.cpp b/mailnews/mime/src/mimedrft.cpp index 90ca027d8b..06f8ea8d36 100644 --- a/mailnews/mime/src/mimedrft.cpp +++ b/mailnews/mime/src/mimedrft.cpp @@ -1088,6 +1088,33 @@ mime_insert_forwarded_message_headers(char **body, } static void +convert_plaintext_body_to_html(char **body, uint32_t bodyLen) +{ + // We need to convert the plain/text to HTML in order to escape any HTML markup + char *escapedBody = MsgEscapeHTML(*body); + if (escapedBody) + { + PR_Free(*body); + *body = escapedBody; + bodyLen = strlen(*body); + } + + // +13 chars for <pre> & </pre> tags and CRLF + uint32_t newbodylen = bodyLen + 14; + char* newbody = (char *)PR_MALLOC (newbodylen); + if (newbody) + { + *newbody = 0; + PL_strcatn(newbody, newbodylen, "<PRE>"); + PL_strcatn(newbody, newbodylen, *body); + PL_strcatn(newbody, newbodylen, "</PRE>" CRLF); + PR_Free(*body); + *body = newbody; + } +} + + +static void mime_parse_stream_complete(nsMIMESession *stream) { mime_draft_data *mdd = (mime_draft_data *)stream->data_object; @@ -1415,28 +1442,8 @@ mime_parse_stream_complete(nsMIMESession *stream) { // ... but the message body is currently plain text. - //We need to convert the plain/text to HTML in order to escape any HTML markup - char *escapedBody = MsgEscapeHTML(body); - if (escapedBody) - { - PR_Free(body); - body = escapedBody; - bodyLen = strlen(body); - } - - //+13 chars for <pre> & </pre> tags and CRLF - uint32_t newbodylen = bodyLen + 14; - char* newbody = (char *)PR_MALLOC (newbodylen); - if (newbody) - { - *newbody = 0; - PL_strcatn(newbody, newbodylen, "<PRE>"); - PL_strcatn(newbody, newbodylen, body); - PL_strcatn(newbody, newbodylen, "</PRE>" CRLF); - PR_Free(body); - body = newbody; - } - } + convert_plaintext_body_to_html(&body, bodyLen); + } // Body is now HTML, set the format too (so headers are inserted in // correct format). composeFormat = nsIMsgCompFormat::HTML; @@ -1460,6 +1467,68 @@ mime_parse_stream_complete(nsMIMESession *stream) } + MSG_ComposeType msgComposeType = 0; // Keep compilers happy. + if (mdd->format_out == nsMimeOutput::nsMimeMessageEditorTemplate) + { + if (PL_strstr(mdd->url_name, "&redirect=true")) + msgComposeType = nsIMsgCompType::Redirect; + else if (PL_strstr(mdd->url_name, "&editasnew=true")) + msgComposeType = nsIMsgCompType::EditAsNew; + else + msgComposeType = nsIMsgCompType::Template; + } + + if (body && msgComposeType == nsIMsgCompType::EditAsNew) + { + // When editing as new, we respect the identities preferred format + // which can be overridden. + if (mdd->identity) + { + bool identityComposeHTML; + mdd->identity->GetComposeHtml(&identityComposeHTML); + + if (composeFormat == nsIMsgCompFormat::HTML && + identityComposeHTML == mdd->overrideComposeFormat) + { + // We we have HTML: + // If they want HTML and they want to override it (true == true) + // or they don't want HTML and they don't want to override it + // (false == false), then convert. Conversion happens below. + convertToPlainText = true; + composeFormat = nsIMsgCompFormat::PlainText; + } + else if (composeFormat == nsIMsgCompFormat::PlainText && + identityComposeHTML != mdd->overrideComposeFormat) + { + // We have plain text: + // If they want HTML and they don't want to override it (true != false) + // or they don't want HTML and they want to override it + // (false != true), then convert. + convert_plaintext_body_to_html(&body, bodyLen); + composeFormat = nsIMsgCompFormat::HTML; + } + } + } + else if (body && mdd->overrideComposeFormat && + (msgComposeType == nsIMsgCompType::Template || + !mdd->forwardInline)) // Draft processing. + { + // When using a template and overriding, the user gets the + // "other" format. + if (composeFormat == nsIMsgCompFormat::PlainText) + { + convert_plaintext_body_to_html(&body, bodyLen); + composeFormat = nsIMsgCompFormat::HTML; + } + else + { + // Conversion happens below. + convertToPlainText = true; + composeFormat = nsIMsgCompFormat::PlainText; + } + } + + // convert from UTF-8 to UTF-16 if (body) { @@ -1474,10 +1543,9 @@ mime_parse_stream_complete(nsMIMESession *stream) // if (mdd->format_out == nsMimeOutput::nsMimeMessageEditorTemplate) { - MSG_ComposeType msgComposeType = PL_strstr(mdd->url_name, - "&redirect=true") ? - nsIMsgCompType::Redirect : - nsIMsgCompType::Template; + if (convertToPlainText) + fields->ConvertBodyToPlainText(); + CreateTheComposeWindow(fields, newAttachData, msgComposeType, composeFormat, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr); @@ -1505,6 +1573,8 @@ mime_parse_stream_complete(nsMIMESession *stream) } else { + if (convertToPlainText) + fields->ConvertBodyToPlainText(); fields->SetDraftId(mdd->url_name); CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, composeFormat, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr); } |