Changed to pass a default charset to MIME decoder.

The decoder can use the default if it's indicated in case no charset specified in the header itself,
bug 66098, r=ducarroz, sr=bienvenu.
This commit is contained in:
nhotta%netscape.com 2001-02-12 21:55:19 +00:00
Родитель 3df3cdb319
Коммит a1987d45e4
2 изменённых файлов: 23 добавлений и 29 удалений

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

@ -952,7 +952,7 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI,
nsAutoString subjectStr; nsAutoString subjectStr;
nsAutoString aCharset; nsAutoString aCharset;
nsAutoString decodedString; nsAutoString decodedString;
nsAutoString encodedCharset; // we don't use this nsAutoString encodedCharset;
nsXPIDLCString charset; nsXPIDLCString charset;
char *aCString = nsnull; char *aCString = nsnull;
@ -996,8 +996,9 @@ nsresult nsMsgCompose::CreateMessage(const PRUnichar * originalMsgURI,
// get an original charset, used for a label, UTF-8 is used for the internal processing // get an original charset, used for a label, UTF-8 is used for the internal processing
if (!aCharset.IsEmpty()) if (!aCharset.IsEmpty())
{ {
nsCAutoString aCharsetCStr; aCharsetCStr.AssignWithConversion(aCharset); m_compFields->SetCharacterSet(aCharset.GetUnicode());
m_compFields->SetCharacterSet(aCharsetCStr); // set an original charset so MIME decoder can use it in case the header has no label
encodedCharset = aCharset;
} }
subjectStr.AppendWithConversion("Re: "); subjectStr.AppendWithConversion("Re: ");

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

@ -77,7 +77,7 @@ int mime_decompose_file_output_fn ( char *buf, PRInt32 size, voi
int mime_decompose_file_close_fn ( void *stream_closure ); int mime_decompose_file_close_fn ( void *stream_closure );
extern int MimeHeaders_build_heads_list(MimeHeaders *hdrs); extern int MimeHeaders_build_heads_list(MimeHeaders *hdrs);
static nsString& mime_decode_string(const char* str , static nsString& mime_decode_string(const char* str , const char* defaultCharset,
PRBool eatContinuations = PR_TRUE); PRBool eatContinuations = PR_TRUE);
// CID's // CID's
@ -227,11 +227,12 @@ mime_dump_attachments ( attachmentList );
return rv; return rv;
} }
static nsString& mime_decode_string(const char* str, static nsString& mime_decode_string(const char* str, const char* defaultCharset,
PRBool eatContinuations) PRBool eatContinuations)
{ {
static nsString decodedString; static nsString decodedString;
nsString encodedCharset; nsString encodedCharset;
encodedCharset.AssignWithConversion(defaultCharset); // in case the header has no charset specified
nsMsgI18NDecodeMimePartIIStr(NS_ConvertASCIItoUCS2(str), encodedCharset, nsMsgI18NDecodeMimePartIIStr(NS_ConvertASCIItoUCS2(str), encodedCharset,
decodedString, eatContinuations); decodedString, eatContinuations);
return decodedString; return decodedString;
@ -269,21 +270,21 @@ CreateCompositionFields(const char *from,
// Now set all of the passed in stuff... // Now set all of the passed in stuff...
cFields->SetCharacterSet(NS_ConvertASCIItoUCS2(charset).GetUnicode()); cFields->SetCharacterSet(NS_ConvertASCIItoUCS2(charset).GetUnicode());
cFields->SetFrom(mime_decode_string(from).GetUnicode()); cFields->SetFrom(mime_decode_string(from, charset).GetUnicode());
cFields->SetSubject(mime_decode_string(subject).GetUnicode()); cFields->SetSubject(mime_decode_string(subject, charset).GetUnicode());
cFields->SetReplyTo(mime_decode_string(reply_to).GetUnicode()); cFields->SetReplyTo(mime_decode_string(reply_to, charset).GetUnicode());
cFields->SetTo(mime_decode_string(to).GetUnicode()); cFields->SetTo(mime_decode_string(to, charset).GetUnicode());
cFields->SetCc(mime_decode_string(cc).GetUnicode()); cFields->SetCc(mime_decode_string(cc, charset).GetUnicode());
cFields->SetBcc(mime_decode_string(bcc).GetUnicode()); cFields->SetBcc(mime_decode_string(bcc, charset).GetUnicode());
cFields->SetFcc(mime_decode_string(fcc).GetUnicode()); cFields->SetFcc(mime_decode_string(fcc, charset).GetUnicode());
cFields->SetNewsgroups(mime_decode_string(newsgroups).GetUnicode()); cFields->SetNewsgroups(mime_decode_string(newsgroups, charset).GetUnicode());
cFields->SetFollowupTo(mime_decode_string(followup_to).GetUnicode()); cFields->SetFollowupTo(mime_decode_string(followup_to, charset).GetUnicode());
cFields->SetOrganization(mime_decode_string(organization).GetUnicode()); cFields->SetOrganization(mime_decode_string(organization, charset).GetUnicode());
cFields->SetReferences(mime_decode_string(references).GetUnicode()); cFields->SetReferences(mime_decode_string(references, charset).GetUnicode());
cFields->SetOtherRandomHeaders(mime_decode_string(other_random_headers).GetUnicode()); cFields->SetOtherRandomHeaders(mime_decode_string(other_random_headers, charset).GetUnicode());
cFields->SetPriority(mime_decode_string(priority).GetUnicode()); cFields->SetPriority(mime_decode_string(priority, charset).GetUnicode());
cFields->SetAttachments(mime_decode_string(attachment).GetUnicode()); cFields->SetAttachments(mime_decode_string(attachment, charset).GetUnicode());
cFields->SetNewspostUrl(mime_decode_string(newspost_url).GetUnicode()); cFields->SetNewspostUrl(mime_decode_string(newspost_url, charset).GetUnicode());
return cFields; return cFields;
} }
@ -559,7 +560,7 @@ mime_intl_insert_message_header_1(char **body,
mime_SACat(body, ": "); mime_SACat(body, ": ");
// MIME decode header and convert to UTF-8 // MIME decode header and convert to UTF-8
nsAutoString ucs2(mime_decode_string(*hdr_value)); nsAutoString ucs2(mime_decode_string(*hdr_value, mailcharset));
char* utf8 = ucs2.ToNewUTF8String(); char* utf8 = ucs2.ToNewUTF8String();
if (NULL != utf8) { if (NULL != utf8) {
mime_SACat(body, utf8); mime_SACat(body, utf8);
@ -1182,13 +1183,6 @@ mime_parse_stream_complete (nsMIMESession *stream)
refs = MimeHeaders_get(mdd->headers, HEADER_REFERENCES, PR_FALSE, PR_TRUE); refs = MimeHeaders_get(mdd->headers, HEADER_REFERENCES, PR_FALSE, PR_TRUE);
priority = MimeHeaders_get(mdd->headers, HEADER_X_PRIORITY, PR_FALSE, PR_FALSE); priority = MimeHeaders_get(mdd->headers, HEADER_X_PRIORITY, PR_FALSE, PR_FALSE);
mime_intl_mimepart_2_str(&repl, mdd->mailcharset);
mime_intl_mimepart_2_str(&to, mdd->mailcharset);
mime_intl_mimepart_2_str(&cc, mdd->mailcharset);
mime_intl_mimepart_2_str(&bcc, mdd->mailcharset);
mime_intl_mimepart_2_str(&grps, mdd->mailcharset);
mime_intl_mimepart_2_str(&foll, mdd->mailcharset);
mime_intl_mimepart_2_str(&host, mdd->mailcharset);
if (host) if (host)
{ {
@ -1207,7 +1201,6 @@ mime_parse_stream_complete (nsMIMESession *stream)
} }
} }
mime_intl_mimepart_2_str(&subj, mdd->mailcharset);
fields = CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll, fields = CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll,
org, subj, refs, 0, priority, 0, news_host, org, subj, refs, 0, priority, 0, news_host,