diff options
author | Dan Vrátil <dvratil@redhat.com> | 2012-10-09 05:27:29 +0800 |
---|---|---|
committer | Dan Vrátil <dvratil@redhat.com> | 2012-10-09 05:29:11 +0800 |
commit | d0734298d21c5a59ed408910b552d7c4ffa79577 (patch) | |
tree | 983316e93a1f5efd58dd5f74278e94615d85da27 | |
parent | ceda9fa5e742b511886335078cce6f5d2667295f (diff) | |
download | gsoc2013-evolution-d0734298d21c5a59ed408910b552d7c4ffa79577.tar gsoc2013-evolution-d0734298d21c5a59ed408910b552d7c4ffa79577.tar.gz gsoc2013-evolution-d0734298d21c5a59ed408910b552d7c4ffa79577.tar.bz2 gsoc2013-evolution-d0734298d21c5a59ed408910b552d7c4ffa79577.tar.lz gsoc2013-evolution-d0734298d21c5a59ed408910b552d7c4ffa79577.tar.xz gsoc2013-evolution-d0734298d21c5a59ed408910b552d7c4ffa79577.tar.zst gsoc2013-evolution-d0734298d21c5a59ed408910b552d7c4ffa79577.zip |
Bug #684447 - Fallback to text/plain when highlight program is missing or fails
We can't add a new dependency to Evolution 3.6, but the runtime
check will fallback to text/plain formatter when highlight program
is missing (or when it crashes or fails).
(cherry-picked from 5437fa7c354b5ddf12b4e13136834d86168e3580)
-rw-r--r-- | em-format/e-mail-formatter-text-plain.c | 1 | ||||
-rw-r--r-- | modules/text-highlight/e-mail-formatter-text-highlight.c | 85 |
2 files changed, 55 insertions, 31 deletions
diff --git a/em-format/e-mail-formatter-text-plain.c b/em-format/e-mail-formatter-text-plain.c index 7fd63b5566..5ef5ba3d1f 100644 --- a/em-format/e-mail-formatter-text-plain.c +++ b/em-format/e-mail-formatter-text-plain.c @@ -34,6 +34,7 @@ static const gchar *formatter_mime_types[] = { "text/plain", "text/*", "message/*", + "application/vnd.evolution.plaintext", NULL }; typedef struct _EMailFormatterTextPlain { diff --git a/modules/text-highlight/e-mail-formatter-text-highlight.c b/modules/text-highlight/e-mail-formatter-text-highlight.c index 48c6e7a742..e0a892cd20 100644 --- a/modules/text-highlight/e-mail-formatter-text-highlight.c +++ b/modules/text-highlight/e-mail-formatter-text-highlight.c @@ -258,43 +258,66 @@ emfe_text_highlight_format (EMailFormatterExtension *extension, argv[3] = g_strdup_printf ("--syntax=%s", syntax); g_free (syntax); - if (!g_spawn_async_with_pipes ( - NULL, (gchar **) argv, NULL, - G_SPAWN_SEARCH_PATH | - G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, &pid, &pipe_stdin, &pipe_stdout, NULL, NULL)) { - return FALSE; + if (g_spawn_async_with_pipes ( + NULL, (gchar **) argv, NULL, + G_SPAWN_SEARCH_PATH | + G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, &pid, &pipe_stdin, &pipe_stdout, NULL, NULL)) { + + write = camel_stream_fs_new_with_fd (pipe_stdin); + read = camel_stream_fs_new_with_fd (pipe_stdout); + + /* Decode the content of mime part to the 'utf8' stream */ + utf8 = camel_stream_mem_new (); + camel_data_wrapper_decode_to_stream_sync ( + 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); + + g_seekable_seek (G_SEEKABLE (read), 0, G_SEEK_SET, cancellable, NULL); + camel_stream_write_to_stream (read, stream, cancellable, NULL); + g_object_unref (read); + } else { + /* We can't call e_mail_formatter_format_as on text/plain, + * because text-highlight is registered as an handler for + * text/plain, so we would end up in an endless recursion. + * + * Just return FALSE here and EMailFormatter will automatically + * fall back to the default text/plain formatter */ + if (camel_content_type_is (ct, "text", "plain")) { + g_free (font_family); + g_free (font_size); + g_free ((gchar *) argv[3]); + pango_font_description_free (fd); + + return FALSE; + } else { + /* In case of any other content, force use of + * text/plain formatter, because returning FALSE + * for text/x-patch or application/php would show + * an error, as there is no other handler registered + * for these */ + e_mail_formatter_format_as ( + formatter, context, part, stream, + "application/vnd.evolution.plaintext", + cancellable); + } } - write = camel_stream_fs_new_with_fd (pipe_stdin); - read = camel_stream_fs_new_with_fd (pipe_stdout); - - /* Decode the content of mime part to the 'utf8' stream */ - utf8 = camel_stream_mem_new (); - camel_data_wrapper_decode_to_stream_sync ( - 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); - - g_seekable_seek (G_SEEKABLE (read), 0, G_SEEK_SET, cancellable, NULL); - camel_stream_write_to_stream (read, stream, cancellable, NULL); - g_object_unref (read); - g_free (font_family); g_free (font_size); g_free ((gchar *) argv[3]); pango_font_description_free (fd); - } else { gchar *uri, *str; gchar *syntax; |