X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-mime-part.c;h=3e9a4736cdc6bd678adce94e8ead75959cac0fc6;hp=15001207bf5a4dff7fb406382679428bc1361b29;hb=80d46e0ddb62768d3ce531038da3e055aa8feaba;hpb=4e501493efaac0d9331e924a2ea569497abff1bf diff --git a/src/modest-tny-mime-part.c b/src/modest-tny-mime-part.c index 1500120..3e9a473 100644 --- a/src/modest-tny-mime-part.c +++ b/src/modest-tny-mime-part.c @@ -83,10 +83,30 @@ modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part) gboolean has_content_disp_name = FALSE; 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)) + + /* purged attachments were attachments in the past, so they're + * still attachments */ + if (tny_mime_part_is_purged (part)) return TRUE; + + /* if tinymail thinks it's an attachment, it is. One exception: if it's + * a multipart and it's not a message/rfc822 it cannot be an attahcment */ + if (tny_mime_part_is_attachment (part)) { + if (!TNY_IS_MSG (part)) { + const gchar *content_type; + gchar *down_content_type; + gboolean is_attachment; + + content_type = tny_mime_part_get_content_type (part); + down_content_type = g_ascii_strdown (content_type, -1); + + is_attachment = !g_str_has_prefix (down_content_type, "multipart/"); + g_free (down_content_type); + return is_attachment; + } else { + return TRUE; + } + } /* if the mime part is a message itself (ie. embedded), it's an attachment */ if (TNY_IS_MSG (part)) @@ -94,9 +114,22 @@ modest_tny_mime_part_is_attachment_for_modest (TnyMimePart *part) tmp = modest_tny_mime_part_get_header_value (part, "Content-Disposition"); if (tmp) { + /* If the Content-Disposition header contains a "name" + * parameter, treat the mime part as an attachment */ gchar *content_disp = g_ascii_strdown(tmp, -1); + gint len = strlen (content_disp); + const gchar *substr = g_strstr_len (content_disp, len, "name"); + if (substr != NULL) { + gint substrlen = len - (substr - content_disp); + /* The parameter can appear in muliple + * ways. See RFC 2231 for details */ + has_content_disp_name = + g_strstr_len (substr, substrlen, "name=") != NULL || + g_strstr_len (substr, substrlen, "name*=") != NULL || + g_strstr_len (substr, substrlen, "name*0=") != NULL || + g_strstr_len (substr, substrlen, "name*0*=") != NULL; + } g_free (tmp); - has_content_disp_name = g_strstr_len (content_disp, strlen(content_disp), "name=") != NULL; g_free (content_disp); } @@ -129,16 +162,21 @@ gboolean modest_tny_mime_part_is_msg (TnyMimePart *part) { const gchar *content_type; + gchar *down_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/"))) { + down_content_type = g_ascii_strdown (content_type, -1); + if ((g_str_has_prefix (down_content_type, "message/rfc822") || + g_str_has_prefix (down_content_type, "multipart/") || + g_str_has_prefix (down_content_type, "text/plain") || + g_str_has_prefix (down_content_type, "text/html"))) { + g_free (down_content_type); return TRUE; } else { + g_free (down_content_type); return FALSE; } } @@ -194,3 +232,46 @@ modest_tny_mime_part_to_string (TnyMimePart *part, gint indent) g_string_free (indent_prefix, TRUE); } +gchar * +modest_tny_mime_part_get_headers_content_type (TnyMimePart *part) +{ + gchar *header_content_type; + gchar *suffix; + + g_return_val_if_fail (TNY_IS_MIME_PART (part), NULL); + + header_content_type = modest_tny_mime_part_get_header_value (part, "Content-Type"); + + /* See RFC2045 sec 5.2 */ + if (!header_content_type) + return g_strdup ("text/plain; charset=us-ascii"); + + header_content_type = g_strstrip (header_content_type); + + /* remove the ; suffix */ + suffix = index (header_content_type, ';'); + if (suffix) + suffix[0] = '\0'; + + return g_ascii_strdown (header_content_type, -1); +} + +gchar * +modest_tny_mime_part_get_content_type (TnyMimePart *part) +{ + const gchar *content_type; + gchar *retval = NULL; + + g_return_val_if_fail (TNY_IS_MIME_PART (part), NULL); + content_type = tny_mime_part_get_content_type (part); + + if (g_str_has_prefix (content_type, "message/rfc822")) { + retval = modest_tny_mime_part_get_headers_content_type (part); + } + + if (retval == NULL) { + retval = g_ascii_strdown (content_type, -1); + } + + return retval; +}