From b37aa623dad9200d8db98571a59f1418e4699aa9 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Fri, 4 Jan 2008 15:01:18 +0000 Subject: [PATCH] * correctly determine what are attachments from modest's perspective; ie. non-image/ parts, even with "content-disposition: inline" are considered attachments from modest's pov. note; added modest_tny_mime_part_is_attachment_for_modest; it works and improves upon the current situation; anyway, it's important to keep an eye for any mails which fail our heuristics pmo-trunk-r3980 --- src/modest-tny-msg.c | 51 +++++++++++++++++++++++++++++++++ src/modest-tny-msg.h | 15 ++++++++++ src/widgets/modest-attachments-view.c | 10 +++++-- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index ef0cb28..fb7e5a1 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -668,6 +668,57 @@ modest_tny_mime_part_get_header_value (TnyMimePart *part, const gchar *header) } +/* we consider more things attachments than tinymail does... + */ +gboolean +modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part) +{ + gchar *content_disp; + gchar *content_type; + gboolean has_content_disp; + + g_return_val_if_fail (part && TNY_IS_MIME_PART(part), FALSE); + + /* if tinymail thinks it's an attachment, it definitely is */ + if (tny_mime_part_is_attachment (part)) + return TRUE; + + /* if the mime part is a message itself (ie. embedded), it's an attachment */ + if (TNY_IS_MSG (part)) + return TRUE; + + content_disp = modest_tny_mime_part_get_header_value (part, "Content-Disposition"); + has_content_disp = content_disp && strlen (content_disp) != 0; + g_free (content_disp); + + /* if it doesn't have a content deposition, it's not an attachment */ + if (!content_disp) + return FALSE; + + /* ok, it must be content-disposition "inline" then, because "attachment" + * is already handle above "...is_attachment". modest consider these "inline" things + * attachments as well, unless they are embedded images for html mail + */ + content_type = g_ascii_strdown (tny_mime_part_get_content_type (part), -1); + if (!g_str_has_prefix (content_type, "image/")) { + g_free (content_type); + return TRUE; /* it's not an image, so it must be an attachment */ + } + g_free (content_type); + + + /* now, if it's an inline-image, and it has a content-id or location, we + * we guess it's an inline image, and not an attachment */ + if (tny_mime_part_get_content_id (part) || tny_mime_part_get_content_location(part)) + return FALSE; + + /* in other cases... */ + return TRUE; +} + + + + static gint count_addresses (const gchar* addresses) { diff --git a/src/modest-tny-msg.h b/src/modest-tny-msg.h index d24af7d..09eeaa3 100644 --- a/src/modest-tny-msg.h +++ b/src/modest-tny-msg.h @@ -145,6 +145,21 @@ gchar* modest_tny_mime_part_get_header_value (TnyMimePart *part, const gch /** + * modest_tny_mime_part_is_attachment_for_modest: + * @self: some #TnyMimePart + * + * determine whether the given mime part is an attachment; note modest considers + * more things attachments than tinymail does; in particular, modest considers + * non-image 'inline' things to be attachments; check the source for details + * + * NOTE: this function should maybe in modest-tny-mime-part.... + * + * Returns: TRUE if it's attachment for modest, or FALSE otherwise + **/ +gboolean modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part); + + +/** * modest_tny_msg_create_forward_msg: * @msg: a valid #TnyMsg instance * @from: the sender of the forwarded mail diff --git a/src/widgets/modest-attachments-view.c b/src/widgets/modest-attachments-view.c index 22d3b05..0f11592 100644 --- a/src/widgets/modest-attachments-view.c +++ b/src/widgets/modest-attachments-view.c @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -101,6 +102,10 @@ modest_attachments_view_new (TnyMsg *msg) return GTK_WIDGET (self); } + + + + void modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, TnyMsg *msg) { @@ -135,7 +140,6 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn return; } - parts = TNY_LIST (tny_simple_list_new ()); tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), parts); iter = tny_list_create_iterator (parts); @@ -144,7 +148,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn TnyMimePart *part; part = TNY_MIME_PART (tny_iterator_get_current (iter)); - if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) { + if (part && modest_tny_mime_part_is_attachment_for_modest(part)) { modest_attachments_view_add_attachment (attachments_view, part); } @@ -155,7 +159,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn } gtk_widget_queue_draw (GTK_WIDGET (attachments_view)); - + } void -- 1.7.9.5