* Fixes NB#85743, do not hang when changing outgoing settings while sending
[modest] / src / modest-tny-msg.c
index b7c761d..9aeb40d 100644 (file)
@@ -312,8 +312,18 @@ add_attachments (TnyMimePart *part, GList *attachments_list, gboolean add_inline
                        old_cid = tny_mime_part_get_content_id (old_attachment);
                        attachment_part = copy_mime_part (old_attachment, err);
                        if (attachment_part != NULL) {
-                               tny_mime_part_set_header_pair (attachment_part, "Content-Disposition", 
-                                                              add_inline?"inline":"attachment");
+                               if (add_inline) {
+                                       tny_mime_part_set_header_pair (attachment_part, "Content-Disposition",
+                                                                      "inline");
+                               } else {
+                                       const gchar *filename;
+                                       filename = tny_mime_part_get_filename (old_attachment);
+                                       if (filename)
+                                               tny_mime_part_set_filename (attachment_part, filename);
+                                       else
+                                               tny_mime_part_set_header_pair (attachment_part, "Content-Disposition",
+                                                                              "attachment");
+                               }
                                tny_mime_part_set_transfer_encoding (TNY_MIME_PART (attachment_part), "base64");
                                ret = tny_mime_part_add_part (TNY_MIME_PART (part), attachment_part);
                                if (old_cid)
@@ -442,11 +452,20 @@ 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)) {
-               const gchar *content_type;
+               gchar *content_type;
+               gchar *content_type_lower;
+               gboolean is_text_part;
                g_object_unref (G_OBJECT(iter));
-               content_type = tny_mime_part_get_content_type (msg);
+               content_type = g_strdup (tny_mime_part_get_content_type (msg));
+               if (content_type == NULL)
+                       return NULL;
+               content_type = g_strstrip (content_type);
+               content_type_lower = g_ascii_strdown (content_type, -1);
+               g_free (content_type);
+               is_text_part = g_str_has_prefix (content_type_lower, "text/");
+               g_free (content_type_lower);
                /* if this part cannot be a supported body return NULL */
-               if (!g_str_has_prefix (content_type, "text/")) {
+               if (!is_text_part) {
                        return NULL;
                } else {
                        return TNY_MIME_PART (g_object_ref(G_OBJECT(msg)));
@@ -487,7 +506,9 @@ modest_tny_msg_find_body_part_from_mime_part (TnyMimePart *msg, gboolean want_ht
                                g_free (content_disp);
                        }
                        
-                       if (g_str_has_prefix (content_type, desired_mime_type) && !has_content_disp_name) {
+                       if (g_str_has_prefix (content_type, desired_mime_type) && 
+                           !has_content_disp_name &&
+                           !modest_tny_mime_part_is_attachment_for_modest (part)) {
                                /* we found the desired mime-type! */
                                g_free (content_type);
                                break;