[evolution] Bug #680786 - [text-highlight] Prefer Content-Type header over file name extension



commit 2ba06f65fa2b4676072689d8ba5c679b820defb7
Author: Dan VrÃtil <dvratil redhat com>
Date:   Fri Aug 10 14:24:59 2012 +0200

    Bug #680786 - [text-highlight] Prefer Content-Type header over file name extension

 .../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 7dfeac1..643e54b 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");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]