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);
}
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;
+}