diff options
author | Dan Vrátil <dvratil@redhat.com> | 2012-08-23 17:12:39 +0800 |
---|---|---|
committer | Dan Vrátil <dvratil@redhat.com> | 2012-08-23 17:12:39 +0800 |
commit | 164d4aeaddabe4987089003adc38f1d05cbb6111 (patch) | |
tree | 601710826f3bc1c8a3e707f40c1aabf51faf2fef | |
parent | 1d9b69527aa57b3ed815b8ad0791743d89c96556 (diff) | |
download | gsoc2013-evolution-164d4aeaddabe4987089003adc38f1d05cbb6111.tar.gz gsoc2013-evolution-164d4aeaddabe4987089003adc38f1d05cbb6111.tar.zst gsoc2013-evolution-164d4aeaddabe4987089003adc38f1d05cbb6111.zip |
Bug #680786 - [text-highlight] Correctly display binary patches
-rw-r--r-- | modules/text-highlight/e-mail-formatter-text-highlight.c | 25 |
1 files changed, 19 insertions, 6 deletions
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); |