Bug fix 5660, changed for MIME decoder to use default charset.

This commit is contained in:
nhotta%netscape.com 1999-06-21 20:30:52 +00:00
Родитель 47997ed80c
Коммит b54a317912
2 изменённых файлов: 24 добавлений и 22 удалений

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

@ -1702,7 +1702,7 @@ PRInt32 MIME_ConvertCharset(const PRBool autoDetection, const char* from_charset
PRInt32 MIME_ConvertToUnicode(const char* from_charset, const char* inCstring,
void** uniBuffer, PRInt32* uniLength)
{
char charset[kMAX_CSNAME];
char charset[kMAX_CSNAME+1];
// Since we don't have a converter for us-ascii and the manager does not map,
// so we do the mapping here.
PL_strcpy(charset, PL_strcasecmp(from_charset, "us-ascii") ? (char *) from_charset : "iso-8859-1");
@ -1712,7 +1712,7 @@ PRInt32 MIME_ConvertToUnicode(const char* from_charset, const char* inCstring,
PRInt32 MIME_ConvertFromUnicode(const char* to_charset, const void* uniBuffer, const PRInt32 uniLength,
char** outCstring)
{
char charset[kMAX_CSNAME];
char charset[kMAX_CSNAME+1];
// Since we don't have a converter for us-ascii and the manager does not map,
// so we do the mapping here.
PL_strcpy(charset, PL_strcasecmp(to_charset, "us-ascii") ? (char *) to_charset : "iso-8859-1");
@ -1726,18 +1726,9 @@ extern "C" char *MIME_DecodeMimePartIIStr(const char *header, char *charset)
if (header == 0)
return nsnull;
// No MIME encoded, duplicate the input and put us-ascii as a charset
if (*header == '\0' || !intlmime_is_mime_part2_header(header)) {
result = PL_strdup(header);
PL_strcpy(charset, "us-ascii");
}
else {
char *header_copy = PL_strdup(header); // avoid to modify the original string
if (header_copy) {
result = MIME_StripContinuations(intl_decode_mime_part2_str(header_copy, charset));
PR_Free(header_copy);
}
// If no MIME encoded then do nothing otherwise decode the input.
if (*header != '\0' && intlmime_is_mime_part2_header(header)) {
result = MIME_StripContinuations(intl_decode_mime_part2_str(header, charset));
}
return result;

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

@ -78,25 +78,35 @@ nsMimeConverter::DecodeMimePartIIStr(const nsString& header,
nsString& charset,
nsString& decodedString)
{
char charsetCstr[kMAX_CSNAME];
char charsetCstr[kMAX_CSNAME+1];
char *encodedCstr;
char *decodedCstr;
nsresult res = NS_OK;
(void) charset.ToCString(charsetCstr, kMAX_CSNAME+1);
encodedCstr = header.ToNewCString();
if (nsnull != encodedCstr) {
PRUnichar *unichars;
PRInt32 unicharLength;
// apply MIME decode.
decodedCstr = MIME_DecodeMimePartIIStr((const char *) encodedCstr, charsetCstr);
delete [] encodedCstr;
if (nsnull == decodedCstr) {
// no decode needed, set an input string
charset.SetString("");
decodedString=header;
// no decode needed and no default charset was specified
if (*charsetCstr == '\0') {
decodedString = header;
}
else {
// no MIME encoded, convert default charset to unicode
res = MIME_ConvertToUnicode(charsetCstr, (const char *) encodedCstr,
(void **) &unichars, &unicharLength);
if (NS_SUCCEEDED(res)) {
decodedString.SetString(unichars, unicharLength);
PR_Free(unichars);
}
}
}
else {
// convert to unicode
PRUnichar *unichars;
PRInt32 unicharLength;
// convert MIME charset to unicode
res = MIME_ConvertToUnicode(charsetCstr, (const char *) decodedCstr,
(void **) &unichars, &unicharLength);
if (NS_SUCCEEDED(res)) {
@ -106,6 +116,7 @@ nsMimeConverter::DecodeMimePartIIStr(const nsString& header,
}
PR_Free(decodedCstr);
}
delete [] encodedCstr;
}
return res;
}