summaryrefslogtreecommitdiff
path: root/mailnews/mime
diff options
context:
space:
mode:
authorJeremy Andrews <athenian200@outlook.com>2022-06-01 19:32:33 -0500
committerJeremy Andrews <athenian200@outlook.com>2022-06-04 16:13:32 -0500
commit9c395967cc6726158cf34c977f6c4da4cce742d1 (patch)
treede1b03d73b65e513ab9ec143176cef99236adaef /mailnews/mime
parent64e3f4118a430706046f5757da73ed0081807df7 (diff)
downloaduxp-9c395967cc6726158cf34c977f6c4da4cce742d1.tar.gz
[MailNews] Allow shift-clicking on Edit As New to edit a message as plaintext.
Ref: BZ 731688
Diffstat (limited to 'mailnews/mime')
-rw-r--r--mailnews/mime/src/mimedrft.cpp122
1 files changed, 96 insertions, 26 deletions
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);
}