From 164d4aeaddabe4987089003adc38f1d05cbb6111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Thu, 23 Aug 2012 11:12:39 +0200 Subject: Bug #680786 - [text-highlight] Correctly display binary patches --- .../e-mail-formatter-text-highlight.c | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 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 b9ce34dc6b..d3bec3878b 100644 --- a/modules/text-highlight/e-mail-formatter-text-highlight.c +++ b/modules/text-highlight/e-mail-formatter-text-highlight.c @@ -113,9 +113,10 @@ get_syntax (EMailPart *part, /* 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")) { + 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, "."); @@ -188,9 +189,10 @@ emfe_text_highlight_format (EMailFormatterExtension *extension, } else if (context->mode == E_MAIL_FORMATTER_MODE_RAW) { gint stdin, stdout; GPid pid; - CamelStream *read, *write; + CamelStream *read, *write, *utf8; CamelDataWrapper *dw; - gchar *font_family, *font_size, *syntax; + gchar *font_family, *font_size, *syntax, *tmp; + GByteArray *ba; gboolean use_custom_font; EShell *shell; EShellSettings *settings; @@ -267,8 +269,19 @@ emfe_text_highlight_format (EMailFormatterExtension *extension, write = camel_stream_fs_new_with_fd (stdin); read = camel_stream_fs_new_with_fd (stdout); + /* Decode the content of mime part to the 'utf8' stream */ + utf8 = camel_stream_mem_new (); camel_data_wrapper_decode_to_stream_sync ( - dw, write, cancellable, NULL); + dw, utf8, cancellable, NULL); + + /* Convert the binary data do someting displayable */ + ba = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (utf8)); + tmp = e_util_utf8_data_make_valid ((gchar *) ba->data, ba->len); + + /* Send the sanitized data to the highlighter */ + camel_stream_write_string (write, tmp, cancellable, NULL); + g_free (tmp); + g_object_unref (utf8); g_object_unref (write); g_spawn_close_pid (pid); -- cgit v1.2.3