[PATCH 2/2] Decode properly filename in bs mime part.



	* libtinymail-camel/tny-camel-bs-mime-part.c: properly decode
	filename field.
---
 ChangeLog                                       |    3 ++
 libtinymail-camel/tny-camel-bs-mime-part-priv.h |    1 +
 libtinymail-camel/tny-camel-bs-mime-part.c      |   34 +++++++++++++++++++---
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a548049..7bd16d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2009-12-21  Jose Dapena Paz  <jdapena igalia com>
 
+	* libtinymail-camel/tny-camel-bs-mime-part.c: properly decode
+	filename field.
+
 	* libtinymail-camel/tny-camel-bs-mime-part.c
 	(..._get_decoded_stream_default): properly decode text/plain
 	messages as utf8.
diff --git a/libtinymail-camel/tny-camel-bs-mime-part-priv.h b/libtinymail-camel/tny-camel-bs-mime-part-priv.h
index 4266e94..1ee8776 100644
--- a/libtinymail-camel/tny-camel-bs-mime-part-priv.h
+++ b/libtinymail-camel/tny-camel-bs-mime-part-priv.h
@@ -31,6 +31,7 @@ struct _TnyCamelBsMimePartPriv
 	GMutex *part_lock;
 	bodystruct_t *bodystructure;
 	gchar *cached_content_type;
+	gchar *cached_filename;
 	gchar *uid;
 	TnyCamelBsMimePart *parent;
 	TnyFolder *folder;
diff --git a/libtinymail-camel/tny-camel-bs-mime-part.c b/libtinymail-camel/tny-camel-bs-mime-part.c
index b6149ab..ffc07f9 100644
--- a/libtinymail-camel/tny-camel-bs-mime-part.c
+++ b/libtinymail-camel/tny-camel-bs-mime-part.c
@@ -897,13 +897,33 @@ static const gchar*
 tny_camel_bs_mime_part_get_filename_default (TnyMimePart *self)
 {
 	TnyCamelBsMimePartPriv *priv = TNY_CAMEL_BS_MIME_PART_GET_PRIVATE (self);
-	const gchar *retval;
 
-	g_mutex_lock (priv->part_lock);
-	retval = mimeparam_get_value_for (priv->bodystructure->disposition.params, "FILENAME");
-	g_mutex_unlock (priv->part_lock);
+	if (!priv->cached_filename) {
+		const gchar *raw_value;
+		const gchar *charset;
 
-	return retval;
+		g_mutex_lock (priv->part_lock);
+		raw_value = mimeparam_get_value_for (priv->bodystructure->disposition.params, "FILENAME");
+		charset = mimeparam_get_value_for (priv->bodystructure->content.params, "CHARSET");
+
+		if (!raw_value) {
+			priv->cached_filename = NULL;
+		} else {
+	
+			if (charset && (g_ascii_strcasecmp(charset, "us-ascii") == 0))
+				charset = NULL;
+
+			charset = charset ? e_iconv_charset_name (charset) : NULL;
+
+			while (isspace ((unsigned) *raw_value))
+				raw_value++;
+
+			priv->cached_filename = camel_header_decode_string (raw_value, charset);
+		}
+		g_mutex_unlock (priv->part_lock);
+	}
+
+	return priv->cached_filename;
 }
 
 static const gchar*
@@ -1111,6 +1131,9 @@ tny_camel_bs_mime_part_finalize (GObject *object)
 	if (priv->cached_content_type)
 		g_free (priv->cached_content_type);
 	priv->cached_content_type = NULL;
+	if (priv->cached_filename)
+		g_free (priv->cached_filename);
+	priv->cached_filename = NULL;
 	g_mutex_unlock (priv->part_lock);
 
 	g_mutex_free (priv->part_lock);
@@ -1236,6 +1259,7 @@ tny_camel_bs_mime_part_instance_init (GTypeInstance *instance, gpointer g_class)
 	priv->folder = NULL;
 	priv->uid = NULL;
 	priv->cached_content_type = NULL;
+	priv->cached_filename = NULL;
 	priv->parent = NULL;
 	priv->bodystructure = NULL;
 
-- 
1.6.3.3


--=-Yg8q9tBt8l7SqQ49Sqzs--



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