Take into account multipart/signed on showing attachments of a message
[modest] / src / widgets / modest-attachments-view.c
index 5617a65..2e717eb 100644 (file)
@@ -109,6 +109,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
        TnyList *parts;
        TnyIterator *iter;
        gchar *msg_content_type = NULL;
+       TnyMimePart *part_to_check;
        
        if (msg == priv->msg) return;
 
@@ -128,16 +129,49 @@ 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));
+       }
+
+
        /* If the top mime part is a multipart/related, we don't show the attachments, as they're
         * embedded images in body */
-       msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
        if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
                gchar *header_content_type;
                gboolean application_multipart = FALSE;
 
                g_free (msg_content_type);
 
-               header_content_type = modest_tny_mime_part_get_headers_content_type (TNY_MIME_PART (priv->msg));
+               header_content_type = modest_tny_mime_part_get_headers_content_type (TNY_MIME_PART (part_to_check));
                
                if ((header_content_type != NULL) && 
                    !strstr (header_content_type, "application/")) {
@@ -147,6 +181,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
 
                if (application_multipart) {
                        gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+                       g_object_unref (part_to_check);
                        return;
                }
        } else {
@@ -159,14 +194,15 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
                g_free (msg_content_type);
 
                if (direct_attach) {
-                       modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (msg), TRUE, 0);
+                       modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (part_to_check), TRUE, 0);
                        gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+                       g_object_unref (part_to_check);
                        return;
                }
        }
 
        parts = TNY_LIST (tny_simple_list_new ());
-       tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), parts);
+       tny_mime_part_get_parts (TNY_MIME_PART (part_to_check), parts);
        iter = tny_list_create_iterator (parts);
 
        while (!tny_iterator_is_done (iter)) {
@@ -184,6 +220,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
        }
        g_object_unref (iter);
        g_object_unref (parts);
+       g_object_unref (part_to_check);
        
 
        gtk_widget_queue_draw (GTK_WIDGET (attachments_view));