Adding I18N support for email messages

This commit is contained in:
rhp%netscape.com 1999-04-15 00:54:58 +00:00
parent 09ebc9f463
commit a23da21d35
3 changed files with 57 additions and 22 deletions

View File

@ -319,7 +319,7 @@ static char * intl_decode_mime_part2_str(const char *, int , char* );
static char *DecodeBase64Buffer(char *subject);
static char *EncodeBase64Buffer(char *subject, size_t size);
static PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_charset,
PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_charset,
const char* inBuffer, const PRInt32 inLength,
char** outBuffer);
@ -1176,7 +1176,7 @@ char *intl_decode_mime_part2_str(const char *header, char* charset)
}
////////////////////////////////////////////////////////////////////////////////
static PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_charset,
PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_charset,
const char* inBuffer, const PRInt32 inLength,
char** outBuffer)
{

View File

@ -34,6 +34,8 @@
#include "nsMimeTransition.h"
#include "nsMsgMessageFlags.h"
#include "nsMimeAddress.h"
#include "comi18n.h"
#include "nsMailHeaders.h"
extern "C" int MK_OUT_OF_MEMORY;
extern "C" int MK_MSG_NO_HEADERS;
@ -93,6 +95,32 @@ extern "C"
char *
MIME_StripContinuations(char *original);
static int
MimeHeaders_convert_rfc1522(MimeDisplayOptions *opt,
const char *input, PRInt32 input_length,
char **output_ret, PRInt32 *output_length_ret);
char *
MimeHeaders_convert_header_value(MimeDisplayOptions *opt, char **value)
{
char *converted;
PRInt32 converted_length;
if ((!value) || (!*value))
return *value;
PRInt32 contents_length = PL_strlen(*value);
int status = MimeHeaders_convert_rfc1522(opt, *value, contents_length,
&converted, &converted_length);
if (status == 0)
{
PR_FREEIF(*value);
*value = converted;
}
return(*value);
}
MimeHeaders *
MimeHeaders_new (void)
@ -862,9 +890,7 @@ MimeHeaders_convert_rfc1522(MimeDisplayOptions *opt,
{
char *converted = 0;
PRInt32 converted_len = 0;
const char *output_charset = (opt->override_charset
? opt->override_charset
: opt->default_charset);
const char *output_charset = "UTF-8";
int status =
opt->rfc1522_conversion_fn(input, input_length,
0, output_charset, /* no input charset? */
@ -1965,11 +1991,12 @@ MimeHeaders_write_all_headers (MimeHeaders *hdrs, MimeDisplayOptions *opt, PRBoo
else
status = MimeHeaders_write_random_header_1(hdrs, name, c2, opt, PR_FALSE);
****************************************/
if (attachment)
status = mimeEmitter->AddAttachmentField(name, c2);
status = mimeEmitter->AddAttachmentField(name,
MimeHeaders_convert_header_value(opt, &c2));
else
status = mimeEmitter->AddHeaderField(name, c2);
status = mimeEmitter->AddHeaderField(name,
MimeHeaders_convert_header_value(opt, &c2));
PR_Free(name);
PR_Free(c2);
@ -2663,3 +2690,4 @@ MimeHeaders_do_unix_display_hook_hack(MimeHeaders *hdrs)
}
}
#endif /* XP_UNIX */

View File

@ -43,6 +43,7 @@
#include "nsIServiceManager.h"
#include "nsFileSpec.h"
#include "nsMimeTransition.h"
#include "comi18n.h"
#ifdef MOZ_SECURITY
#include HG01944
@ -145,22 +146,27 @@ mime_convert_charset (const char *input_line, PRInt32 input_length,
char **output_ret, PRInt32 *output_size_ret,
void *stream_closure)
{
struct mime_stream_data *msd = (struct mime_stream_data *) stream_closure;
unsigned char *converted;
extern PRInt32 INTL_ConvertCharset(const char* from_charset, const char* to_charset,
const char* inBuffer, const PRInt32 inLength,
char** outBuffer);
converted = INTL_ConvMailToWinCharCode(msd->context,
(unsigned char *) input_line,
input_length);
if (converted)
{
*output_ret = (char *) converted;
*output_size_ret = PL_strlen((char *) converted);
}
else
{
struct mime_stream_data *msd = (struct mime_stream_data *) stream_closure;
// Now do conversion to UTF-8 for output
char *convertedString = NULL;
PRInt32 res = INTL_ConvertCharset(input_charset, "UTF-8", input_line, input_length, &convertedString);
if (res != 0)
{
*output_ret = 0;
*output_size_ret = 0;
}
}
else
{
*output_ret = (char *) convertedString;
*output_size_ret = PL_strlen((char *) convertedString);
}
return 0;
}
@ -470,7 +476,8 @@ mime_insert_html_convert_charset (const char *input_line, PRInt32 input_length,
void *stream_closure)
{
struct mime_stream_data *msd = (struct mime_stream_data *) stream_closure;
int status;
int status;
INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(msd->context);
PRUint16 old_csid = INTL_GetCSIDocCSID(csi);