From 26524d4a05dc4bb8cde52f7ca52d4e8af4e9b717 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 22 Jul 2002 23:34:34 +0000 Subject: Removed a lot of extra g_return_if_fail's that we don't need (if we are 2002-07-22 Jeffrey Stedfast * e-msg-composer.c: Removed a lot of extra g_return_if_fail's that we don't need (if we are going to check if the pointer is a a composer widget using the gtk type-check macros, then there is no need to first check that it isn't NULL). (get_file_content): Signatures are now supposed to be in UTF-8 and not the user's locale charset, so we must first read in the content, then check that it is valid UTF-8. If it isn't, then we need to try to convert it to UTF-8. svn path=/trunk/; revision=17538 --- composer/ChangeLog | 4 ++++ composer/e-msg-composer.c | 48 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 12 deletions(-) (limited to 'composer') diff --git a/composer/ChangeLog b/composer/ChangeLog index 0fb25d1c2f..24241afd81 100644 --- a/composer/ChangeLog +++ b/composer/ChangeLog @@ -4,6 +4,10 @@ we don't need (if we are going to check if the pointer is a a composer widget using the gtk type-check macros, then there is no need to first check that it isn't NULL). + (get_file_content): Signatures are now supposed to be in UTF-8 and + not the user's locale charset, so we must first read in the + content, then check that it is valid UTF-8. If it isn't, then we + need to try to convert it to UTF-8. 2002-07-22 Radek Doulik diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index a56ced92b9..d3aff4395c 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -766,7 +766,7 @@ build_message (EMsgComposer *composer, gboolean save_html_object_data) static char * get_file_content (EMsgComposer *composer, const char *file_name, gboolean want_html, guint flags, gboolean warn) { - CamelStreamFilter *filtered_stream; + CamelStreamFilter *filtered_stream; CamelStreamMem *memstream; CamelMimeFilter *html, *charenc; CamelStream *stream; @@ -789,27 +789,51 @@ get_file_content (EMsgComposer *composer, const char *file_name, gboolean want_h } stream = camel_stream_fs_new_with_fd (fd); - filtered_stream = camel_stream_filter_new_with_stream (stream); - camel_object_unref (CAMEL_OBJECT (stream)); - - charset = composer ? composer->charset : mail_config_get_default_charset (); - charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "utf-8"); - camel_stream_filter_add (filtered_stream, charenc); - camel_object_unref (CAMEL_OBJECT (charenc)); if (want_html) { + filtered_stream = camel_stream_filter_new_with_stream (stream); + camel_object_unref (stream); + html = camel_mime_filter_tohtml_new (flags, 0); camel_stream_filter_add (filtered_stream, html); - camel_object_unref (CAMEL_OBJECT (html)); + camel_object_unref (html); + + stream = (CamelStream *) filtered_stream; } memstream = (CamelStreamMem *) camel_stream_mem_new (); buffer = g_byte_array_new (); camel_stream_mem_set_byte_array (memstream, buffer); - camel_stream_write_to_stream (CAMEL_STREAM (filtered_stream), CAMEL_STREAM (memstream)); - camel_object_unref (CAMEL_OBJECT (filtered_stream)); - camel_object_unref (CAMEL_OBJECT (memstream)); + camel_stream_write_to_stream (stream, (CamelStream *) memstream); + camel_object_unref (stream); + + /* The newer signature UI saves signatures in UTF-8, but we still need to check that + the signature is valid UTF-8 because it is possible that the user imported a + signature file that is in his/her locale charset. If it's not in UTF-8 and not in + the charset the composer is in (or their default mail charset) then fuck it, + there's nothing we can do. */ + if (!g_utf8_validate (buffer->data, buffer->len, NULL)) { + stream = (CamelStream *) memstream; + memstream = (CamelStreamMem *) camel_stream_mem_new (); + camel_stream_mem_set_byte_array (memstream, g_byte_array_new ()); + + filtered_stream = camel_stream_filter_new_with_stream (stream); + camel_object_unref (stream); + + charset = composer ? composer->charset : mail_config_get_default_charset (); + charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "utf-8"); + camel_stream_filter_add (filtered_stream, charenc); + camel_object_unref (charenc); + + camel_stream_write_to_stream ((CamelStream *) filtered_stream, (CamelStream *) memstream); + camel_object_unref (filtered_stream); + g_byte_array_free (buffer, TRUE); + + buffer = memstream->buffer; + } + + camel_object_unref (memstream); g_byte_array_append (buffer, "", 1); content = buffer->data; -- cgit v1.2.3