mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-25 08:37:30 +09:00
[MailNews] Allow shift-clicking on Edit As New to edit a message as plaintext.
Ref: BZ 731688
This commit is contained in:
parent
d18524ab7e
commit
6182744d96
4 changed files with 115 additions and 29 deletions
|
|
@ -39,6 +39,12 @@ interface nsIMsgCompType {
|
||||||
*/
|
*/
|
||||||
const long Redirect = 14;
|
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
|
* Add this value to a reply type to suppress quoting the current selection
|
||||||
* which may not belong to the message being replied to.
|
* which may not belong to the message being replied to.
|
||||||
|
|
|
||||||
|
|
@ -1070,7 +1070,8 @@ nsMsgCompose::Initialize(nsIMsgComposeParams *aParams,
|
||||||
// by checking the identity prefs - but don't clobber the values for
|
// by checking the identity prefs - but don't clobber the values for
|
||||||
// drafts and templates as they were set up already by mime when
|
// drafts and templates as they were set up already by mime when
|
||||||
// initializing the message.
|
// 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;
|
bool requestReturnReceipt = false;
|
||||||
rv = m_identity->GetRequestReturnReceipt(&requestReturnReceipt);
|
rv = m_identity->GetRequestReturnReceipt(&requestReturnReceipt);
|
||||||
|
|
@ -4766,6 +4767,7 @@ nsMsgCompose::BuildBodyMessageAndSignature()
|
||||||
case nsIMsgCompType::Draft :
|
case nsIMsgCompType::Draft :
|
||||||
case nsIMsgCompType::Template :
|
case nsIMsgCompType::Template :
|
||||||
case nsIMsgCompType::Redirect :
|
case nsIMsgCompType::Redirect :
|
||||||
|
case nsIMsgCompType::EditAsNew :
|
||||||
addSignature = false;
|
addSignature = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -387,14 +387,22 @@ nsMsgComposeService::OpenComposeWindow(const char *msgComposeWindowURL, nsIMsgDB
|
||||||
/* Actually, the only way to implement forward inline is to simulate a template message.
|
/* 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
|
Maybe one day when we will have more time we can change that
|
||||||
*/
|
*/
|
||||||
if (type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft || type == nsIMsgCompType::Template
|
if (type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft ||
|
||||||
|| type == nsIMsgCompType::ReplyWithTemplate || type == nsIMsgCompType::Redirect)
|
type == nsIMsgCompType::Template ||
|
||||||
|
type == nsIMsgCompType::ReplyWithTemplate ||
|
||||||
|
type == nsIMsgCompType::Redirect ||
|
||||||
|
type == nsIMsgCompType::EditAsNew)
|
||||||
{
|
{
|
||||||
nsAutoCString uriToOpen(originalMsgURI);
|
nsAutoCString uriToOpen(originalMsgURI);
|
||||||
uriToOpen += (uriToOpen.FindChar('?') == kNotFound) ? '?' : '&';
|
uriToOpen += (uriToOpen.FindChar('?') == kNotFound) ? '?' : '&';
|
||||||
uriToOpen.Append("fetchCompleteMessage=true");
|
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)
|
if (type == nsIMsgCompType::Redirect)
|
||||||
uriToOpen.Append("&redirect=true");
|
uriToOpen.Append("&redirect=true");
|
||||||
|
else if (type == nsIMsgCompType::EditAsNew)
|
||||||
|
uriToOpen.Append("&editasnew=true");
|
||||||
|
|
||||||
return LoadDraftOrTemplate(uriToOpen, type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft ?
|
return LoadDraftOrTemplate(uriToOpen, type == nsIMsgCompType::ForwardInline || type == nsIMsgCompType::Draft ?
|
||||||
nsMimeOutput::nsMimeMessageDraftOrTemplate : nsMimeOutput::nsMimeMessageEditorTemplate,
|
nsMimeOutput::nsMimeMessageDraftOrTemplate : nsMimeOutput::nsMimeMessageEditorTemplate,
|
||||||
|
|
|
||||||
|
|
@ -1087,6 +1087,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
|
static void
|
||||||
mime_parse_stream_complete(nsMIMESession *stream)
|
mime_parse_stream_complete(nsMIMESession *stream)
|
||||||
{
|
{
|
||||||
|
|
@ -1415,28 +1442,8 @@ mime_parse_stream_complete(nsMIMESession *stream)
|
||||||
{
|
{
|
||||||
// ... but the message body is currently plain text.
|
// ... but the message body is currently plain text.
|
||||||
|
|
||||||
//We need to convert the plain/text to HTML in order to escape any HTML markup
|
convert_plaintext_body_to_html(&body, bodyLen);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Body is now HTML, set the format too (so headers are inserted in
|
// Body is now HTML, set the format too (so headers are inserted in
|
||||||
// correct format).
|
// correct format).
|
||||||
composeFormat = nsIMsgCompFormat::HTML;
|
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
|
// convert from UTF-8 to UTF-16
|
||||||
if (body)
|
if (body)
|
||||||
{
|
{
|
||||||
|
|
@ -1474,10 +1543,9 @@ mime_parse_stream_complete(nsMIMESession *stream)
|
||||||
//
|
//
|
||||||
if (mdd->format_out == nsMimeOutput::nsMimeMessageEditorTemplate)
|
if (mdd->format_out == nsMimeOutput::nsMimeMessageEditorTemplate)
|
||||||
{
|
{
|
||||||
MSG_ComposeType msgComposeType = PL_strstr(mdd->url_name,
|
if (convertToPlainText)
|
||||||
"&redirect=true") ?
|
fields->ConvertBodyToPlainText();
|
||||||
nsIMsgCompType::Redirect :
|
|
||||||
nsIMsgCompType::Template;
|
|
||||||
CreateTheComposeWindow(fields, newAttachData, msgComposeType,
|
CreateTheComposeWindow(fields, newAttachData, msgComposeType,
|
||||||
composeFormat, mdd->identity,
|
composeFormat, mdd->identity,
|
||||||
mdd->originalMsgURI, mdd->origMsgHdr);
|
mdd->originalMsgURI, mdd->origMsgHdr);
|
||||||
|
|
@ -1505,6 +1573,8 @@ mime_parse_stream_complete(nsMIMESession *stream)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (convertToPlainText)
|
||||||
|
fields->ConvertBodyToPlainText();
|
||||||
fields->SetDraftId(mdd->url_name);
|
fields->SetDraftId(mdd->url_name);
|
||||||
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, composeFormat, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr);
|
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, composeFormat, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue