bug 228543 : international domain names in URLs are not recognized in email body (r=mscott, sr=bienvenu). In addition, 'const' is added to 'char *' in the function definition of some functions in libmime.

This commit is contained in:
jshin%mailaps.org 2004-01-04 07:57:16 +00:00
parent 4e0370944c
commit 9ab1afb535
29 changed files with 202 additions and 281 deletions

View File

@ -71,9 +71,9 @@ static NS_DEFINE_CID(kEntityConverterCID, NS_ENTITYCONVERTER_CID);
// International functions necessary for composition
//
nsresult nsMsgI18NConvertFromUnicode(const nsCString& aCharset,
const nsString& inString,
nsCString& outString)
nsresult nsMsgI18NConvertFromUnicode(const nsAFlatCString& aCharset,
const nsAFlatString& inString,
nsACString& outString)
{
if (inString.IsEmpty()) {
outString.Truncate(0);
@ -82,36 +82,23 @@ nsresult nsMsgI18NConvertFromUnicode(const nsCString& aCharset,
// Note: this will hide a possible error when the unicode text may contain more than one charset.
// (e.g. Latin1 + Japanese). Use nsMsgI18NSaveAsCharset instead to avoid that problem.
else if (aCharset.IsEmpty() ||
aCharset.EqualsIgnoreCase("us-ascii") ||
aCharset.EqualsIgnoreCase("ISO-8859-1")) {
outString.AssignWithConversion(inString);
aCharset.Equals("us-ascii", nsCaseInsensitiveCStringComparator()) ||
aCharset.Equals("ISO-8859-1", nsCaseInsensitiveCStringComparator())) {
LossyCopyUTF16toASCII(inString, outString);
return NS_OK;
}
else if (aCharset.EqualsIgnoreCase("UTF-8")) {
char *s = ToNewUTF8String(inString);
if (NULL == s)
return NS_ERROR_OUT_OF_MEMORY;
outString.Assign(s);
Recycle(s);
else if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) {
CopyUTF16toUTF8(inString, outString);
return NS_OK;
}
nsCAutoString convCharset(NS_LITERAL_CSTRING("ISO-8859-1"));
nsresult res;
// Resolve charset alias
nsCOMPtr <nsICharsetAlias> calias = do_GetService(NS_CHARSETALIAS_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
if (!aCharset.IsEmpty()) {
res = calias->GetPreferred(aCharset, convCharset);
}
}
nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
if(NS_SUCCEEDED(res)) {
nsCOMPtr <nsIUnicodeEncoder> encoder;
// get an unicode converter
res = ccm->GetUnicodeEncoderRaw(convCharset.get(), getter_AddRefs(encoder));
res = ccm->GetUnicodeEncoder(aCharset.get(), getter_AddRefs(encoder));
if(NS_SUCCEEDED(res)) {
res = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');
if (NS_SUCCEEDED(res)) {
@ -147,41 +134,34 @@ nsresult nsMsgI18NConvertFromUnicode(const nsCString& aCharset,
return res;
}
nsresult nsMsgI18NConvertToUnicode(const nsCString& aCharset,
const nsCString& inString,
nsString& outString)
nsresult nsMsgI18NConvertToUnicode(const nsAFlatCString& aCharset,
const nsAFlatCString& inString,
nsAString& outString)
{
if (inString.IsEmpty()) {
outString.Truncate();
return NS_OK;
}
else if (aCharset.IsEmpty() ||
aCharset.EqualsIgnoreCase("us-ascii") ||
aCharset.EqualsIgnoreCase("ISO-8859-1")) {
outString.AssignWithConversion(inString.get());
aCharset.Equals("us-ascii", nsCaseInsensitiveCStringComparator()) ||
aCharset.Equals("ISO-8859-1", nsCaseInsensitiveCStringComparator())) {
// Despite its name, it also works for Latin-1.
CopyASCIItoUTF16(inString, outString);
return NS_OK;
}
else if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) {
CopyUTF8toUTF16(inString, outString);
return NS_OK;
}
nsCAutoString convCharset;
nsresult res;
// Resolve charset alias
nsCOMPtr <nsICharsetAlias> calias = do_GetService(NS_CHARSETALIAS_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
if (!aCharset.IsEmpty()) {
res = calias->GetPreferred(aCharset, convCharset);
}
}
if (NS_FAILED(res)) {
return res;
}
nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
if(NS_SUCCEEDED(res)) {
nsCOMPtr <nsIUnicodeDecoder> decoder;
// get an unicode converter
res = ccm->GetUnicodeDecoderRaw(convCharset.get(), getter_AddRefs(decoder));
res = ccm->GetUnicodeDecoder(aCharset.get(), getter_AddRefs(decoder));
if(NS_SUCCEEDED(res)) {
const char *originalSrcPtr = inString.get();

View File

@ -120,9 +120,9 @@ NS_MSG_BASE const char * nsMsgI18NFileSystemCharset(void);
* @param outString [OUT] Converted output string.
* @return nsresult.
*/
NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const nsCString& aCharset,
const nsString& inString,
nsCString& outString);
NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const nsAFlatCString& aCharset,
const nsAFlatString& inString,
nsACString& outString);
/**
* Convert from charset to unicode.
@ -132,9 +132,9 @@ NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode(const nsCString& aCharset,
* @param outString [OUT] Output unicode string.
* @return nsresult.
*/
NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode(const nsCString& aCharset,
const nsCString& inString,
nsString& outString);
NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode(const nsAFlatCString& aCharset,
const nsAFlatCString& inString,
nsAString& outString);
/**
* Convert from unicode to target charset.

View File

@ -54,9 +54,9 @@ MimeDefClass(MimeEncrypted, MimeEncryptedClass, mimeEncryptedClass,
static int MimeEncrypted_initialize (MimeObject *);
static void MimeEncrypted_finalize (MimeObject *);
static int MimeEncrypted_parse_begin (MimeObject *);
static int MimeEncrypted_parse_buffer (char *, PRInt32, MimeObject *);
static int MimeEncrypted_parse_buffer (const char *, PRInt32, MimeObject *);
static int MimeEncrypted_parse_line (char *, PRInt32, MimeObject *);
static int MimeEncrypted_parse_decoded_buffer (char *, PRInt32, MimeObject *);
static int MimeEncrypted_parse_decoded_buffer (const char *, PRInt32, MimeObject *);
static int MimeEncrypted_parse_eof (MimeObject *, PRBool);
static int MimeEncrypted_parse_end (MimeObject *, PRBool);
static int MimeEncrypted_add_child (MimeObject *, MimeObject *);
@ -144,7 +144,7 @@ MimeEncrypted_parse_begin (MimeObject *obj)
static int
MimeEncrypted_parse_buffer (char *buffer, PRInt32 size, MimeObject *obj)
MimeEncrypted_parse_buffer (const char *buffer, PRInt32 size, MimeObject *obj)
{
/* (Duplicated from MimeLeaf, see comments in mimecryp.h.)
*/
@ -175,7 +175,7 @@ MimeEncrypted_parse_line (char *line, PRInt32 length, MimeObject *obj)
}
static int
MimeEncrypted_parse_decoded_buffer (char *buffer, PRInt32 size, MimeObject *obj)
MimeEncrypted_parse_decoded_buffer (const char *buffer, PRInt32 size, MimeObject *obj)
{
MimeEncrypted *enc = (MimeEncrypted *) obj;
return
@ -546,7 +546,7 @@ MimeEncrypted_emit_buffered_child(MimeObject *obj)
status = MimePartBufferRead(enc->part_buffer,
/* The (nsresult (*) ...) cast is to turn the `void'
argument into `MimeObject'. */
((nsresult (*) (char *, PRInt32, void *))
((nsresult (*) (const char *, PRInt32, void *))
obj->options->decompose_file_output_fn),
obj->options->stream_closure);
else
@ -555,7 +555,7 @@ MimeEncrypted_emit_buffered_child(MimeObject *obj)
status = MimePartBufferRead(enc->part_buffer,
/* The (nsresult (*) ...) cast is to turn the `void'
argument into `MimeObject'. */
((nsresult (*) (char *, PRInt32, void *))
((nsresult (*) (const char *, PRInt32, void *))
body->clazz->parse_buffer),
body);
if (status < 0) return status;

View File

@ -121,7 +121,7 @@
by the crypto_closure. output_fn may not be called.
int (*parse_decoded_buffer) (char *buf, int32 size, MimeObject *obj)
int (*parse_decoded_buffer) (const char *buf, int32 size, MimeObject *obj)
This method, of the same name as one in MimeLeaf, is a part of the
afforementioned leaf/container hybridization. This method is invoked
@ -139,7 +139,7 @@ struct MimeEncryptedClass {
/* Duplicated from MimeLeaf, see comments above.
This is the callback that is handed to the decoder. */
int (*parse_decoded_buffer) (char *buf, PRInt32 size, MimeObject *obj);
int (*parse_decoded_buffer) (const char *buf, PRInt32 size, MimeObject *obj);
/* Callbacks used by decryption module. */

View File

@ -120,7 +120,8 @@
/*
* This is the write call for outputting processed stream data.
*/
extern int MIME_MimeObject_write(MimeObject *, char *data,
extern int MIME_MimeObject_write(MimeObject *,
const char *data,
PRInt32 length,
PRBool user_visible_p);
/*

View File

@ -80,7 +80,7 @@
//
extern "C" char *MIME_StripContinuations(char *original);
nsresult mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers );
nsresult mime_decompose_file_output_fn ( char *buf, PRInt32 size, void *stream_closure );
nsresult mime_decompose_file_output_fn ( const char *buf, PRInt32 size, void *stream_closure );
nsresult mime_decompose_file_close_fn ( void *stream_closure );
extern int MimeHeaders_build_heads_list(MimeHeaders *hdrs);
@ -1973,7 +1973,7 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers )
}
nsresult
mime_decompose_file_output_fn (char *buf,
mime_decompose_file_output_fn (const char *buf,
PRInt32 size,
void *stream_closure )
{

View File

@ -54,9 +54,9 @@ MimeDefClass(MimeExternalObject, MimeExternalObjectClass,
static int MimeExternalObject_initialize (MimeObject *);
static void MimeExternalObject_finalize (MimeObject *);
static int MimeExternalObject_parse_begin (MimeObject *);
static int MimeExternalObject_parse_buffer (char *, PRInt32, MimeObject *);
static int MimeExternalObject_parse_buffer (const char *, PRInt32, MimeObject *);
static int MimeExternalObject_parse_line (char *, PRInt32, MimeObject *);
static int MimeExternalObject_parse_decoded_buffer (char*, PRInt32, MimeObject*);
static int MimeExternalObject_parse_decoded_buffer (const char*, PRInt32, MimeObject*);
static PRBool MimeExternalObject_displayable_inline_p (MimeObjectClass *clazz,
MimeHeaders *hdrs);
@ -210,7 +210,7 @@ GOTTA STILL DO THIS FOR QUOTING!
}
static int
MimeExternalObject_parse_buffer (char *buffer, PRInt32 size, MimeObject *obj)
MimeExternalObject_parse_buffer (const char *buffer, PRInt32 size, MimeObject *obj)
{
NS_ASSERTION(!obj->closed_p, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
if (obj->closed_p) return -1;
@ -233,7 +233,7 @@ MimeExternalObject_parse_buffer (char *buffer, PRInt32 size, MimeObject *obj)
static int
MimeExternalObject_parse_decoded_buffer (char *buf, PRInt32 size,
MimeExternalObject_parse_decoded_buffer (const char *buf, PRInt32 size,
MimeObject *obj)
{
/* This is called (by MimeLeafClass->parse_buffer) with blocks of data

View File

@ -213,7 +213,7 @@ test_image_make_image_html(void *image_data)
return buf;
}
static int test_image_write_buffer(char *buf, PRInt32 size, void *image_closure)
static int test_image_write_buffer(const char *buf, PRInt32 size, void *image_closure)
{
return 0;
}

View File

@ -229,7 +229,7 @@ mime_locate_external_content_handler(const char *content_type,
/* This is necessary to expose the MimeObject method outside of this DLL */
int
MIME_MimeObject_write(MimeObject *obj, char *output, PRInt32 length, PRBool user_visible_p)
MIME_MimeObject_write(MimeObject *obj, const char *output, PRInt32 length, PRBool user_visible_p)
{
return MimeObject_write(obj, output, length, user_visible_p);
}
@ -1764,7 +1764,7 @@ mime_parse_url_options(const char *url, MimeDisplayOptions *options)
*/
int
MimeOptions_write(MimeDisplayOptions *opt, char *data, PRInt32 length,
MimeOptions_write(MimeDisplayOptions *opt, const char *data, PRInt32 length,
PRBool user_visible_p)
{
int status = 0;
@ -1803,7 +1803,7 @@ MimeOptions_write(MimeDisplayOptions *opt, char *data, PRInt32 length,
}
int
MimeObject_write(MimeObject *obj, char *output, PRInt32 length,
MimeObject_write(MimeObject *obj, const char *output, PRInt32 length,
PRBool user_visible_p)
{
if (!obj->output_p) return 0;

View File

@ -425,10 +425,10 @@ extern int MimeObject_output_init(MimeObject *obj, const char *content_type);
HTML or whitespace ("<P>", "</TABLE>", etc.) This information is used
when making the decision of whether a separating <HR> is needed.
*/
extern int MimeObject_write(MimeObject *, char *data, PRInt32 length,
extern int MimeObject_write(MimeObject *, const char *data, PRInt32 length,
PRBool user_visible_p);
extern int MimeOptions_write(MimeDisplayOptions *,
char *data, PRInt32 length,
const char *data, PRInt32 length,
PRBool user_visible_p);
/* Writes out the right kind of HR (or rather, queues it for writing.) */

View File

@ -54,7 +54,7 @@ static void MimeInlineImage_finalize (MimeObject *);
static int MimeInlineImage_parse_begin (MimeObject *);
static int MimeInlineImage_parse_line (char *, PRInt32, MimeObject *);
static int MimeInlineImage_parse_eof (MimeObject *, PRBool);
static int MimeInlineImage_parse_decoded_buffer (char *, PRInt32, MimeObject *);
static int MimeInlineImage_parse_decoded_buffer (const char *, PRInt32, MimeObject *);
static int
MimeInlineImageClassInitialize(MimeInlineImageClass *clazz)
@ -209,7 +209,7 @@ MimeInlineImage_parse_eof (MimeObject *obj, PRBool abort_p)
static int
MimeInlineImage_parse_decoded_buffer (char *buf, PRInt32 size, MimeObject *obj)
MimeInlineImage_parse_decoded_buffer (const char *buf, PRInt32 size, MimeObject *obj)
{
/* This is called (by MimeLeafClass->parse_buffer) with blocks of data
that have already been base64-decoded. Pass this raw image data

View File

@ -50,7 +50,7 @@ MimeDefClass(MimeLeaf, MimeLeafClass, mimeLeafClass, &MIME_SUPERCLASS);
static int MimeLeaf_initialize (MimeObject *);
static void MimeLeaf_finalize (MimeObject *);
static int MimeLeaf_parse_begin (MimeObject *);
static int MimeLeaf_parse_buffer (char *, PRInt32, MimeObject *);
static int MimeLeaf_parse_buffer (const char *, PRInt32, MimeObject *);
static int MimeLeaf_parse_line (char *, PRInt32, MimeObject *);
static int MimeLeaf_parse_eof (MimeObject *, PRBool);
static PRBool MimeLeaf_displayable_inline_p (MimeObjectClass *clazz,
@ -149,7 +149,7 @@ MimeLeaf_parse_begin (MimeObject *obj)
static int
MimeLeaf_parse_buffer (char *buffer, PRInt32 size, MimeObject *obj)
MimeLeaf_parse_buffer (const char *buffer, PRInt32 size, MimeObject *obj)
{
MimeLeaf *leaf = (MimeLeaf *) obj;

View File

@ -47,7 +47,7 @@
applied to their data. This class provides that service in its
parse_buffer() method:
int (*parse_decoded_buffer) (char *buf, PRInt32 size, MimeObject *obj)
int (*parse_decoded_buffer) (const char *buf, PRInt32 size, MimeObject *obj)
The `parse_buffer' method of MimeLeaf passes each block of data through
the appropriate decoder (if any) and then calls `parse_decoded_buffer'
@ -66,7 +66,7 @@ typedef struct MimeLeaf MimeLeaf;
struct MimeLeafClass {
MimeObjectClass object;
/* This is the callback that is handed to the decoder. */
int (*parse_decoded_buffer) (char *buf, PRInt32 size, MimeObject *obj);
int (*parse_decoded_buffer) (const char *buf, PRInt32 size, MimeObject *obj);
};
extern MimeLeafClass mimeLeafClass;

View File

@ -350,7 +350,7 @@ MimeMultipartAlternative_display_cached_part(MimeObject *obj)
status = MimePartBufferRead (malt->part_buffer,
/* The (nsresult (*) ...) cast is to turn the
`void' argument into `MimeObject'. */
((nsresult (*) (char *, PRInt32, void *))
((nsresult (*) (const char *, PRInt32, void *))
body->clazz->parse_buffer),
body);

View File

@ -825,7 +825,7 @@ mime_convert_charset (const char *input_line, PRInt32 input_length,
}
static int
mime_output_fn(char *buf, PRInt32 size, void *stream_closure)
mime_output_fn(const char *buf, PRInt32 size, void *stream_closure)
{
PRUint32 written = 0;
struct mime_stream_data *msd = (struct mime_stream_data *) stream_closure;
@ -857,7 +857,7 @@ mime_output_fn(char *buf, PRInt32 size, void *stream_closure)
#ifdef XP_MAC
static int
compose_only_output_fn(char *buf, PRInt32 size, void *stream_closure)
compose_only_output_fn(const char *buf, PRInt32 size, void *stream_closure)
{
return 0;
}
@ -1051,7 +1051,7 @@ static void *mime_image_begin(const char *image_url, const char *content_type,
void *stream_closure);
static void mime_image_end(void *image_closure, int status);
static char *mime_image_make_image_html(void *image_data);
static int mime_image_write_buffer(char *buf, PRInt32 size, void *image_closure);
static int mime_image_write_buffer(const char *buf, PRInt32 size, void *image_closure);
/* Interface between libmime and inline display of images: the abomination
that is known as "internal-external-reconnect".
@ -1196,7 +1196,7 @@ mime_image_make_image_html(void *image_closure)
}
static int
mime_image_write_buffer(char *buf, PRInt32 size, void *image_closure)
mime_image_write_buffer(const char *buf, PRInt32 size, void *image_closure)
{
mime_image_stream_data *mid =
(mime_image_stream_data *) image_closure;

View File

@ -155,21 +155,6 @@ public:
char *m_url;
};
/* Stupid utility function. Really ought to be part of the standard string
package if you ask me...*/
static char* mime_strnchr(char* str, char c, int length)
{
int i;
for (i=0 ; i<length ; i++) {
if (*str == c) return str;
str++;
}
return NULL;
}
static int
MimeMultipartRelated_initialize(MimeObject* obj)
{
@ -735,7 +720,7 @@ MimeMultipartRelated_parse_child_line (MimeObject *obj,
static int
real_write(MimeMultipartRelated* relobj, char* buf, PRInt32 size)
real_write(MimeMultipartRelated* relobj, const char* buf, PRInt32 size)
{
MimeObject* obj = (MimeObject*) relobj;
void* closure = relobj->real_output_closure;
@ -832,7 +817,7 @@ flush_tag(MimeMultipartRelated* relobj)
if (!*buf) break;
if (isquote)
{
ptr = mime_strnchr(buf, '"', length - (buf - relobj->curtag));
ptr = PL_strnchr(buf, '"', length - (buf - relobj->curtag));
} else {
for (ptr = buf; *ptr ; ptr++) {
if (*ptr == '>' || nsCRT::IsAsciiSpace(*ptr)) break;
@ -952,7 +937,7 @@ flush_tag(MimeMultipartRelated* relobj)
static int
mime_multipart_related_output_fn(char* buf, PRInt32 size, void *stream_closure)
mime_multipart_related_output_fn(const char* buf, PRInt32 size, void *stream_closure)
{
MimeMultipartRelated *relobj = (MimeMultipartRelated *) stream_closure;
char* ptr;
@ -960,7 +945,7 @@ mime_multipart_related_output_fn(char* buf, PRInt32 size, void *stream_closure)
int status;
while (size > 0) {
if (relobj->curtag_length > 0) {
ptr = mime_strnchr(buf, '>', size);
ptr = PL_strnchr(buf, '>', size);
if (!ptr) {
return push_tag(relobj, buf, size);
}
@ -972,7 +957,7 @@ mime_multipart_related_output_fn(char* buf, PRInt32 size, void *stream_closure)
buf += delta;
size -= delta;
}
ptr = mime_strnchr(buf, '<', size);
ptr = PL_strnchr(buf, '<', size);
if (ptr && ptr - buf >= size) ptr = 0;
if (!ptr) {
return real_write(relobj, buf, size);

View File

@ -82,7 +82,7 @@ struct MimeMultipartRelated {
PLHashTable *hash;
int (*real_output_fn) (char *buf, PRInt32 size, void *stream_closure);
int (*real_output_fn) (const char *buf, PRInt32 size, void *stream_closure);
void* real_output_closure;
char* curtag;

View File

@ -730,7 +730,7 @@ MimeMultipartSigned_emit_child (MimeObject *obj)
status = MimePartBufferRead (sig->part_buffer,
/* The (nsresult (*) ...) cast is to turn the
`void' argument into `MimeObject'. */
((nsresult (*) (char *, PRInt32, void *))
((nsresult (*) (const char *, PRInt32, void *))
body->options->decompose_file_output_fn),
body->options->stream_closure);
else
@ -739,7 +739,7 @@ MimeMultipartSigned_emit_child (MimeObject *obj)
status = MimePartBufferRead (sig->part_buffer,
/* The (nsresult (*) ...) cast is to turn the
`void' argument into `MimeObject'. */
((nsresult (*) (char *, PRInt32, void *))
((nsresult (*) (const char *, PRInt32, void *))
body->clazz->parse_buffer),
body);
if (status < 0) return status;

View File

@ -48,7 +48,7 @@ MimeDefClass (MimeObject, MimeObjectClass, mimeObjectClass, NULL);
static int MimeObject_initialize (MimeObject *);
static void MimeObject_finalize (MimeObject *);
static int MimeObject_parse_begin (MimeObject *);
static int MimeObject_parse_buffer (char *, PRInt32, MimeObject *);
static int MimeObject_parse_buffer (const char *, PRInt32, MimeObject *);
static int MimeObject_parse_line (char *, PRInt32, MimeObject *);
static int MimeObject_parse_eof (MimeObject *, PRBool);
static int MimeObject_parse_end (MimeObject *, PRBool);
@ -237,7 +237,7 @@ MimeObject_parse_begin (MimeObject *obj)
}
static int
MimeObject_parse_buffer (char *buffer, PRInt32 size, MimeObject *obj)
MimeObject_parse_buffer (const char *buffer, PRInt32 size, MimeObject *obj)
{
NS_ASSERTION(!obj->closed_p, "object shouldn't be closed");
if (obj->closed_p) return -1;

View File

@ -57,7 +57,7 @@
should be finalized as well (by calling mime_free(), not by calling
their finalize() methods directly.)
int parse_buffer (char *buf, PRInt32 size, MimeObject *obj)
int parse_buffer (const char *buf, PRInt32 size, MimeObject *obj)
This is the method by which you feed arbitrary data into the parser
for this object. Most subclasses will probably inherit this method
@ -144,7 +144,7 @@ struct MimeObjectClass {
int (*initialize) (MimeObject *obj);
void (*finalize) (MimeObject *obj);
int (*parse_begin) (MimeObject *obj);
int (*parse_buffer) (char *buf, PRInt32 size, MimeObject *obj);
int (*parse_buffer) (const char *buf, PRInt32 size, MimeObject *obj);
int (*parse_line) (char *line, PRInt32 length, MimeObject *obj);
int (*parse_eof) (MimeObject *obj, PRBool abort_p);
int (*parse_end) (MimeObject *obj, PRBool abort_p);

View File

@ -271,7 +271,7 @@ MimePartBufferWrite (MimePartBufferData *data,
int
MimePartBufferRead (MimePartBufferData *data,
nsresult (*read_fn) (char *buf, PRInt32 size, void *closure),
nsresult (*read_fn) (const char *buf, PRInt32 size, void *closure),
void *closure)
{
int status = 0;

View File

@ -93,7 +93,7 @@ extern int MimePartBufferWrite (MimePartBufferData *data,
*/
extern int
MimePartBufferRead (MimePartBufferData *data,
nsresult (*read_fn) (char *buf, PRInt32 size, void *closure),
nsresult (*read_fn) (const char *buf, PRInt32 size, void *closure),
void *closure);
#endif /* _MIMEPBUF_H_ */

View File

@ -49,7 +49,7 @@ static void MimeInlineText_finalize (MimeObject *);
static int MimeInlineText_rot13_line (MimeObject *, char *line, PRInt32 length);
static int MimeInlineText_parse_eof (MimeObject *obj, PRBool abort_p);
static int MimeInlineText_parse_end (MimeObject *, PRBool);
static int MimeInlineText_parse_decoded_buffer (char *, PRInt32, MimeObject *);
static int MimeInlineText_parse_decoded_buffer (const char *, PRInt32, MimeObject *);
static int MimeInlineText_rotate_convert_and_parse_line(char *, PRInt32,
MimeObject *);
static int MimeInlineText_open_dam(char *line, PRInt32 length, MimeObject *obj);
@ -305,7 +305,7 @@ MimeInlineText_rot13_line (MimeObject *obj, char *line, PRInt32 length)
static int
MimeInlineText_parse_decoded_buffer (char *buf, PRInt32 size, MimeObject *obj)
MimeInlineText_parse_decoded_buffer (const char *buf, PRInt32 size, MimeObject *obj)
{
PR_ASSERT(!obj->closed_p);
if (obj->closed_p) return -1;

View File

@ -115,7 +115,7 @@ printf(" B2\n");
charsetline += charset;
charsetline += "\">\n";
int status = MimeObject_write(obj,
NS_CONST_CAST(char*, charsetline.get()),
charsetline.get(),
charsetline.Length(),
PR_TRUE);
PR_Free(charset);

View File

@ -64,16 +64,16 @@ static int MimeInlineTextPlainFlowed_parse_eof (MimeObject *, PRBool);
static MimeInlineTextPlainFlowedExData *MimeInlineTextPlainFlowedExDataList = nsnull;
// From mimetpla.cpp
extern "C" char *MimeTextBuildPrefixCSS(
extern "C" void MimeTextBuildPrefixCSS(
PRInt32 quotedSizeSetting, // mail.quoted_size
PRInt32 quotedStyleSetting, // mail.quoted_style
char *citationColor); // mail.citation_color
char *citationColor, // mail.citation_color
nsACString &style);
// Definition below
extern "C"
nsresult Line_convert_whitespace(const nsString& a_line,
static
nsresult Line_convert_whitespace(const nsAFlatString& a_line,
const PRBool a_convert_all_whitespace,
nsString& a_out_line);
nsAFlatString& a_out_line);
static int
MimeInlineTextPlainFlowedClassInitialize(MimeInlineTextPlainFlowedClass *clazz)
@ -195,7 +195,7 @@ MimeInlineTextPlainFlowed_parse_begin (MimeObject *obj)
openingDiv += '\"';
}
openingDiv += ">";
status = MimeObject_write(obj, NS_CONST_CAST(char*, openingDiv.get()), openingDiv.Length(), PR_FALSE);
status = MimeObject_write(obj, openingDiv.get(), openingDiv.Length(), PR_FALSE);
if (status < 0) return status;
}
@ -331,16 +331,14 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob
PRBool skipConversion = !conv ||
(obj->options && obj->options->force_user_charset);
nsString lineSource;
nsString lineResult;
lineSource.SetCapacity(kInitialBufferSize);
lineResult.SetCapacity(kInitialBufferSize);
nsAutoString lineSource;
nsXPIDLString lineResult;
char *mailCharset = NULL;
nsresult rv;
if (!skipConversion)
{
lineSource.AssignWithConversion(linep, (length - (linep - line)) );
PRUnichar* wresult = nsnull;
nsresult rv = NS_OK;
PRBool whattodo = obj->options->whattodo;
if (plainHTML)
{
@ -353,60 +351,36 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob
might not be able to display the glyphs. */
}
// Get a mail charset of this message.
MimeInlineText *inlinetext = (MimeInlineText *) obj;
char *mailCharset = NULL;
if (inlinetext->charset && *(inlinetext->charset))
nsDependentCString inputStr(linep, length - (linep - line));
// For 'SaveAs', |line| is in |mailCharset|.
// convert |line| to UTF-16 before 'html'izing (calling ScanTXT())
if (obj->options->format_out == nsMimeOutput::nsMimeMessageSaveAs)
{
// Get the mail charset of this message.
MimeInlineText *inlinetext = (MimeInlineText *) obj;
if (!inlinetext->initializeCharset)
((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj);
mailCharset = inlinetext->charset;
if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||
!mailCharset || !nsMsgI18Nstateful_charset(mailCharset))
{
/* This is the main TXT to HTML conversion:
escaping (very important), eventually recognizing etc. */
rv = conv->ScanTXT(lineSource.get(), whattodo, &wresult);
if (NS_FAILED(rv)) return -1;
lineResult = wresult;
Recycle(wresult);
}
else
{
// If nsMimeMessageSaveAs, the string is in mail charset (and stateful, e.g. ISO-2022-JP).
// convert to unicode so it won't confuse ScanTXT.
char *newcstr;
newcstr = ToNewCString(lineSource); // lineSource uses nsString but the string is NOT unicode
if (!newcstr) return -1;
nsAutoString ustr;
nsCAutoString cstr;
nsCAutoString mailCharsetStr(mailCharset);
cstr.Assign(newcstr);
Recycle(newcstr);
rv = nsMsgI18NConvertToUnicode(mailCharsetStr, cstr, ustr);
if (NS_SUCCEEDED(rv))
{
PRUnichar *u;
rv = conv->ScanTXT(ustr.get(), whattodo, &u);
if (NS_SUCCEEDED(rv))
{
ustr.Assign(u);
Recycle(u);
rv = nsMsgI18NConvertFromUnicode(mailCharsetStr, ustr, cstr);
if (NS_SUCCEEDED(rv))
lineResult.AssignWithConversion(cstr.get()); // create nsString which contains NON unicode
// as the following code expecting it
}
if (mailCharset && *mailCharset) {
rv = nsMsgI18NConvertToUnicode(nsDependentCString(mailCharset),
inputStr, lineSource);
NS_ENSURE_SUCCESS(rv, -1);
}
if (NS_FAILED(rv))
return -1;
else // this probably never happens...
CopyUTF8toUTF16(inputStr, lineSource);
}
else // line is in UTF-8
CopyUTF8toUTF16(inputStr, lineSource);
// This is the main TXT to HTML conversion:
// escaping (very important), eventually recognizing etc.
rv = conv->ScanTXT(lineSource.get(), whattodo, getter_Copies(lineResult));
NS_ENSURE_SUCCESS(rv, -1);
}
else
{
lineResult.AssignWithConversion(line, length);
CopyUTF8toUTF16(nsDependentCString(line, length), lineResult);
status = NS_OK;
}
@ -427,16 +401,16 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob
preface += "<blockquote type=cite";
// This is to have us observe the user pref settings for citations
MimeInlineTextPlainFlowed *tObj = (MimeInlineTextPlainFlowed *) obj;
char *style = MimeTextBuildPrefixCSS(tObj->mQuotedSizeSetting,
tObj->mQuotedStyleSetting,
tObj->mCitationColor);
if (!plainHTML && style && strlen(style))
nsCAutoString style;
MimeTextBuildPrefixCSS(tObj->mQuotedSizeSetting, tObj->mQuotedStyleSetting,
tObj->mCitationColor, style);
if (!plainHTML && !style.IsEmpty())
{
preface += " style=\"";
preface += style;
preface += '"';
}
PR_FREEIF(style);
preface += '>';
}
while(quoteleveldiff<0) {
@ -445,8 +419,7 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob
}
exdata->quotelevel = linequotelevel;
nsString lineResult2;
lineResult2.SetCapacity(kInitialBufferSize);
nsAutoString lineResult2;
if(flowed) {
// Check RFC 2646 "4.3. Usenet Signature Convention": "-- "+CRLF is
@ -489,12 +462,19 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob
if (!(exdata->isSig && quoting))
{
char* tmp = ToNewCString(preface);
status = MimeObject_write(obj, tmp, preface.Length(), PR_TRUE);
Recycle(tmp);
tmp = ToNewCString(lineResult2);
status = MimeObject_write(obj, tmp, lineResult2.Length(), PR_TRUE);
Recycle(tmp);
status = MimeObject_write(obj, preface.get(), preface.Length(), PR_TRUE);
if (status < 0) return status;
nsCAutoString outString;
if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||
!mailCharset || !*mailCharset)
CopyUTF16toUTF8(lineResult2, outString);
else
{ // convert back to mailCharset before writing.
rv = nsMsgI18NConvertFromUnicode(nsDependentCString(mailCharset),
lineResult2, outString);
NS_ENSURE_SUCCESS(rv, -1);
}
status = MimeObject_write(obj, outString.get(), outString.Length(), PR_TRUE);
return status;
}
else
@ -575,7 +555,7 @@ static void Update_in_tag_info(PRBool *a_in_tag, /* IN/OUT */
static void Convert_whitespace(const PRUnichar a_current_char,
const PRUnichar a_next_char,
const PRBool a_convert_all_whitespace,
nsString& a_out_string)
nsAFlatString& a_out_string)
{
NS_ASSERTION('\t' == a_current_char || ' ' == a_current_char,
"Convert_whitespace got something else than a whitespace!");
@ -615,10 +595,10 @@ static void Convert_whitespace(const PRUnichar a_current_char,
* converted.
* @param out a_out_string, result will be appended.
*/
extern "C"
nsresult Line_convert_whitespace(const nsString& a_line,
static
nsresult Line_convert_whitespace(const nsAFlatString& a_line,
const PRBool a_convert_all_whitespace,
nsString& a_out_line)
nsAFlatString& a_out_line)
{
PRBool in_tag = PR_FALSE;
PRBool in_quote_in_tag = PR_FALSE;

View File

@ -73,26 +73,24 @@ MimeInlineTextPlainClassInitialize(MimeInlineTextPlainClass *clazz)
}
extern "C"
char *
void
MimeTextBuildPrefixCSS(PRInt32 quotedSizeSetting, // mail.quoted_size
PRInt32 quotedStyleSetting, // mail.quoted_style
char *citationColor) // mail.citation_color
char *citationColor, // mail.citation_color
nsACString &style)
{
char *formatCstr = nsnull;
nsCString formatString;
switch (quotedStyleSetting)
{
case 0: // regular
break;
case 1: // bold
formatString.Append("font-weight: bold; ");
style.Append("font-weight: bold; ");
break;
case 2: // italic
formatString.Append("font-style: italic; ");
style.Append("font-style: italic; ");
break;
case 3: // bold-italic
formatString.Append("font-weight: bold; font-style: italic; ");
style.Append("font-weight: bold; font-style: italic; ");
break;
}
@ -101,22 +99,19 @@ MimeTextBuildPrefixCSS(PRInt32 quotedSizeSetting, // mail.quoted_size
case 0: // regular
break;
case 1: // large
formatString.Append("font-size: large; ");
style.Append("font-size: large; ");
break;
case 2: // small
formatString.Append("font-size: small; ");
style.Append("font-size: small; ");
break;
}
if (citationColor && *citationColor)
{
formatString += "color: ";
formatString += citationColor;
formatString += ';';
style += "color: ";
style += citationColor;
style += ';';
}
formatCstr = ToNewCString(formatString);
return formatCstr;
}
static int
@ -234,7 +229,7 @@ MimeInlineTextPlain_parse_begin (MimeObject *obj)
}
else
openingDiv = "<pre wrap>";
status = MimeObject_write(obj, NS_CONST_CAST(char*, openingDiv.get()), openingDiv.Length(), PR_FALSE);
status = MimeObject_write(obj, openingDiv.get(), openingDiv.Length(), PR_FALSE);
if (status < 0) return status;
/* text/plain objects always have separators before and after them.
@ -335,11 +330,33 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
PRBool skipConversion = !conv || rawPlainText ||
(obj->options && obj->options->force_user_charset);
char *mailCharset = NULL;
nsresult rv;
if (!skipConversion)
{
nsString lineSourceStr;
lineSourceStr.AssignWithConversion(line, length);
nsresult rv;
nsDependentCString inputStr(line, length);
nsAutoString lineSourceStr;
// For 'SaveAs', |line| is in |mailCharset|.
// convert |line| to UTF-16 before 'html'izing (calling ScanTXT())
if (obj->options->format_out == nsMimeOutput::nsMimeMessageSaveAs)
{ // Get the mail charset of this message.
MimeInlineText *inlinetext = (MimeInlineText *) obj;
if (!inlinetext->initializeCharset)
((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj);
mailCharset = inlinetext->charset;
if (mailCharset && *mailCharset) {
rv = nsMsgI18NConvertToUnicode(nsDependentCString(mailCharset),
inputStr, lineSourceStr);
NS_ENSURE_SUCCESS(rv, -1);
}
else // this probably never happens ...
CopyUTF8toUTF16(inputStr, lineSourceStr);
}
else // line is in UTF-8
CopyUTF8toUTF16(inputStr, lineSourceStr);
nsCAutoString prefaceResultStr; // Quoting stuff before the real text
// Recognize quotes
@ -347,8 +364,7 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
PRUint32 logicalLineStart = 0;
rv = conv->CiteLevelTXT(lineSourceStr.get(),
&logicalLineStart, &(text->mCiteLevel));
if (NS_FAILED(rv))
return -1;
NS_ENSURE_SUCCESS(rv, -1);
// Find out, which recognitions to do
PRBool whattodo = obj->options->whattodo;
@ -371,10 +387,10 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
prefaceResultStr += "</pre>";
for (PRUint32 i = 0; i < text->mCiteLevel - oldCiteLevel; i++)
{
char *style = MimeTextBuildPrefixCSS(text->mQuotedSizeSetting,
text->mQuotedStyleSetting,
text->mCitationColor);
if (!plainHTML && style && strlen(style))
nsCAutoString style;
MimeTextBuildPrefixCSS(text->mQuotedSizeSetting, text->mQuotedStyleSetting,
text->mCitationColor, style);
if (!plainHTML && !style.IsEmpty())
{
prefaceResultStr += "<blockquote type=cite style=\"";
prefaceResultStr += style;
@ -382,7 +398,6 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
}
else
prefaceResultStr += "<blockquote type=cite>";
Recycle(style);
}
prefaceResultStr += "<pre wrap>";
}
@ -405,11 +420,6 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
nsAutoString citeTagsSource;
lineSourceStr.Mid(citeTagsSource, 0, logicalLineStart);
NS_ASSERTION(citeTagsSource.IsASCII(), "Non-ASCII-Chars are about to be "
"added to nsCAutoString prefaceResultStr. "
"Change the latter to nsAutoString.");
/* I'm currently using nsCAutoString, because currently citeTagsSource
is always ASCII and I save 2 conversions this way. */
// Convert to HTML
nsXPIDLString citeTagsResultUnichar;
@ -417,10 +427,7 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
getter_Copies(citeTagsResultUnichar));
if (NS_FAILED(rv)) return -1;
// Convert to char* and write out
nsCAutoString citeTagsResultCStr;
CopyUCS2toASCII(citeTagsResultUnichar, citeTagsResultCStr);
prefaceResultStr += citeTagsResultCStr;
AppendUTF16toUTF8(citeTagsResultUnichar, prefaceResultStr);
if (!plainHTML)
prefaceResultStr += "</span>";
}
@ -437,62 +444,31 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
prefaceResultStr += "<div class=\"moz-txt-sig\">";
}
// Get a mail charset of this message.
MimeInlineText *inlinetext = (MimeInlineText *) obj;
char *mailCharset = NULL;
if (inlinetext->charset && *(inlinetext->charset))
mailCharset = inlinetext->charset;
/* This is the main TXT to HTML conversion:
escaping (very important), eventually recognizing etc. */
nsXPIDLString lineResultUnichar;
if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||
!mailCharset || !nsMsgI18Nstateful_charset(mailCharset))
{
rv = conv->ScanTXT(lineSourceStr.get() + logicalLineStart,
whattodo, getter_Copies(lineResultUnichar));
if (NS_FAILED(rv)) return -1;
}
else
{
// If nsMimeMessageSaveAs, the string is in mail charset (and stateful, e.g. ISO-2022-JP).
// convert to unicode so it won't confuse ScanTXT.
nsAutoString ustr;
nsCAutoString cstr(line, length);
nsCAutoString mailCharsetStr(mailCharset);
rv = nsMsgI18NConvertToUnicode(mailCharsetStr, cstr, ustr);
if (NS_SUCCEEDED(rv))
{
nsXPIDLString u;
rv = conv->ScanTXT(ustr.get() + logicalLineStart, whattodo, getter_Copies(u));
if (NS_SUCCEEDED(rv))
{
ustr.Assign(u);
rv = nsMsgI18NConvertFromUnicode(mailCharsetStr, ustr, cstr);
if (NS_SUCCEEDED(rv))
{
// create PRUnichar* which contains NON unicode
// as the following code expecting it
lineResultUnichar.Adopt(ToNewUnicode(cstr));
if (!lineResultUnichar) return -1;
}
}
}
if (NS_FAILED(rv))
return -1;
}
rv = conv->ScanTXT(lineSourceStr.get() + logicalLineStart,
whattodo, getter_Copies(lineResultUnichar));
NS_ENSURE_SUCCESS(rv, -1);
if (!(text->mIsSig && quoting))
{
status = MimeObject_write(obj, NS_CONST_CAST(char*, prefaceResultStr.get()), prefaceResultStr.Length(), PR_TRUE);
if (status < 0) return status;
nsCAutoString lineResultCStr;
CopyUCS2toASCII(lineResultUnichar, lineResultCStr);
status = MimeObject_write(obj, NS_CONST_CAST(char*, lineResultCStr.get()), lineResultCStr.Length(), PR_TRUE);
status = MimeObject_write(obj, prefaceResultStr.get(), prefaceResultStr.Length(), PR_TRUE);
if (status < 0) return status;
nsCAutoString outString;
if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||
!mailCharset || !*mailCharset)
CopyUTF16toUTF8(lineResultUnichar, outString);
else
{ // convert back to mailCharset before writing.
rv = nsMsgI18NConvertFromUnicode(nsDependentCString(mailCharset),
lineResultUnichar, outString);
NS_ENSURE_SUCCESS(rv, -1);
}
status = MimeObject_write(obj, outString.get(), outString.Length(), PR_TRUE);
}
else
{
@ -502,7 +478,6 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
else
{
status = MimeObject_write(obj, line, length, PR_TRUE);
if (status < 0) return status;
}
return status;

View File

@ -66,7 +66,7 @@ MimeInlineTextRichtextClassInitialize(MimeInlineTextRichtextClass *clazz)
*/
int
MimeRichtextConvert (char *line, PRInt32 length,
int (*output_fn) (char *buf, PRInt32 size, void *closure),
int (*output_fn) (const char *buf, PRInt32 size, void *closure),
void *closure,
char **obufferP,
PRInt32 *obuffer_sizeP,

View File

@ -62,7 +62,7 @@ struct MimeInlineTextRichtext {
extern int
MimeRichtextConvert (char *line, PRInt32 length,
int (*output_fn) (char *buf, PRInt32 size, void *closure),
int (*output_fn) (const char *buf, PRInt32 size, void *closure),
void *closure,
char **obufferP,
PRInt32 *obuffer_sizeP,

View File

@ -249,7 +249,7 @@ public:
void *stream_closure);
/* How the MIME parser feeds its output (HTML or raw) back to the caller. */
int (*output_fn) (char *buf, PRInt32 size, void *closure);
int (*output_fn) (const char *buf, PRInt32 size, void *closure);
/* Closure to pass to the above output_fn. If NULL, then the
stream_closure is used. */
@ -333,7 +333,7 @@ public:
void (*image_end) (void *image_closure, int status);
/* Dump some raw image data down the stream. */
int (*image_write_buffer) (char *buf, PRInt32 size, void *image_closure);
int (*image_write_buffer) (const char *buf, PRInt32 size, void *image_closure);
/* What HTML should be dumped out for this image. */
char *(*make_image_html) (void *image_closure);
@ -380,7 +380,7 @@ public:
nsresult (*decompose_file_init_fn) (void *stream_closure,
MimeHeaders *headers );
nsresult (*decompose_file_output_fn) (char *buf, PRInt32 size,
nsresult (*decompose_file_output_fn) (const char *buf, PRInt32 size,
void *stream_closure);
nsresult (*decompose_file_close_fn) (void *stream_closure);