aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-07-18 04:12:12 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-07-18 04:12:12 +0800
commit451cc1a07a7010fba205ffebfb7778b284f524cf (patch)
tree1ed2548bd23831e761088d9dee16a535c02f8702 /camel
parent76c23a45f1737a6fc6d11b235ef753a082fe16cb (diff)
downloadgsoc2013-evolution-451cc1a07a7010fba205ffebfb7778b284f524cf.tar.gz
gsoc2013-evolution-451cc1a07a7010fba205ffebfb7778b284f524cf.tar.zst
gsoc2013-evolution-451cc1a07a7010fba205ffebfb7778b284f524cf.zip
Updated to convert to/from the correct charset (since content is no longer
2003-07-17 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-message.c (find_best_encoding): Updated to convert to/from the correct charset (since content is no longer necessarily in UTF-8). (best_encoding): Free the charset string when we're done with it. svn path=/trunk/; revision=21863
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog5
-rw-r--r--camel/camel-mime-message.c58
2 files changed, 33 insertions, 30 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index bb654f24bc..8a607b8bfe 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,10 @@
2003-07-17 Jeffrey Stedfast <fejj@ximian.com>
+ * camel-mime-message.c (find_best_encoding): Updated to convert
+ to/from the correct charset (since content is no longer
+ necessarily in UTF-8).
+ (best_encoding): Free the charset string when we're done with it.
+
* camel-stream-fs.c (stream_read): Increment the seekable stream
position by the number of bytes read. Oops.
(stream_write): Same here.
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 3bbce53e68..0d5824ce4c 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -673,17 +673,17 @@ camel_mime_message_has_8bit_parts (CamelMimeMessage *msg)
static CamelMimePartEncodingType
find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBestencEncoding enctype, char **charsetp)
{
- const char *charsetin = NULL;
- char *charset = NULL;
- CamelStream *null;
- CamelStreamFilter *filter;
CamelMimeFilterCharset *charenc = NULL;
+ CamelMimePartEncodingType encoding;
CamelMimeFilterBestenc *bestenc;
- int idb, idc = -1;
- gboolean istext;
unsigned int flags, callerflags;
- CamelMimePartEncodingType encoding;
CamelDataWrapper *content;
+ CamelStreamFilter *filter;
+ const char *charsetin;
+ char *charset = NULL;
+ CamelStream *null;
+ int idb, idc = -1;
+ gboolean istext;
/* we use all these weird stream things so we can do it with streams, and
not have to read the whole lot into memory - although i have a feeling
@@ -717,12 +717,10 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
null = (CamelStream *)camel_stream_null_new ();
filter = camel_stream_filter_new_with_stream (null);
- /* if we're not looking for the best charset, then use the one we have */
- if (istext && (required & CAMEL_BESTENC_GET_CHARSET) == 0
- && (charsetin = header_content_type_param (part->content_type, "charset"))) {
- /* if libunicode doesn't support it, we dont really have utf8 anyway, so
- we dont need a converter */
- charenc = camel_mime_filter_charset_new_convert ("UTF-8", charsetin);
+ /* if we're looking for the best charset, then we need to convert to UTF-8 */
+ if (istext && (required & CAMEL_BESTENC_GET_CHARSET) != 0
+ && (charsetin = header_content_type_param (content->mime_type, "charset"))) {
+ charenc = camel_mime_filter_charset_new_convert (charsetin, "UTF-8");
if (charenc != NULL)
idc = camel_stream_filter_add (filter, (CamelMimeFilter *)charenc);
charsetin = NULL;
@@ -735,31 +733,29 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
camel_stream_filter_remove (filter, idb);
if (idc != -1) {
camel_stream_filter_remove (filter, idc);
- camel_object_unref ((CamelObject *)charenc);
+ camel_object_unref (charenc);
charenc = NULL;
}
- if (istext)
+ if (istext && (required & CAMEL_BESTENC_GET_CHARSET) != 0) {
charsetin = camel_mime_filter_bestenc_get_best_charset (bestenc);
-
- d(printf("charsetin = %s\n", charsetin ? charsetin : "(null)"));
-
- /* if we have US-ASCII, or we're not doing text, we dont need to bother with the rest */
- if (charsetin != NULL && (required & CAMEL_BESTENC_GET_CHARSET) != 0) {
+ d(printf("best charset = %s\n", charsetin ? charsetin : "(null)"));
charset = g_strdup (charsetin);
+ charsetin = header_content_type_param (content->mime_type, "charset");
+ } else {
+ charset = NULL;
+ }
+
+ /* if we have US-ASCII, or we're not doing text, we dont need to bother with the rest */
+ if (istext && charsetin && charset && (required & CAMEL_BESTENC_GET_CHARSET) != 0) {
d(printf("have charset, trying conversion/etc\n"));
/* now that 'bestenc' has told us what the best encoding is, we can use that to create
a charset conversion filter as well, and then re-add the bestenc to filter the
result to find the best encoding to use as well */
- charenc = camel_mime_filter_charset_new_convert ("UTF-8", charset);
-
- /* eek, libunicode doesn't undertand this charset anyway, then the 'utf8' we
- thought we had is really the native format, in which case, we just treat
- it as binary data (and take the result we have so far) */
-
+ charenc = camel_mime_filter_charset_new_convert (charsetin, charset);
if (charenc != NULL) {
/* otherwise, try another pass, converting to the real charset */
@@ -773,15 +769,15 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
/* and write it to the new stream */
camel_data_wrapper_write_to_stream (content, (CamelStream *)filter);
- camel_object_unref ((CamelObject *)charenc);
+ camel_object_unref (charenc);
}
}
encoding = camel_mime_filter_bestenc_get_best_encoding (bestenc, enctype);
- camel_object_unref ((CamelObject *)filter);
- camel_object_unref ((CamelObject *)bestenc);
- camel_object_unref ((CamelObject *)null);
+ camel_object_unref (filter);
+ camel_object_unref (bestenc);
+ camel_object_unref (null);
d(printf("done, best encoding = %d\n", encoding));
@@ -833,6 +829,8 @@ best_encoding (CamelMimeMessage *msg, CamelMimePart *part, void *datap)
}
}
}
+
+ g_free (charset);
}
return TRUE;