[PATCH 5/7] Refactor decode_it and decode_it_2 to be both in tny_camel_common
- From: Jose Dapena Paz <jdapena igalia com>
- Subject: [PATCH 5/7] Refactor decode_it and decode_it_2 to be both in tny_camel_common
- Date: Fri, 11 Dec 2009 14:56:21 +0100
---
ChangeLog | 1 +
libtinymail-camel/tny-camel-common-priv.h | 3 ++
libtinymail-camel/tny-camel-common.c | 44 +++++++++++++++++++++++
libtinymail-camel/tny-camel-mime-part.c | 46 +-----------------------
libtinymail-camel/tny-camel-msg-header.c | 55 +++-------------------------
5 files changed, 55 insertions(+), 94 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 49e89c8..df3b2b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@
* Handle better in IMAP "NIL" parameter in fetch response.
* 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
2009-12-11 Sergio Villar Senin <svillar igalia com>
diff --git a/libtinymail-camel/tny-camel-common-priv.h b/libtinymail-camel/tny-camel-common-priv.h
index b597212..97bb231 100644
--- a/libtinymail-camel/tny-camel-common-priv.h
+++ b/libtinymail-camel/tny-camel-common-priv.h
@@ -37,5 +37,8 @@ gboolean _tny_folder_store_query_passes (TnyFolderStoreQuery *query, CamelFolder
gboolean _tny_session_check_operation (TnySessionCamel *session, TnyAccount *account, GError **err, GQuark domain, gint code);
void _tny_session_stop_operation (TnySessionCamel *session);
void _tny_camel_exception_to_tny_error (CamelException *ex, GError **err);
+char *_tny_camel_decode_raw_header (CamelMimePart *part, const char *str, gboolean is_addr);
+
+
#endif
diff --git a/libtinymail-camel/tny-camel-common.c b/libtinymail-camel/tny-camel-common.c
index 1ea15c3..323fe27 100644
--- a/libtinymail-camel/tny-camel-common.c
+++ b/libtinymail-camel/tny-camel-common.c
@@ -494,3 +494,47 @@ _tny_camel_exception_to_tny_error (CamelException *ex, GError **err)
return;
}
+
+char *
+_tny_camel_decode_raw_header (CamelMimePart *part, const char *str, gboolean is_addr)
+{
+ struct _camel_header_raw *h = part->headers;
+ const char *content, *charset = NULL;
+ CamelContentType *ct = NULL;
+
+ if (!str)
+ return NULL;
+
+ if ((content = camel_header_raw_find(&h, "Content-Type", NULL))
+ && (ct = camel_content_type_decode(content))
+ && (charset = camel_content_type_param(ct, "charset"))
+ && (g_ascii_strcasecmp(charset, "us-ascii") == 0))
+ charset = NULL;
+
+ charset = charset ? e_iconv_charset_name (charset) : NULL;
+
+ while (isspace ((unsigned) *str))
+ str++;
+
+ if (is_addr) {
+ char *ret;
+ struct _camel_header_address *addr;
+ addr = camel_header_address_decode (str, charset);
+ if (addr) {
+ ret = camel_header_address_list_format (addr);
+ camel_header_address_list_clear (&addr);
+ } else {
+ ret = g_strdup (str);
+ }
+
+ if (ct)
+ camel_content_type_unref (ct);
+
+ return ret;
+ }
+
+ if (ct)
+ camel_content_type_unref (ct);
+
+ return camel_header_decode_string (str, charset);
+}
diff --git a/libtinymail-camel/tny-camel-mime-part.c b/libtinymail-camel/tny-camel-mime-part.c
index f3e6bcc..65cfcce 100644
--- a/libtinymail-camel/tny-camel-mime-part.c
+++ b/libtinymail-camel/tny-camel-mime-part.c
@@ -68,50 +68,6 @@ static ssize_t camel_stream_format_text (CamelDataWrapper *dw, CamelStream *stre
-static char*
-decode_it_2 (CamelMimePart *part, const char *str, gboolean is_addr)
-{
- struct _camel_header_raw *h = part->headers;
- const char *content, *charset = NULL;
- CamelContentType *ct = NULL;
-
- if (!str)
- return NULL;
-
- if ((content = camel_header_raw_find(&h, "Content-Type", NULL))
- && (ct = camel_content_type_decode(content))
- && (charset = camel_content_type_param(ct, "charset"))
- && (g_ascii_strcasecmp(charset, "us-ascii") == 0))
- charset = NULL;
-
- charset = charset ? e_iconv_charset_name (charset) : NULL;
-
- while (isspace ((unsigned) *str))
- str++;
-
- if (is_addr) {
- char *ret;
- struct _camel_header_address *addr;
- addr = camel_header_address_decode (str, charset);
- if (addr) {
- ret = camel_header_address_list_format (addr);
- camel_header_address_list_clear (&addr);
- } else {
- ret = g_strdup (str);
- }
-
- if (ct)
- camel_content_type_unref (ct);
-
- return ret;
- }
-
- if (ct)
- camel_content_type_unref (ct);
-
- return camel_header_decode_string (str, charset);
-}
-
static void
tny_camel_mime_part_set_header_pair (TnyMimePart *self, const gchar *name, const gchar *value)
@@ -1115,7 +1071,7 @@ tny_camel_mime_part_get_filename_default (TnyMimePart *self)
if (str) {
if (!g_utf8_validate (str, -1, NULL))
- priv->cached_filename = decode_it_2 (priv->part, str, FALSE);
+ priv->cached_filename = _tny_camel_decode_raw_header (priv->part, str, FALSE);
else
priv->cached_filename = g_strdup (str);
}
diff --git a/libtinymail-camel/tny-camel-msg-header.c b/libtinymail-camel/tny-camel-msg-header.c
index 5ddab93..e5067e5 100644
--- a/libtinymail-camel/tny-camel-msg-header.c
+++ b/libtinymail-camel/tny-camel-msg-header.c
@@ -44,49 +44,6 @@
static GObjectClass *parent_class = NULL;
-static char*
-decode_it (CamelMimeMessage *msg, const char *str, gboolean is_addr)
-{
- struct _camel_header_raw *h = ((CamelMimePart *)msg)->headers;
- const char *content, *charset = NULL;
- CamelContentType *ct = NULL;
-
- if (!str)
- return NULL;
-
- if ((content = camel_header_raw_find(&h, "Content-Type", NULL))
- && (ct = camel_content_type_decode(content))
- && (charset = camel_content_type_param(ct, "charset"))
- && (g_ascii_strcasecmp(charset, "us-ascii") == 0))
- charset = NULL;
-
- charset = charset ? e_iconv_charset_name (charset) : NULL;
-
- while (isspace ((unsigned) *str))
- str++;
-
- if (is_addr) {
- char *ret;
- struct _camel_header_address *addr;
- addr = camel_header_address_decode (str, charset);
- if (addr) {
- ret = camel_header_address_list_format (addr);
- camel_header_address_list_clear (&addr);
- } else {
- ret = g_strdup (str);
- }
-
- if (ct)
- camel_content_type_unref (ct);
-
- return ret;
- }
-
- if (ct)
- camel_content_type_unref (ct);
-
- return camel_header_decode_string (str, charset);
-}
static gchar*
tny_camel_msg_header_dup_replyto (TnyHeader *self)
@@ -96,7 +53,7 @@ tny_camel_msg_header_dup_replyto (TnyHeader *self)
if (!me->reply_to) {
enc = camel_medium_get_header (CAMEL_MEDIUM (me->msg), "reply-to");
- me->reply_to = decode_it (me->msg, enc, TRUE);
+ me->reply_to = _tny_camel_decode_raw_header ((CamelMimePart *) me->msg, enc, TRUE);
}
return g_strdup ((const gchar *) me->reply_to);
@@ -212,7 +169,7 @@ tny_camel_msg_header_dup_cc (TnyHeader *self)
if (!me->cc) {
enc = camel_medium_get_header (CAMEL_MEDIUM (me->msg), "cc");
- me->cc = decode_it (me->msg, enc, TRUE);
+ me->cc = _tny_camel_decode_raw_header ((CamelMimePart *) me->msg, enc, TRUE);
}
return g_strdup ((const gchar *) me->cc);
@@ -226,7 +183,7 @@ tny_camel_msg_header_dup_bcc (TnyHeader *self)
if (!me->bcc) {
enc = camel_medium_get_header (CAMEL_MEDIUM (me->msg), "bcc");
- me->bcc = decode_it (me->msg, enc, TRUE);
+ me->bcc = _tny_camel_decode_raw_header ((CamelMimePart *) me->msg, enc, TRUE);
}
return g_strdup ((const gchar *) me->bcc);
@@ -394,7 +351,7 @@ tny_camel_msg_header_dup_from (TnyHeader *self)
if (!me->from) {
enc = camel_medium_get_header (CAMEL_MEDIUM (me->msg), "from");
- me->from = decode_it (me->msg, enc, TRUE);
+ me->from = _tny_camel_decode_raw_header ((CamelMimePart *) me->msg, enc, TRUE);
}
return g_strdup ((const gchar *) me->from);
@@ -408,7 +365,7 @@ tny_camel_msg_header_dup_subject (TnyHeader *self)
if (!me->subject) {
enc = camel_medium_get_header (CAMEL_MEDIUM (me->msg), "subject");
- me->subject = decode_it (me->msg, enc, FALSE);
+ me->subject = _tny_camel_decode_raw_header ((CamelMimePart *) me->msg, enc, FALSE);
}
return g_strdup ((const gchar *) me->subject);
@@ -423,7 +380,7 @@ tny_camel_msg_header_dup_to (TnyHeader *self)
if (!me->to) {
enc = camel_medium_get_header (CAMEL_MEDIUM (me->msg), "to");
- me->to = decode_it (me->msg, enc, TRUE);
+ me->to = _tny_camel_decode_raw_header ((CamelMimePart *) me->msg, enc, TRUE);
}
return g_strdup ((const gchar *) me->to);
--
1.6.3.3
--=-7xSGRSdHbBXdNvov60N6
Content-Disposition: attachment; filename*0=0006-Properly-return-decoded-headers-from-envelope-in-bod.pat; filename*1=ch
Content-Type: text/x-patch; name="0006-Properly-return-decoded-headers-from-envelope-in-bod.patch"; charset="UTF-8"
Content-Transfer-Encoding: 7bit
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]