From 3de9db5ae79348a641351f6141b282ce5e9b50a9 Mon Sep 17 00:00:00 2001 From: Michael Zucci Date: Thu, 31 Aug 2000 03:08:51 +0000 Subject: (write_to_stream): Rearrange the logic so it always does charset conversion, and not just if we have a qp/base64 block. svn path=/trunk/; revision=5134 --- camel/ChangeLog | 2 ++ camel/camel-mime-part.c | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'camel') diff --git a/camel/ChangeLog b/camel/ChangeLog index f074a045cf..650948e8fc 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -7,6 +7,8 @@ filter to do that too. (write_to_stream): Fix some warnings/use the right constructor, oops. + (write_to_stream): Rearrange the logic so it always does charset + conversion, and not just if we have a qp/base64 block. * camel-mime-utils.c (append_latin1): New function - even though its broken, we'll assume mailers send latin1 headers instead of diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index 20e26e110e..9dba5162a4 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -505,6 +505,8 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) #ifdef CAN_THIS_GO_ELSEWHERE CamelMimeFilter *filter = NULL; CamelStreamFilter *filter_stream = NULL; + CamelMimeFilter *charenc = NULL; + const char *charset; switch(mp->encoding) { case CAMEL_MIME_PART_ENCODING_BASE64: @@ -516,25 +518,31 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) default: break; } - if (filter) { + + if (gmime_content_field_is_type(mp->content_type, "text", "*")) { + charset = gmime_content_field_get_parameter(mp->content_type, "charset"); + if (!(charset == NULL || !strcasecmp(charset, "us-ascii") || !strcasecmp(charset, "utf-8"))) { + charenc = (CamelMimeFilter *)camel_mime_filter_charset_new_convert("utf-8", charset); + } + } + + if (filter || charenc) { filter_stream = camel_stream_filter_new_with_stream(stream); - if (gmime_content_field_is_type(mp->content_type, "text", "*")) { + + /* if we have a character encoder, add that always */ + if (charenc) { + camel_stream_filter_add(filter_stream, charenc); + camel_object_unref((CamelObject *)charenc); + } + + /* we only re-do crlf on encoded blocks */ + if (filter && gmime_content_field_is_type(mp->content_type, "text", "*")) { CamelMimeFilter *crlf = camel_mime_filter_crlf_new(CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY); - const char *charset; camel_stream_filter_add(filter_stream, crlf); camel_object_unref((CamelObject *)crlf); - charset = gmime_content_field_get_parameter(mp->content_type, "charset"); - if (!(charset == NULL || !strcasecmp(charset, "us-ascii") || !strcasecmp(charset, "utf-8"))) { - CamelMimeFilter *charenc; - charenc = (CamelMimeFilter *)camel_mime_filter_charset_new_convert("utf-8", charset); - camel_stream_filter_add(filter_stream, charenc); - /* well some idiot changed the _add function to do its own ref'ing for - no decent purpose whatsoever ... */ - camel_object_unref((CamelObject *)charenc); - } } camel_stream_filter_add(filter_stream, filter); camel_object_unref((CamelObject *)filter); -- cgit