* src/modest-tny-mime-part.[ch]:
authorJose Dapena Paz <jdapena@igalia.com>
Fri, 8 Feb 2008 10:26:56 +0000 (10:26 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Fri, 8 Feb 2008 10:26:56 +0000 (10:26 +0000)
        * New method to know if a TnyMsg instance is really a message
          or in fact it's a direct attachment.
* src/widgets/modest-attachments-view.c:
        * On setting a message, if it's an application
          multipart/related, show its contents as attachments (should
          help showing smil messages).
        * On setting a message, if the top mime part is a file, then
          show it as attachment.
* src/modest-tny-msg.c:
        * Modify code to detect body, to take into account the
          application multiparts (as smil) and direct attachments. These
          shouldn't show a body.
        * On creating forward messages, attach properly the direct
          attachments (we don't show any body for them).
* src/maemo/modest-msg-view-window.c:
        * Manage properly the application multiparts and top mime part
          attachments.
* src/modest-formatter.c:
        * Modify attach method to work if body is NULL.

pmo-trunk-r4147

src/maemo/modest-msg-view-window.c
src/modest-formatter.c
src/modest-tny-mime-part.c
src/modest-tny-mime-part.h
src/modest-tny-msg.c
src/widgets/modest-attachments-view.c

index 0bfcf6b..9c83732 100644 (file)
 #include <modest-tny-account.h>
 #include <modest-mime-part-view.h>
 #include <modest-isearch-view.h>
 #include <modest-tny-account.h>
 #include <modest-mime-part-view.h>
 #include <modest-isearch-view.h>
+#include <modest-tny-mime-part.h>
 #include <math.h>
 #include <errno.h>
 #include <glib/gstdio.h>
 #include <math.h>
 #include <errno.h>
 #include <glib/gstdio.h>
+#include <modest-debug.h>
 
 #define DEFAULT_FOLDER "MyDocs/.documents"
 
 
 #define DEFAULT_FOLDER "MyDocs/.documents"
 
@@ -845,6 +847,10 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg,
        ModestWindow *main_window = NULL;
        ModestWindowMgr *mgr = NULL;
 
        ModestWindow *main_window = NULL;
        ModestWindowMgr *mgr = NULL;
 
+       MODEST_DEBUG_BLOCK (
+              modest_tny_mime_part_to_string (TNY_MIME_PART (msg), 0);
+       );
+
        mgr = modest_runtime_get_window_mgr ();
        window = MODEST_MSG_VIEW_WINDOW (modest_window_mgr_get_msg_view_window (mgr));
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
        mgr = modest_runtime_get_window_mgr ();
        window = MODEST_MSG_VIEW_WINDOW (modest_window_mgr_get_msg_view_window (mgr));
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
@@ -2342,7 +2348,7 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart
                return;
        }
 
                return;
        }
 
-       if (!TNY_IS_MSG (mime_part)) {
+       if (!modest_tny_mime_part_is_msg (mime_part)) {
                gchar *filepath = NULL;
                const gchar *att_filename = tny_mime_part_get_filename (mime_part);
                const gchar *content_type;
                gchar *filepath = NULL;
                const gchar *att_filename = tny_mime_part_get_filename (mime_part);
                const gchar *content_type;
@@ -2578,7 +2584,7 @@ modest_msg_view_window_save_attachments (ModestMsgViewWindow *window, TnyList *m
                iter = tny_list_create_iterator (mime_parts);
                TnyMimePart *mime_part = (TnyMimePart *) tny_iterator_get_current (iter);
                g_object_unref (iter);
                iter = tny_list_create_iterator (mime_parts);
                TnyMimePart *mime_part = (TnyMimePart *) tny_iterator_get_current (iter);
                g_object_unref (iter);
-               if (!TNY_IS_MSG (mime_part) && tny_mime_part_is_attachment (mime_part)) {
+               if (!modest_tny_mime_part_is_msg (mime_part) && tny_mime_part_is_attachment (mime_part)) {
                        filename = tny_mime_part_get_filename (mime_part);
                } else {
                        g_warning ("Tried to save a non-file attachment");
                        filename = tny_mime_part_get_filename (mime_part);
                } else {
                        g_warning ("Tried to save a non-file attachment");
@@ -2723,7 +2729,7 @@ modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, gboolean
                iter = tny_list_create_iterator (mime_parts);
                part = (TnyMimePart *) tny_iterator_get_current (iter);
                g_object_unref (iter);
                iter = tny_list_create_iterator (mime_parts);
                part = (TnyMimePart *) tny_iterator_get_current (iter);
                g_object_unref (iter);
-               if (TNY_IS_MSG (part)) {
+               if (modest_tny_mime_part_is_msg (part)) {
                        TnyHeader *header;
                        header = tny_msg_get_header (TNY_MSG (part));
                        filename = tny_header_get_subject (header);
                        TnyHeader *header;
                        header = tny_msg_get_header (TNY_MSG (part));
                        filename = tny_header_get_subject (header);
index e54154e..ed10222 100644 (file)
@@ -189,8 +189,10 @@ modest_formatter_attach (ModestFormatter *self, TnyMsg *msg, TnyHeader *header)
        construct_from_text (body_part, "", priv->content_type);
        g_object_unref (body_part);
 
        construct_from_text (body_part, "", priv->content_type);
        g_object_unref (body_part);
 
-       /* Add parts */
-       tny_mime_part_add_part (TNY_MIME_PART (new_msg), TNY_MIME_PART (msg));
+       if (msg) {
+               /* Add parts */
+               tny_mime_part_add_part (TNY_MIME_PART (new_msg), TNY_MIME_PART (msg));
+       }
 
        return new_msg;
 }
 
        return new_msg;
 }
index bfd0d62..1500120 100644 (file)
@@ -125,4 +125,72 @@ modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part)
        return TRUE;
 }
 
        return TRUE;
 }
 
+gboolean
+modest_tny_mime_part_is_msg (TnyMimePart *part)
+{
+       const gchar *content_type;
+
+       if (!TNY_IS_MSG (part))
+               return FALSE;
+
+       content_type = tny_mime_part_get_content_type (part);
+       if ((g_str_has_prefix (content_type, "message/rfc822") ||
+            g_str_has_prefix (content_type, "multipart/") ||
+            g_str_has_prefix (content_type, "text/"))) {
+               return TRUE;
+       } else {
+               return FALSE;
+       }
+}
+
+void 
+modest_tny_mime_part_to_string (TnyMimePart *part, gint indent)
+{
+       return;
+       gint i;
+       GString *indent_prefix;
+       TnyList *list, *pairs_list;
+       TnyIterator *iter, *pairs_iter;
+       
+       indent_prefix = g_string_new ("");
+       for (i = 0; i < indent; i++) {
+               indent_prefix = g_string_append_c (indent_prefix, ' ');
+       }
+
+       if (TNY_IS_MSG (part)) {
+               TnyHeader *header;
+
+               header = tny_msg_get_header (TNY_MSG (part));
+               g_print ("(%s(MSG))\n", indent_prefix->str);
+               g_object_unref (header);
+       }
+
+       list = tny_simple_list_new ();
+       tny_mime_part_get_parts (part, list);
+       pairs_list = tny_simple_list_new ();
+       tny_mime_part_get_header_pairs (part, pairs_list);
+       g_print ("%s(content=%s parts=%d location=%s)\n", indent_prefix->str, 
+                tny_mime_part_get_content_type (part),
+                tny_list_get_length (list),
+                tny_mime_part_get_content_location (part));
+       for (pairs_iter = tny_list_create_iterator (pairs_list);
+            !tny_iterator_is_done (pairs_iter);
+            tny_iterator_next (pairs_iter)) {
+               TnyPair *pair = TNY_PAIR (tny_iterator_get_current (pairs_iter));
+               g_print ("%s(%s:%s)\n", indent_prefix->str, tny_pair_get_name (pair), tny_pair_get_value (pair));
+               g_object_unref (pair);
+       }
+       for (iter = tny_list_create_iterator (list);
+            !tny_iterator_is_done (iter);
+            tny_iterator_next (iter)) {
+               TnyMimePart *child;
+               child = (TnyMimePart *) tny_iterator_get_current (iter);
+               modest_tny_mime_part_to_string (child, indent + 3);
+               g_object_unref (child);
+       }
+       g_object_unref (iter);
+       g_object_unref (list);
+
+       g_string_free (indent_prefix, TRUE);
+}
 
 
index b1c577c..91a54f2 100644 (file)
@@ -56,4 +56,25 @@ gchar* modest_tny_mime_part_get_header_value (TnyMimePart *part, const gchar *he
 
 gboolean modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part);
 
 
 gboolean modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part);
 
+/**
+ * modest_tny_mime_part_is_msg:
+ * @part: a #TnyMimePart
+ *
+ * determines if this is a message (it's a TnyMsg and it's not a
+ * file attached as the top mime part of the TnyMsg).
+ *
+ * Returns: %TRUE if it's a real message, %FALSE otherwise
+ */
+gboolean modest_tny_mime_part_is_msg (TnyMimePart *part);
+
+/**
+ * modest_tny_mime_part_to_string:
+ * @part: a #TnyMimePart
+ * @indent: indent level (should be 0)
+ *
+ * Shows in stdout a text representation of the mime structure of
+ * the message. This is intended for debugging.
+ */
+void modest_tny_mime_part_to_string (TnyMimePart *part, gint indent);
+
 #endif /*__MODEST_TNY_MIME_PART_H__*/
 #endif /*__MODEST_TNY_MIME_PART_H__*/
index 48b2108..e1ad4eb 100644 (file)
@@ -401,10 +401,27 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht
        TnyMimePart *part = NULL;
        TnyList *parts = NULL;
        TnyIterator *iter = NULL;
        TnyMimePart *part = NULL;
        TnyList *parts = NULL;
        TnyIterator *iter = NULL;
+       gchar *header_content_type;
+       gchar *header_content_type_lower;
        
        if (!msg)
                return NULL;
 
        
        if (!msg)
                return NULL;
 
+       /* If it's an application multipart, then we don't get into as we don't
+        * support them (for example application/sml or wap messages */
+       header_content_type = modest_tny_mime_part_get_header_value (msg, "Content-Type");
+       header_content_type = g_strstrip (header_content_type);
+       header_content_type_lower = header_content_type?g_ascii_strdown (header_content_type, -1):NULL;
+       if (header_content_type_lower && 
+           g_str_has_prefix (header_content_type_lower, "multipart/") &&
+           strstr (header_content_type_lower, "application/")) {
+               g_free (header_content_type_lower);
+               g_free (header_content_type);
+               return NULL;
+       }
+       g_free (header_content_type_lower);
+       g_free (header_content_type);
+
        parts = TNY_LIST (tny_simple_list_new());
        tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
 
        parts = TNY_LIST (tny_simple_list_new());
        tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
 
@@ -412,8 +429,15 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht
 
        /* no parts? assume it's single-part message */
        if (tny_iterator_is_done(iter)) {
 
        /* no parts? assume it's single-part message */
        if (tny_iterator_is_done(iter)) {
+               const gchar *content_type;
                g_object_unref (G_OBJECT(iter));
                g_object_unref (G_OBJECT(iter));
-               return TNY_MIME_PART (g_object_ref(G_OBJECT(msg)));
+               content_type = tny_mime_part_get_content_type (msg);
+               /* if this part cannot be a supported body return NULL */
+               if (!g_str_has_prefix (content_type, "text/")) {
+                       return NULL;
+               } else {
+                       return TNY_MIME_PART (g_object_ref(G_OBJECT(msg)));
+               }
        } else {
                do {
                        gchar *tmp, *content_type = NULL;
        } else {
                do {
                        gchar *tmp, *content_type = NULL;
@@ -542,11 +566,12 @@ create_reply_forward_mail (TnyMsg *msg, TnyHeader *header, const gchar *from,
        else {
                /* for attachements; inline if there is a text part, and include the
                 * full old mail if there was none */
        else {
                /* for attachements; inline if there is a text part, and include the
                 * full old mail if there was none */
-               if (no_text_part) 
+               if (no_text_part) {
                        new_msg = modest_formatter_attach (formatter, msg, header);
                        new_msg = modest_formatter_attach (formatter, msg, header);
-               else 
+               } else { 
                        new_msg = modest_formatter_inline  (formatter, body, header,
                                                            attachments);
                        new_msg = modest_formatter_inline  (formatter, body, header,
                                                            attachments);
+               }
        }
        
        g_object_unref (G_OBJECT(formatter));
        }
        
        g_object_unref (G_OBJECT(formatter));
@@ -589,6 +614,10 @@ create_reply_forward_mail (TnyMsg *msg, TnyHeader *header, const gchar *from,
        g_object_unref (G_OBJECT (header));
        /* ugly to unref it here instead of in the calling func */
 
        g_object_unref (G_OBJECT (header));
        /* ugly to unref it here instead of in the calling func */
 
+       if (!is_reply & !no_text_part) {
+               add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE);
+       }
+
        return new_msg;
 }
 
        return new_msg;
 }
 
@@ -636,7 +665,6 @@ modest_tny_msg_create_forward_msg (TnyMsg *msg,
 
        new_msg = create_reply_forward_mail (msg, NULL, from, signature, FALSE, forward_type,
                                             attachments_list);
 
        new_msg = create_reply_forward_mail (msg, NULL, from, signature, FALSE, forward_type,
                                             attachments_list);
-       add_attachments (TNY_MIME_PART (new_msg), attachments_list, FALSE);
 
        /* Clean */
        if (attachments_list) {
 
        /* Clean */
        if (attachments_list) {
index 04742ad..0a3550d 100644 (file)
@@ -130,8 +130,36 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
         * embedded images in body */
        msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
        if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
         * embedded images in body */
        msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
        if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
-               gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
-               return;
+               gchar *header_content_type;
+               gchar *header_content_type_lower;
+               gboolean application_multipart = FALSE;
+               header_content_type = modest_tny_mime_part_get_header_value (TNY_MIME_PART (priv->msg), "Content-Type");
+               header_content_type = g_strstrip (header_content_type);
+               header_content_type_lower = header_content_type?g_ascii_strdown (header_content_type, -1):NULL;
+               
+               if (!strstr (header_content_type_lower, "application/"))
+                       application_multipart = TRUE;
+               
+               g_free (header_content_type);
+               g_free (header_content_type_lower);
+               if (application_multipart) {
+                       gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+                       return;
+               }
+       } else {
+               gchar *lower;
+               gboolean direct_attach;
+
+               lower = g_ascii_strdown (msg_content_type, -1);
+               direct_attach = (!g_str_has_prefix (lower, "message/rfc822") && 
+                                !g_str_has_prefix (lower, "multipart") && 
+                                !g_str_has_prefix (lower, "text/"));
+               g_free (lower);
+               if (direct_attach) {
+                       modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (msg), TRUE, 0);
+                       gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+                       return;
+               }
        }
 
        parts = TNY_LIST (tny_simple_list_new ());
        }
 
        parts = TNY_LIST (tny_simple_list_new ());