aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2012-10-09 05:27:29 +0800
committerDan Vrátil <dvratil@redhat.com>2012-10-09 05:27:29 +0800
commit5437fa7c354b5ddf12b4e13136834d86168e3580 (patch)
tree30f8236f3ce563a40aeadfdbb3eb18b90b2f219c
parent1cfe0327ca436a687383412664e3a5c2869c7dda (diff)
downloadgsoc2013-evolution-5437fa7c354b5ddf12b4e13136834d86168e3580.tar
gsoc2013-evolution-5437fa7c354b5ddf12b4e13136834d86168e3580.tar.gz
gsoc2013-evolution-5437fa7c354b5ddf12b4e13136834d86168e3580.tar.bz2
gsoc2013-evolution-5437fa7c354b5ddf12b4e13136834d86168e3580.tar.lz
gsoc2013-evolution-5437fa7c354b5ddf12b4e13136834d86168e3580.tar.xz
gsoc2013-evolution-5437fa7c354b5ddf12b4e13136834d86168e3580.tar.zst
gsoc2013-evolution-5437fa7c354b5ddf12b4e13136834d86168e3580.zip
Bug #684447 - Check for highlight during configure.
If the highlight program cannot be found width AC_PATH_PROGS, configure will abort with an error message. You can either a) install highlight b) specify the patch with HIGHLIGHT=/path/to/highlight c) pass --disable-text-highlight to configure to exclude the module This also makes text-highlight module to fallback to text/plain formatter when highlight program would crash or fail to ensure the content is delivered to user.
-rw-r--r--configure.ac30
-rw-r--r--em-format/e-mail-formatter-text-plain.c1
-rw-r--r--modules/Makefile.am8
-rw-r--r--modules/text-highlight/e-mail-formatter-text-highlight.c85
4 files changed, 91 insertions, 33 deletions
diff --git a/configure.ac b/configure.ac
index 95f6ca979b..db4a7af05f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1312,6 +1312,35 @@ fi
AM_CONDITIONAL([ENABLE_AUDIO_INLINE], [test "x$enable_audio_inline" = "xyes"])
+dnl **************************************************
+dnl text-highlight plugins requires highlight utility
+dnl **************************************************
+AC_ARG_ENABLE([text-highlight],
+ [AS_HELP_STRING([--enable-text-highlight],
+ [Enable text-highlight plugin (default=yes)])],
+ [enable_text_highlight="$enableval"], [enable_text_highlight=yes])
+AC_MSG_CHECKING([if source code highlighting support is enabled])
+AC_MSG_RESULT([$enable_text_highlight])
+msg_text_highlight="$enable_text_highlight"
+if test "x$enable_text_highlight" = "xyes"; then
+ AC_ARG_VAR([HIGHLIGHT], [Source code highlighting utility])
+ AC_PATH_PROG([HIGHLIGHT], [highlight])
+ if test "x$HIGHLIGHT" == "x"; then
+ AC_MSG_ERROR([
+
+ Highlight utility not found.
+
+ If you want to disable text-highlight plugin,
+ please append --disable-text-highlight to configure.])
+ fi
+ AC_DEFINE_UNQUOTED(
+ HIGHLIGHT_COMMAND, "$HIGHLIGHT",
+ [Source code highlighting utility])
+
+ msg_text_highlight="$msg_text_highlight ($HIGHLIGHT)"
+fi
+AM_CONDITIONAL([ENABLE_TEXT_HIGHLIGHT], [test "x$enable_text_highlight" = "xyes"])
+
dnl **************************************
dnl Weather calendars require gweather-3.0
dnl **************************************
@@ -1685,6 +1714,7 @@ echo "
SMIME support: $msg_smime
Bogofilter support: $msg_bogofilter
SpamAssassin support: $msg_spamassassin
+ Highlight support: $msg_text_highlight
Plugins: $msg_plugins
User documentation: $with_help
"
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/Makefile.am b/modules/Makefile.am
index a7e34de52b..6bb19c8071 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -26,6 +26,10 @@ if ENABLE_AUDIO_INLINE
AUDIO_INLINE_DIR = audio-inline
endif
+if ENABLE_TEXT_HIGHLIGHT
+TEXT_HIGHLIGHT_DIR = text-highlight
+endif
+
SUBDIRS = \
addressbook \
calendar \
@@ -52,13 +56,13 @@ SUBDIRS = \
plugin-manager \
prefer-plain \
startup-wizard \
- text-highlight \
vcard-inline \
web-inspector \
$(BOGOFILTER_DIR) \
$(ONLINE_ACCOUNTS_DIR) \
$(SPAMASSASSIN_DIR) \
$(TNEF_ATTACHMENT_DIR) \
- $(AUDIO_INLINE_DIR)
+ $(AUDIO_INLINE_DIR) \
+ $(TEXT_HIGHLIGHT_DIR)
-include $(top_srcdir)/git.mk
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;