From 2ba06f65fa2b4676072689d8ba5c679b820defb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Fri, 10 Aug 2012 14:24:59 +0200 Subject: Bug #680786 - [text-highlight] Prefer Content-Type header over file name extension --- .../e-mail-formatter-text-highlight.c | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'modules/text-highlight/e-mail-formatter-text-highlight.c') diff --git a/modules/text-highlight/e-mail-formatter-text-highlight.c b/modules/text-highlight/e-mail-formatter-text-highlight.c index 7dfeac1c60..643e54b7f4 100644 --- a/modules/text-highlight/e-mail-formatter-text-highlight.c +++ b/modules/text-highlight/e-mail-formatter-text-highlight.c @@ -85,6 +85,7 @@ get_syntax (EMailPart *part, const gchar *uri) { gchar *syntax = NULL; + CamelContentType *ct = NULL; if (uri) { SoupURI *soup_uri = soup_uri_new (uri); @@ -98,30 +99,33 @@ get_syntax (EMailPart *part, soup_uri_free (soup_uri); } - /* Try to detect syntax from attachment filename extension */ + /* Try to detect syntax by content-type first */ if (syntax == NULL) { + ct = camel_mime_part_get_content_type (part->part); + if (ct) { + gchar *mime_type = camel_content_type_simple (ct); + + syntax = (gchar *) get_syntax_for_mime_type (mime_type); + syntax = syntax ? g_strdup (syntax) : NULL; + g_free (mime_type); + } + } + + /* If it fails or the content type too generic, try to detect it by + * filename extension */ + if (syntax == NULL || ct == NULL || + camel_content_type_is (ct, "application", "octet-stream") || + camel_content_type_is (ct, "text", "plain")) { const gchar *filename = camel_mime_part_get_filename (part->part); if (filename) { gchar *ext = g_strrstr (filename, "."); if (ext) { syntax = (gchar *) get_syntax_for_ext (ext + 1); - syntax = g_strdup (syntax ? syntax : "txt"); + syntax = syntax ? g_strdup (syntax) : NULL; } } } - /* Try it by mime type */ - if (syntax == NULL) { - CamelContentType *ct = camel_mime_part_get_content_type (part->part); - if (ct) { - gchar *mime_type = camel_content_type_simple (ct); - - syntax = (gchar *) get_syntax_for_mime_type (mime_type); - syntax = g_strdup (syntax ? syntax : "txt"); - g_free (mime_type); - } - } - /* Out of ideas - use plain text */ if (syntax == NULL) { syntax = g_strdup ("txt"); -- cgit v1.2.3