[PATCH 6/7] Properly return decoded headers from envelope in bodystruct



---
 ChangeLog                                        |    2 +
 libtinymail-camel/tny-camel-bs-mime-part.c       |    3 +-
 libtinymail-camel/tny-camel-bs-msg-header-priv.h |    5 ++-
 libtinymail-camel/tny-camel-bs-msg-header.c      |   44 ++++++++++++++++++---
 libtinymail-camel/tny-camel-common.c             |    1 +
 5 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index df3b2b6..f2aa25d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,8 @@
 	* Fix part specs of direct child of attached messages in
 	bodystruct parser.
 	* Refactor decode_it and decode_it_2 in _tny_camel_decode_raw_header
+	* Decode properly headers in TnyCamelBsMsgHeader, to return utf8
+	strings.
 
 2009-12-11  Sergio Villar Senin  <svillar igalia com>
 
diff --git a/libtinymail-camel/tny-camel-bs-mime-part.c b/libtinymail-camel/tny-camel-bs-mime-part.c
index 3be3fbb..4808312 100644
--- a/libtinymail-camel/tny-camel-bs-mime-part.c
+++ b/libtinymail-camel/tny-camel-bs-mime-part.c
@@ -401,7 +401,8 @@ tny_camel_bs_mime_part_get_parts_default (TnyMimePart *self, TnyList *list)
 			TnyMimePart *mpart;
 
 			if (!strcasecmp (part->content.type, "message") && !strcasecmp (part->content.subtype, "rfc822")) {
-				TnyHeader *header = _tny_camel_bs_msg_header_new (part->envelope, part->octets);
+				TnyHeader *header = _tny_camel_bs_msg_header_new (part->envelope, part->octets, 
+										  mimeparam_get_value_for (part->content.params, "CHARSET"));
 				mpart = (TnyMimePart *) _tny_camel_bs_msg_new (part->subparts,
 					priv->uid, TNY_CAMEL_BS_MIME_PART (self));
 				_tny_camel_bs_msg_set_header (TNY_CAMEL_BS_MSG (mpart), header);
diff --git a/libtinymail-camel/tny-camel-bs-msg-header-priv.h b/libtinymail-camel/tny-camel-bs-msg-header-priv.h
index 4133fb1..391eac2 100644
--- a/libtinymail-camel/tny-camel-bs-msg-header-priv.h
+++ b/libtinymail-camel/tny-camel-bs-msg-header-priv.h
@@ -44,6 +44,9 @@ struct _TnyCamelBsMsgHeader
 	GObject parent;
 	envelope_t *envelope;
 	gint msg_size;
+	gchar *content_type;
+	gchar *content_subtype;
+	gchar *charset;
 };
 
 struct _TnyCamelBsMsgHeaderClass 
@@ -53,7 +56,7 @@ struct _TnyCamelBsMsgHeaderClass
 
 GType tny_camel_bs_msg_header_get_type (void);
 
-TnyHeader* _tny_camel_bs_msg_header_new (envelope_t *envelope, gint msg_size);
+TnyHeader* _tny_camel_bs_msg_header_new (envelope_t *envelope, gint msg_size, const gchar *charset);
 
 G_END_DECLS
 
diff --git a/libtinymail-camel/tny-camel-bs-msg-header.c b/libtinymail-camel/tny-camel-bs-msg-header.c
index 502f2cf..cb891c7 100644
--- a/libtinymail-camel/tny-camel-bs-msg-header.c
+++ b/libtinymail-camel/tny-camel-bs-msg-header.c
@@ -23,6 +23,7 @@
 
 #include <glib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include <tny-header.h>
 
@@ -32,15 +33,38 @@
 #include <tny-camel-shared.h>
 
 #include <camel/camel-mime-utils.h>
+#include <libedataserver/e-iconv.h>
 
 static GObjectClass *parent_class = NULL;
 
+char *
+_tny_camel_bs_decode_raw_header (TnyCamelBsMsgHeader *me, const char *str, gboolean is_addr)
+{
+	const gchar *charset;
+
+	if (!str)
+		return NULL;
+
+	charset = me->charset;
+	
+	if (charset && (g_ascii_strcasecmp(charset, "us-ascii") == 0))
+		charset = NULL;
+
+	charset = charset ? e_iconv_charset_name (charset) : NULL;
+
+	while (isspace ((unsigned) *str))
+		str++;
+
+	return camel_header_decode_string (str, charset);
+}
+
+
 
 static gchar*
 tny_camel_bs_msg_header_dup_replyto (TnyHeader *self)
 {
 	TnyCamelBsMsgHeader *me = TNY_CAMEL_BS_MSG_HEADER (self);
-	return g_strdup (me->envelope->reply_to);
+	return _tny_camel_bs_decode_raw_header (me, me->envelope->reply_to, TRUE);
 }
 
 
@@ -92,14 +116,14 @@ static gchar*
 tny_camel_bs_msg_header_dup_cc (TnyHeader *self)
 {
 	TnyCamelBsMsgHeader *me = TNY_CAMEL_BS_MSG_HEADER (self);
-	return g_strdup (me->envelope->cc);
+	return _tny_camel_bs_decode_raw_header (me, me->envelope->cc, TRUE);
 }
 
 static gchar*
 tny_camel_bs_msg_header_dup_bcc (TnyHeader *self)
 {
 	TnyCamelBsMsgHeader *me = TNY_CAMEL_BS_MSG_HEADER (self);
-	return g_strdup (me->envelope->bcc);
+	return _tny_camel_bs_decode_raw_header (me, me->envelope->bcc, TRUE);
 }
 
 static TnyHeaderFlags
@@ -140,14 +164,14 @@ static gchar*
 tny_camel_bs_msg_header_dup_from (TnyHeader *self)
 {
 	TnyCamelBsMsgHeader *me = TNY_CAMEL_BS_MSG_HEADER (self);
-	return g_strdup (me->envelope->from);
+	return _tny_camel_bs_decode_raw_header (me, me->envelope->from, TRUE);
 }
 
 static gchar*
 tny_camel_bs_msg_header_dup_subject (TnyHeader *self)
 {
 	TnyCamelBsMsgHeader *me = TNY_CAMEL_BS_MSG_HEADER (self);
-	return g_strdup (me->envelope->subject);
+	return _tny_camel_bs_decode_raw_header (me, me->envelope->subject, FALSE);
 }
 
 
@@ -155,7 +179,7 @@ static gchar*
 tny_camel_bs_msg_header_dup_to (TnyHeader *self)
 {
 	TnyCamelBsMsgHeader *me = TNY_CAMEL_BS_MSG_HEADER (self);
-	return g_strdup (me->envelope->to);
+	return _tny_camel_bs_decode_raw_header (me, me->envelope->to, TRUE);
 }
 
 static gchar*
@@ -188,6 +212,10 @@ tny_camel_bs_msg_header_dup_uid (TnyHeader *self)
 static void
 tny_camel_bs_msg_header_finalize (GObject *object)
 {
+	TnyCamelBsMsgHeader *me = TNY_CAMEL_BS_MSG_HEADER (object);
+
+	g_free (me->charset);
+
 	(*parent_class->finalize) (object);
 	return;
 }
@@ -199,12 +227,14 @@ tny_camel_bs_msg_header_get_folder (TnyHeader *self)
 }
 
 TnyHeader*
-_tny_camel_bs_msg_header_new (envelope_t *envelope, gint msg_size)
+_tny_camel_bs_msg_header_new (envelope_t *envelope, gint msg_size,
+			      const gchar *charset)
 {
 	TnyCamelBsMsgHeader *self = g_object_new (TNY_TYPE_CAMEL_BS_MSG_HEADER, NULL);
 
 	self->envelope = envelope; 
 	self->msg_size = msg_size;
+	self->charset = g_strdup (charset);
 
 	return (TnyHeader*) self;
 }
diff --git a/libtinymail-camel/tny-camel-common.c b/libtinymail-camel/tny-camel-common.c
index 323fe27..b240ba4 100644
--- a/libtinymail-camel/tny-camel-common.c
+++ b/libtinymail-camel/tny-camel-common.c
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <glib/gi18n-lib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include <tny-camel-account.h>
 #include <tny-session-camel.h>
-- 
1.6.3.3


--=-7xSGRSdHbBXdNvov60N6
Content-Disposition: attachment; filename="0007-Parse-properly-rfc2047-word-in-utf-8.patch"
Content-Type: text/x-patch; name="0007-Parse-properly-rfc2047-word-in-utf-8.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]