Bug 228562: shift+forward should toggle html/plain text. r+sr=bienvenu

This commit is contained in:
Magnus Melin 2009-05-13 19:13:36 +03:00
Родитель acc5314b9b
Коммит c23f3b289b
9 изменённых файлов: 99 добавлений и 49 удалений

Просмотреть файл

@ -179,7 +179,7 @@
1040=Part %s
# default forwarded message prefix
## @name MIME_FORWARDED_MESSAGE_USER_WROTE
## @name MIME_FORWARDED_MESSAGE_HTML_USER_WROTE
## @loc
1041=-------- Original Message --------

Просмотреть файл

@ -568,7 +568,7 @@ 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, aMsgWindow);
identity, originalMsgURI, origMsgHdr, type == nsIMsgCompType::ForwardInline, format, aMsgWindow);
}
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
@ -1517,7 +1517,9 @@ nsresult
nsMsgComposeService::LoadDraftOrTemplate(const nsACString& aMsgURI, nsMimeOutputType aOutType,
nsIMsgIdentity * aIdentity, const char * aOriginalMsgURI,
nsIMsgDBHdr * aOrigMsgHdr,
PRBool aAddInlineHeaders, nsIMsgWindow *aMsgWindow)
PRBool aAddInlineHeaders,
MSG_ComposeFormat format,
nsIMsgWindow *aMsgWindow)
{
nsresult rv;
nsCOMPtr <nsIMsgMessageService> messageService;
@ -1531,6 +1533,7 @@ nsMsgComposeService::LoadDraftOrTemplate(const nsACString& aMsgURI, nsMimeOutput
mimeConverter->SetMimeOutputType(aOutType); // Set the type of output for libmime
mimeConverter->SetForwardInline(aAddInlineHeaders);
mimeConverter->SetOverrideComposeFormat(format == nsIMsgCompFormat::OppositeOfDefault);
mimeConverter->SetIdentity(aIdentity);
mimeConverter->SetOriginalMsgURI(aOriginalMsgURI);
mimeConverter->SetOrigMsgHdr(aOrigMsgHdr);

Просмотреть файл

@ -101,6 +101,7 @@ private:
nsresult LoadDraftOrTemplate(const nsACString& aMsgURI, nsMimeOutputType aOutType,
nsIMsgIdentity * aIdentity, const char * aOriginalMsgURI,
nsIMsgDBHdr * aOrigMsgHdr, PRBool aAddInlineHeaders,
MSG_ComposeFormat format,
nsIMsgWindow *aMsgWindow);
nsresult ShowCachedComposeWindow(nsIDOMWindowInternal *aComposeWindow, PRBool aShow);

Просмотреть файл

@ -35,12 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
/*
I've created this interface to contain mailnews mime specific information
for stream converters. Most of this code is just stuff that has been moved out
of nsIStreamConverter.idl to make it more generic.
*/
#include "nsISupports.idl"
#include "nsrootidl.idl"
#include "nsIMimeHeaders.idl"
@ -76,36 +70,45 @@ interface nsIMimeStreamConverterListener : nsISupports{
void onHeadersReady(in nsIMimeHeaders headers);
};
[scriptable, uuid(9b1d157b-4223-42f5-9bec-11c1ec34d609)]
/**
* This interface contains mailnews mime specific information for stream
* 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)]
interface nsIMimeStreamConverter : nsISupports {
/*
* This is used to set the desired mime output type on the converer.
*/
/**
* Set the desired mime output type on the converer.
*/
void SetMimeOutputType(in nsMimeOutputType aType);
void GetMimeOutputType(out nsMimeOutputType aOutFormat);
/*
* This is needed by libmime for MHTML link processing...the url is the URL string associated
* with this input stream
*/
/**
* This is needed by libmime for MHTML link processing...the url is the URL
* string associated with this input stream.
*/
void SetStreamURI(in nsIURI aURI);
/*
* This is used to extract headers while parsing a message
*/
/**
* Used to extract headers while parsing a message.
*/
void SetMimeHeadersListener(in nsIMimeStreamConverterListener listener, in nsMimeOutputType aType);
/*
* This is used for forward inline
*/
/**
* This is used for forward inline.
*/
attribute PRBool forwardInline;
/*
* This is used for OpenDraft, OpenEditorTemplate and Forward inline (which use OpenDraft)
*/
/**
* Use the opposite compose format, used for forward inline.
*/
attribute PRBool overrideComposeFormat;
/**
* This is used for OpenDraft, OpenEditorTemplate and Forward inline (which use OpenDraft)
*/
attribute nsIMsgIdentity identity;
attribute string originalMsgURI;
attribute nsIMsgDBHdr origMsgHdr;

Просмотреть файл

@ -22,6 +22,7 @@
*
* Contributor(s):
* Eric Ballet Baz BT Global Services / Etat francais Ministere de la Defense
* Magnus Melin <mkmelin+mozilla@iki.fi>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -191,7 +192,6 @@ CreateTheComposeWindow(nsIMsgCompFields * compFields,
)
{
nsresult rv;
MSG_ComposeFormat format = nsIMsgCompFormat::Default;
#ifdef NS_DEBUG
mime_dump_attachments ( attachmentList );
@ -232,22 +232,18 @@ CreateTheComposeWindow(nsIMsgCompFields * compFields,
if ((NS_FAILED(rv)) || (!msgComposeService))
return rv;
MSG_ComposeFormat format = composeFormat; // Format to actually use.
if (identity && composeType == nsIMsgCompType::ForwardInline)
{
PRBool composeHtml = PR_FALSE;
identity->GetComposeHtml(&composeHtml);
if (composeHtml)
format = nsIMsgCompFormat::HTML;
format = (composeFormat == nsIMsgCompFormat::OppositeOfDefault) ?
nsIMsgCompFormat::PlainText : nsIMsgCompFormat::HTML;
else
{
format = nsIMsgCompFormat::PlainText;
/* do we we need to convert the HTML body to plain text? */
if (composeFormat == nsIMsgCompFormat::HTML)
compFields->ConvertBodyToPlainText();
}
format = (composeFormat == nsIMsgCompFormat::OppositeOfDefault) ?
nsIMsgCompFormat::HTML : nsIMsgCompFormat::PlainText;
}
else
format = composeFormat;
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && pMsgComposeParams)
@ -1443,21 +1439,22 @@ mime_parse_stream_complete (nsMIMESession *stream)
}
}
// Since we have body text, then we should set the compose fields with
// this data.
// if (composeFormat == nsIMsgCompFormat::PlainText)
// fields->SetTheForcePlainText(PR_TRUE);
PRBool convertToPlainText = PR_FALSE;
if (forward_inline)
{
if (mdd->identity)
{
PRBool bFormat;
mdd->identity->GetComposeHtml(&bFormat);
if (bFormat)
PRBool identityComposeHTML;
mdd->identity->GetComposeHtml(&identityComposeHTML);
if ((identityComposeHTML && !mdd->overrideComposeFormat) ||
(!identityComposeHTML && mdd->overrideComposeFormat))
{
// In the end, we're going to compose in HTML mode...
if (body && composeFormat == nsIMsgCompFormat::PlainText)
{
// ... 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)
@ -1479,15 +1476,28 @@ mime_parse_stream_complete (nsMIMESession *stream)
body = newbody;
}
}
// Body is now HTML, set the format too (so headers are inserted in
// correct format).
composeFormat = nsIMsgCompFormat::HTML;
}
else if ((identityComposeHTML && mdd->overrideComposeFormat) || !identityComposeHTML)
{
// In the end, we're going to compose in plain text mode...
if (composeFormat == nsIMsgCompFormat::HTML)
{
// ... but the message body is currently HTML.
// We'll do the conversion later on when headers have been
// inserted, body has been set and converted to unicode.
convertToPlainText = PR_TRUE;
}
}
}
mime_insert_forwarded_message_headers(&body, mdd->headers, composeFormat,
mdd->mailcharset);
}
// setting the charset while we are creating the composition fields
//fields->SetCharacterSet(NS_ConvertASCIItoUTF16(mdd->mailcharset));
// convert from UTF-8 to UTF-16
if (body)
@ -1515,7 +1525,13 @@ mime_parse_stream_complete (nsMIMESession *stream)
else
{
if (mdd->forwardInline)
{
if (convertToPlainText)
fields->ConvertBodyToPlainText();
if (mdd->overrideComposeFormat)
composeFormat = nsIMsgCompFormat::OppositeOfDefault;
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, composeFormat, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr);
}
else
{
fields->SetDraftId(mdd->url_name);
@ -1542,7 +1558,14 @@ mime_parse_stream_complete (nsMIMESession *stream)
printf("Time to create the composition window WITHOUT a body!!!!\n");
#endif
if (mdd->forwardInline)
CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::ForwardInline, nsIMsgCompFormat::Default, mdd->identity, mdd->originalMsgURI, mdd->origMsgHdr);
{
MSG_ComposeFormat composeFormat = (mdd->overrideComposeFormat) ?
nsIMsgCompFormat::OppositeOfDefault : nsIMsgCompFormat::Default;
CreateTheComposeWindow(fields, newAttachData,
nsIMsgCompType::ForwardInline, composeFormat,
mdd->identity, mdd->originalMsgURI,
mdd->origMsgHdr);
}
else
{
fields->SetDraftId(mdd->url_name);
@ -2018,6 +2041,7 @@ mime_bridge_create_draft_stream(
}
newPluginObj2->GetForwardInline(&mdd->forwardInline);
newPluginObj2->GetOverrideComposeFormat(&mdd->overrideComposeFormat);
newPluginObj2->GetIdentity(getter_AddRefs(mdd->identity));
newPluginObj2->GetOriginalMsgURI(&mdd->originalMsgURI);
newPluginObj2->GetOrigMsgHdr(getter_AddRefs(mdd->origMsgHdr));

Просмотреть файл

@ -156,6 +156,7 @@ struct mime_draft_data
MimeDecoderData *decoder_data;
char *mailcharset; // get it from CHARSET of Content-Type
PRBool forwardInline;
PRBool overrideComposeFormat; // Override compose format (for forward inline).
nsCOMPtr<nsIMsgIdentity> identity;
char *originalMsgURI; // the original URI of the message we are currently processing
nsCOMPtr<nsIMsgDBHdr> origMsgHdr;

Просмотреть файл

@ -530,6 +530,7 @@ nsStreamConverter::nsStreamConverter()
mOutputFormat = "text/html";
mAlreadyKnowOutputType = PR_FALSE;
mForwardInline = PR_FALSE;
mOverrideComposeFormat = PR_FALSE;
mPendingRequest = nsnull;
mPendingContext = nsnull;
@ -792,6 +793,22 @@ nsStreamConverter::SetForwardInline(PRBool forwardInline)
return NS_OK;
}
NS_IMETHODIMP
nsStreamConverter::GetOverrideComposeFormat(PRBool *aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = mOverrideComposeFormat;
return NS_OK;
}
NS_IMETHODIMP
nsStreamConverter::SetOverrideComposeFormat(PRBool aOverrideComposeFormat)
{
mOverrideComposeFormat = aOverrideComposeFormat;
return NS_OK;
}
NS_IMETHODIMP
nsStreamConverter::GetForwardInline(PRBool *result)
{

Просмотреть файл

@ -100,6 +100,7 @@ private:
nsCOMPtr<nsIMimeStreamConverterListener> mMimeStreamConverterListener;
PRBool mForwardInline;
PRBool mOverrideComposeFormat;
nsCOMPtr<nsIMsgIdentity> mIdentity;
nsCString mOriginalMsgURI;
nsCOMPtr<nsIMsgDBHdr> mOrigMsgHdr;

Просмотреть файл

@ -179,7 +179,7 @@
1040=Part %s
# default forwarded message prefix
## @name MIME_FORWARDED_MESSAGE_USER_WROTE
## @name MIME_FORWARDED_MESSAGE_HTML_USER_WROTE
## @loc
1041=-------- Original Message --------