[evolution-mapi] Bug #641251 - All sent mail containing unicode/utf8 is converted to junk
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-mapi] Bug #641251 - All sent mail containing unicode/utf8 is converted to junk
- Date: Wed, 2 Feb 2011 19:09:26 +0000 (UTC)
commit 40b17651c676df661ed13ddfec40692d32f4a0ef
Author: Milan Crha <mcrha redhat com>
Date: Wed Feb 2 20:08:43 2011 +0100
Bug #641251 - All sent mail containing unicode/utf8 is converted to junk
src/camel/camel-mapi-utils.c | 98 +++++++++++++++++++++++++++++++++++------
1 files changed, 83 insertions(+), 15 deletions(-)
---
diff --git a/src/camel/camel-mapi-utils.c b/src/camel/camel-mapi-utils.c
index 93c14cb..b00558f 100644
--- a/src/camel/camel-mapi-utils.c
+++ b/src/camel/camel-mapi-utils.c
@@ -265,6 +265,81 @@ mail_item_add_attach (MailItem *item, CamelMimePart *part, CamelStream *content_
return TRUE;
}
+static CamelStream *
+get_content_stream (CamelMimePart *part, GCancellable *cancellable)
+{
+ CamelStream *content_stream;
+ CamelStream *filter_stream = NULL;
+ CamelMimeFilterWindows *windows = NULL;
+ CamelDataWrapper *dw;
+
+ g_return_val_if_fail (part != NULL, NULL);
+
+ dw = camel_medium_get_content (CAMEL_MEDIUM (part));
+ g_return_val_if_fail (dw != NULL, NULL);
+
+ content_stream = camel_stream_mem_new();
+
+ if (camel_mime_part_get_content_type (part)) {
+ const gchar *charset = camel_content_type_param (camel_mime_part_get_content_type (part), "charset");
+
+ if (charset && *charset && g_ascii_strcasecmp (charset, "utf8") != 0 && g_ascii_strcasecmp (charset, "utf-8") != 0) {
+ if (g_ascii_strncasecmp (charset, "iso-8859-", 9) == 0) {
+ CamelStream *null;
+
+ /* Since a few Windows mailers like to claim they sent
+ * out iso-8859-# encoded text when they really sent
+ * out windows-cp125#, do some simple sanity checking
+ * before we move on... */
+
+ null = camel_stream_null_new ();
+ filter_stream = camel_stream_filter_new (null);
+ g_object_unref (null);
+
+ windows = (CamelMimeFilterWindows *)camel_mime_filter_windows_new (charset);
+ camel_stream_filter_add (
+ CAMEL_STREAM_FILTER (filter_stream),
+ CAMEL_MIME_FILTER (windows));
+
+ camel_data_wrapper_decode_to_stream_sync (
+ dw, (CamelStream *)filter_stream, cancellable, NULL);
+ camel_stream_flush ((CamelStream *)filter_stream, cancellable, NULL);
+ g_object_unref (filter_stream);
+
+ charset = camel_mime_filter_windows_real_charset (windows);
+ }
+
+ if (charset && *charset) {
+ CamelMimeFilter *filter;
+
+ filter_stream = camel_stream_filter_new (content_stream);
+
+ if ((filter = camel_mime_filter_charset_new (charset, "UTF-8"))) {
+ camel_stream_filter_add (
+ CAMEL_STREAM_FILTER (filter_stream),
+ CAMEL_MIME_FILTER (filter));
+ g_object_unref (filter);
+ } else {
+ g_object_unref (filter_stream);
+ filter_stream = NULL;
+ }
+ }
+ }
+ }
+
+ if (filter_stream) {
+ camel_data_wrapper_decode_to_stream_sync (dw, (CamelStream *) filter_stream, cancellable, NULL);
+ camel_stream_flush (filter_stream, cancellable, NULL);
+ g_object_unref (filter_stream);
+ } else {
+ camel_data_wrapper_decode_to_stream_sync (dw, (CamelStream *) content_stream, cancellable, NULL);
+ }
+
+ g_seekable_seek (G_SEEKABLE (content_stream), 0, G_SEEK_SET, NULL, NULL);
+
+ return content_stream;
+}
+
static gboolean
mapi_do_multipart (CamelMultipart *mp, MailItem *item, gboolean *is_first, GCancellable *cancellable)
{
@@ -276,7 +351,6 @@ mapi_do_multipart (CamelMultipart *mp, MailItem *item, gboolean *is_first, GCanc
const gchar *filename;
const gchar *description;
const gchar *content_id;
- gint content_size;
g_return_val_if_fail (is_first != NULL, FALSE);
@@ -294,11 +368,7 @@ mapi_do_multipart (CamelMultipart *mp, MailItem *item, gboolean *is_first, GCanc
/* filename */
filename = camel_mime_part_get_filename(part);
- content_stream = camel_stream_mem_new();
- content_size = camel_data_wrapper_decode_to_stream_sync (
- dw, (CamelStream *) content_stream, cancellable, NULL);
-
- g_seekable_seek (G_SEEKABLE (content_stream), 0, G_SEEK_SET, NULL, NULL);
+ content_stream = get_content_stream (part, cancellable);
description = camel_mime_part_get_description(part);
content_id = camel_mime_part_get_content_id(part);
@@ -313,6 +383,9 @@ mapi_do_multipart (CamelMultipart *mp, MailItem *item, gboolean *is_first, GCanc
} else {
mail_item_add_attach (item, part, content_stream, cancellable);
}
+
+ if (content_stream)
+ g_object_unref (content_stream);
}
return TRUE;
@@ -335,19 +408,16 @@ MailItem *
camel_mapi_utils_mime_to_item (CamelMimeMessage *message, gint32 message_camel_flags, CamelAddress *from, GCancellable *cancellable, GError **error)
{
CamelDataWrapper *dw = NULL;
- CamelContentType *type;
CamelStream *content_stream;
CamelMultipart *multipart;
CamelInternetAddress *to, *cc, *bcc;
MailItem *item = g_new0 (MailItem, 1);
const gchar *namep = NULL;
const gchar *addressp = NULL;
- const gchar *content_type;
time_t msg_time = 0;
gint msg_time_offset = 0;
GArray *headers;
- gssize content_size;
GSList *recipient_list = NULL;
gint i = 0;
@@ -430,14 +500,12 @@ camel_mapi_utils_mime_to_item (CamelMimeMessage *message, gint32 message_camel_f
} else {
dw = camel_medium_get_content (CAMEL_MEDIUM (message));
if (dw) {
- type = camel_mime_part_get_content_type((CamelMimePart *)message);
- content_type = camel_content_type_simple (type);
-
- content_stream = (CamelStream *)camel_stream_mem_new();
- content_size = camel_data_wrapper_decode_to_stream_sync (
- dw, (CamelStream *)content_stream, cancellable, NULL);
+ content_stream = get_content_stream ((CamelMimePart *) message, cancellable);
mail_item_set_body_stream (item, content_stream, PART_TYPE_PLAIN_TEXT, cancellable);
+
+ if (content_stream)
+ g_object_unref (content_stream);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]