Changed mime_generate_attachment_headers to pass both attachment charset and main body's charset,

and use the main body's charset to encode attachment filename then fallback to system's default,
bug 160801, r=ducarroz, sr=bienvenu.
This commit is contained in:
nhotta%netscape.com 2002-08-12 19:13:54 +00:00
Родитель 0895bbb959
Коммит c5507153ab
3 изменённых файлов: 38 добавлений и 18 удалений

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

@ -723,7 +723,8 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
const char *base_url,
PRBool /*digest_p*/,
nsMsgAttachmentHandler * /*ma*/,
const char *charset,
const char *attachmentCharset,
const char *bodyCharset,
PRBool bodyIsAsciiOnly,
const char *content_id,
PRBool aBodyDocument)
@ -747,18 +748,28 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
/* Let's encode the real name */
char *encodedRealName = nsnull;
nsXPIDLCString charset; // actual charset used for MIME encode
if (real_name)
{
encodedRealName = nsMsgI18NEncodeMimePartIIStr(real_name, PR_FALSE, nsMsgI18NFileSystemCharset(), 0, usemime);
// first try main body's charset to encode the file name,
// then try local file system charset if fails
NS_ConvertUTF8toUCS2 realName(real_name);
if (bodyCharset && *bodyCharset &&
nsMsgI18Ncheck_data_in_charset_range(bodyCharset, realName.get()))
charset.Assign(bodyCharset);
else
{
charset.Assign(nsMsgI18NFileSystemCharset());
if (!nsMsgI18Ncheck_data_in_charset_range(charset.get(), realName.get()))
charset.Assign("UTF-8"); // set to UTF-8 if fails again
}
encodedRealName = nsMsgI18NEncodeMimePartIIStr(real_name, PR_FALSE, charset.get(), 0, usemime);
if (!encodedRealName || !*encodedRealName)
{
/* Let's try one more time using UTF8 */
encodedRealName = nsMsgI18NEncodeMimePartIIStr(real_name, PR_FALSE, "UTF-8", 0, usemime);
if (!encodedRealName || !*encodedRealName)
{
PR_FREEIF(encodedRealName);
encodedRealName = PL_strdup(real_name);
}
PR_Free(encodedRealName);
encodedRealName = PL_strdup(real_name);
charset.Assign("us-ascii");
}
/* ... and then put backslashes before special characters (RFC 822 tells us to). */
@ -777,8 +788,11 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
{
char charset_label[65] = ""; // Content-Type: charset
PL_strncpy(charset_label, charset, sizeof(charset_label)-1);
charset_label[sizeof(charset_label)-1] = '\0';
if (attachmentCharset)
{
PL_strncpy(charset_label, attachmentCharset, sizeof(charset_label)-1);
charset_label[sizeof(charset_label)-1] = '\0';
}
/* If the characters are all 7bit, then it's better (and true) to
claim the charset to be US- rather than Latin1. Should we
@ -791,7 +805,7 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
// If charset is multibyte then no charset to be specified (apply base64 instead).
// The list of file types match with PickEncoding() where we put base64 label.
if ( ((charset && !nsMsgI18Nmultibyte_charset(charset)) ||
if ( ((attachmentCharset && !nsMsgI18Nmultibyte_charset(attachmentCharset)) ||
((PL_strcasecmp(type, TEXT_HTML) == 0) ||
(PL_strcasecmp(type, TEXT_MDL) == 0) ||
(PL_strcasecmp(type, TEXT_PLAIN) == 0) ||
@ -815,7 +829,7 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
// Add format=flowed as in RFC 2646 if we are using that
if(type && !PL_strcasecmp(type, "text/plain"))
{
if(UseFormatFlowed(charset))
if(UseFormatFlowed(bodyCharset))
PUSH_STRING ("; format=flowed");
// else
// {
@ -848,7 +862,7 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
}
else // if (parmFolding == 2)
{
char *rfc2231Parm = RFC2231ParmFolding("name", charset,
char *rfc2231Parm = RFC2231ParmFolding("name", charset.get(),
nsMsgI18NGetAcceptLanguage(), encodedRealName);
if (rfc2231Parm) {
PUSH_STRING(";\r\n ");
@ -917,7 +931,7 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
}
else // if (parmFolding == 2)
{
char *rfc2231Parm = RFC2231ParmFolding("filename", charset,
char *rfc2231Parm = RFC2231ParmFolding("filename", charset.get(),
nsMsgI18NGetAcceptLanguage(), encodedRealName);
if (rfc2231Parm) {
PUSH_STRING(";\r\n ");

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

@ -103,7 +103,8 @@ char *mime_generate_attachment_headers (const char *type,
const char *base_url,
PRBool digest_p,
nsMsgAttachmentHandler *ma,
const char *charset,
const char *attachmentCharset, // charset of the attachment (can be null)
const char *bodyCharset, // charset of the main body
PRBool bodyIsAsciiOnly,
const char *content_id,
PRBool aBodyDocument);

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

@ -822,6 +822,7 @@ nsMsgComposeAndSend::GatherMimeAttachments()
m_plaintext->AnalyzeSnarfedFile(); // look for 8 bit text, long lines, etc.
m_plaintext->PickEncoding(mCompFields->GetCharacterSet(), this);
const char *charset = mCompFields->GetCharacterSet();
hdrs = mime_generate_attachment_headers(m_plaintext->m_type,
m_plaintext->m_encoding,
m_plaintext->m_description,
@ -830,7 +831,8 @@ nsMsgComposeAndSend::GatherMimeAttachments()
nsnull, 0,
m_digest_p,
m_plaintext,
mCompFields->GetCharacterSet(),
charset,
charset,
mCompFields->GetBodyIsAsciiOnly(),
nsnull,
PR_TRUE);
@ -1024,12 +1026,14 @@ nsMsgComposeAndSend::GatherMimeAttachments()
//
if ((!plainpart) || (plainpart != mainbody))
{
const char *charset = mCompFields->GetCharacterSet();
hdrs = mime_generate_attachment_headers (m_attachment1_type,
m_attachment1_encoding,
0, 0, 0, 0, 0,
m_digest_p,
nsnull, /* no "ma"! */
mCompFields->GetCharacterSet(),
charset,
charset,
mCompFields->GetBodyIsAsciiOnly(),
nsnull,
PR_TRUE);
@ -1254,6 +1258,7 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma,
// we determine from
// the file or none
// at all!
mCompFields->GetCharacterSet(),
PR_FALSE, // bodyIsAsciiOnly to false
// for attachments
ma->m_content_id,