diff options
author | Dan Vrátil <dvratil@redhat.com> | 2012-08-10 20:24:59 +0800 |
---|---|---|
committer | Dan Vrátil <dvratil@redhat.com> | 2012-08-10 20:26:04 +0800 |
commit | 2ba06f65fa2b4676072689d8ba5c679b820defb7 (patch) | |
tree | ee3c00baeed2493f3f45ccf389544bc3470cb01f /modules/text-highlight | |
parent | 208a55d765329712293980babbd2163469f81a42 (diff) | |
download | gsoc2013-evolution-2ba06f65fa2b4676072689d8ba5c679b820defb7.tar.gz gsoc2013-evolution-2ba06f65fa2b4676072689d8ba5c679b820defb7.tar.zst gsoc2013-evolution-2ba06f65fa2b4676072689d8ba5c679b820defb7.zip |
Bug #680786 - [text-highlight] Prefer Content-Type header over file name extension
Diffstat (limited to 'modules/text-highlight')
-rw-r--r-- | modules/text-highlight/e-mail-formatter-text-highlight.c | 32 |
1 files changed, 18 insertions, 14 deletions
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"); |