From bc13df76e4593a1510f50d68cb8e7ea0fdecb63d Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Mon, 30 Mar 2009 07:39:42 +0000 Subject: [PATCH] Better detection of valid child in signed pmo-trunk-r8460 --- src/modest-tny-msg.c | 147 ++++++++++++++++++++++----------- src/modest-tny-msg.h | 10 +++ src/widgets/modest-attachments-view.c | 35 +------- 3 files changed, 110 insertions(+), 82 deletions(-) diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index f9e4e7f..2d79dea 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -692,6 +692,101 @@ modest_tny_msg_get_parent_uid (TnyMsg *msg) return g_object_get_data (G_OBJECT(msg), MODEST_TNY_MSG_PARENT_UID); } +static gchar *get_signed_protocol (TnyMimePart *part) +{ + TnyList *header_pairs; + TnyIterator *iterator; + gchar *result = NULL; + + header_pairs = TNY_LIST (tny_simple_list_new ()); + tny_mime_part_get_header_pairs (part, header_pairs); + iterator = tny_list_create_iterator (header_pairs); + + while (!result && !tny_iterator_is_done (iterator)) { + TnyPair *pair; + const gchar *name; + + pair = TNY_PAIR (tny_iterator_get_current (iterator)); + name = tny_pair_get_name (pair); + if (name && !g_ascii_strcasecmp (name, "Content-Type")) { + const gchar *s; + s = tny_pair_get_value (pair); + if (s) { + s = strstr (s, "protocol="); + if (s) { + const gchar *t; + s += 9; + if (*s == '\"') { + s++; + t = strstr (s, "\""); + } else { + t = strstr (s, ";"); + } + result = g_strndup (s, t - s); + } + } + } + + g_object_unref (pair); + tny_iterator_next (iterator); + } + + g_object_unref (iterator); + g_object_unref (header_pairs); + + return result; +} + +TnyMimePart * +modest_tny_msg_get_attachments_parent (TnyMsg *msg) +{ + TnyMimePart *result; + const gchar *content_type; + + result = NULL; + + content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg)); + if (content_type && !strcmp (content_type, "multipart/signed")) { + TnyList *msg_children; + TnyIterator *iterator; + gchar *signed_protocol; + + msg_children = TNY_LIST (tny_simple_list_new ()); + tny_mime_part_get_parts (TNY_MIME_PART (msg), msg_children); + + iterator = tny_list_create_iterator (msg_children); + signed_protocol = get_signed_protocol (TNY_MIME_PART (msg)); + + while (!result && !tny_iterator_is_done (iterator)) { + TnyMimePart *part; + + part = TNY_MIME_PART (tny_iterator_get_current (iterator)); + if (signed_protocol) { + const gchar *part_content_type; + + part_content_type = tny_mime_part_get_content_type (part); + if (part_content_type && g_ascii_strcasecmp (part_content_type, signed_protocol)) { + result = g_object_ref (part); + } + } else { + result = g_object_ref (part); + } + + g_object_unref (part); + tny_iterator_next (iterator); + } + + g_object_unref (iterator); + g_free (signed_protocol); + g_object_unref (msg_children); + } + if (result == NULL) { + result = g_object_ref (msg); + } + + return result; +} + static void @@ -719,34 +814,10 @@ modest_tny_msg_create_forward_msg (TnyMsg *msg, TnyList *parts = NULL; GList *attachments_list = NULL; TnyMimePart *part_to_check = NULL; - const gchar *content_type; g_return_val_if_fail (msg && TNY_IS_MSG(msg), NULL); - - content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg)); - if (content_type && !strcmp (content_type, "multipart/signed")) { - TnyList *msg_children; - guint length; - - msg_children = TNY_LIST (tny_simple_list_new ()); - tny_mime_part_get_parts (TNY_MIME_PART (msg), msg_children); - - length = tny_list_get_length (msg_children); - if (length == 1 || length == 2) { - TnyIterator *iterator; - - iterator = tny_list_create_iterator (msg_children); - - part_to_check = TNY_MIME_PART (tny_iterator_get_current (iterator)); - - g_object_unref (iterator); - } - g_object_unref (msg_children); - } - if (part_to_check == NULL) { - part_to_check = g_object_ref (msg); - } + part_to_check = modest_tny_msg_get_attachments_parent (TNY_MSG (msg)); /* Add attachments */ parts = TNY_LIST (tny_simple_list_new()); @@ -1000,35 +1071,11 @@ modest_tny_msg_create_reply_msg (TnyMsg *msg, TnyList *parts = NULL; GList *attachments_list = NULL; TnyMimePart *part_to_check = NULL; - const gchar *content_type; g_return_val_if_fail (msg && TNY_IS_MSG(msg), NULL); - content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg)); - if (content_type && !strcmp (content_type, "multipart/signed")) { - TnyList *msg_children; - guint length; - - msg_children = TNY_LIST (tny_simple_list_new ()); - tny_mime_part_get_parts (TNY_MIME_PART (msg), msg_children); - - length = tny_list_get_length (msg_children); - if (length == 1 || length == 2) { - TnyIterator *iterator; - - iterator = tny_list_create_iterator (msg_children); - - part_to_check = TNY_MIME_PART (tny_iterator_get_current (iterator)); - - g_object_unref (iterator); - } + part_to_check = modest_tny_msg_get_attachments_parent (TNY_MSG (msg)); - g_object_unref (msg_children); - } - if (part_to_check == NULL) { - part_to_check = g_object_ref (msg); - } - parts = TNY_LIST (tny_simple_list_new()); tny_mime_part_get_parts (TNY_MIME_PART (part_to_check), parts); tny_list_foreach (parts, add_if_attachment, &attachments_list); diff --git a/src/modest-tny-msg.h b/src/modest-tny-msg.h index fabbafb..0c0126a 100644 --- a/src/modest-tny-msg.h +++ b/src/modest-tny-msg.h @@ -234,5 +234,15 @@ modest_tny_msg_get_all_recipients_list (TnyMsg *msg); */ void modest_tny_msg_get_references (TnyMsg *msg, gchar **message_id, gchar **references, gchar **in_reply_to); +/** + * modest_tny_msg_get_attachments_parent: + * @msg: a #TnyMsg + * + * the mime part of the message attachments should be below + * + * Returns: the mime part (ref owned by caller) + */ +TnyMimePart *modest_tny_msg_get_attachments_parent (TnyMsg *msg); + #endif /* __MODEST_TNY_MSG_H__ */ diff --git a/src/widgets/modest-attachments-view.c b/src/widgets/modest-attachments-view.c index 2e717eb..96f21c7 100644 --- a/src/widgets/modest-attachments-view.c +++ b/src/widgets/modest-attachments-view.c @@ -40,6 +40,7 @@ #include #include #include +#include static GObjectClass *parent_class = NULL; @@ -129,39 +130,9 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn return; } - msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg)); - /* If the top mime part is a multipart/signed, we have to work with its first child (if available) - * as "message" for showing attachments */ - - part_to_check = NULL; - if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/signed")) { - TnyList *msg_children; - guint length; - - msg_children = TNY_LIST (tny_simple_list_new ()); - tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), msg_children); - - length = tny_list_get_length (msg_children); - if (length == 1 || length == 2) { - TnyIterator *iterator; - - iterator = tny_list_create_iterator (msg_children); - - part_to_check = TNY_MIME_PART (tny_iterator_get_current (iterator)); - - g_object_unref (iterator); - } - - g_object_unref (msg_children); - - } - - if (part_to_check == NULL) { - part_to_check = g_object_ref (priv->msg); - } else { - msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (part_to_check)); - } + part_to_check = modest_tny_msg_get_attachments_parent (TNY_MSG (msg)); + msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (part_to_check)); /* If the top mime part is a multipart/related, we don't show the attachments, as they're * embedded images in body */ -- 1.7.9.5