[balsa/gtk3] Use a filter to quote html-only messages
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk3] Use a filter to quote html-only messages
- Date: Sun, 5 Jun 2016 13:55:36 +0000 (UTC)
commit 378f25a7efedab31e9a97ce82443367631065ec5
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sun Jun 5 09:54:06 2016 -0400
Use a filter to quote html-only messages
* configure.ac: detect an html-to-text-or-markdown filter;
* libbalsa/html.c (html2text), (libbalsa_html_to_string):
use it.
ChangeLog | 10 +++++++++
configure.ac | 13 +++++++++++
libbalsa/html.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 78 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 23cb5d5..5650294 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-06-05 Albrecht Dreß
+
+ As Webkit does not have a method to convert html to text,
+ we cannot quote html-only messages.
+ As a workaround, try to use html2text.
+
+ * configure.ac: detect an html-to-text-or-markdown filter;
+ * libbalsa/html.c (html2text), (libbalsa_html_to_string):
+ use it.
+
2016-06-04 Albrecht Dreß
Force proper icon sizes
diff --git a/configure.ac b/configure.ac
index f247038..d02cd36 100644
--- a/configure.ac
+++ b/configure.ac
@@ -367,6 +367,19 @@ case "$use_html_widget" in
fi
fi
AC_DEFINE(HAVE_WEBKIT,1,[Defined when WebKit can be used.])
+ AC_PATH_PROGS(HTML2TEXT,
+ [python-html2text \
+ html2markdown \
+ html2markdown.py2 \
+ html2markdown.py3 \
+ html2text],
+ no)
+ if test x"$ac_cv_path_HTML2TEXT" != "xno" ; then
+ AC_DEFINE_UNQUOTED(HTML2TEXT, "$ac_cv_path_HTML2TEXT",
+ [Path to html2text program.])
+ else
+ AC_MSG_WARN([You cannot properly quote html-only messags.])
+ fi
;;
no)
AC_MSG_RESULT([none])
diff --git a/libbalsa/html.c b/libbalsa/html.c
index 2078eb0..1616840 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -79,6 +79,57 @@ lbh_get_body_content(LibBalsaMessageBody * body, gchar ** buf)
}
# if defined(HAVE_WEBKIT)
+
+#ifdef HTML2TEXT
+
+/* common function for all Webkit versions */
+static void
+html2text(gchar ** text, gsize len)
+{
+ gchar *html2text[] = { HTML2TEXT, NULL, NULL };
+ GFile *html_data;
+ GFileIOStream *stream;
+ GError *err = NULL;
+
+ html_data = g_file_new_tmp("balsa-conv-XXXXXX.html", &stream, &err);
+ if (html_data != NULL) {
+ gsize bytes_written;
+ GOutputStream *ostream =
+ g_io_stream_get_output_stream(G_IO_STREAM(stream));
+
+ if (g_output_stream_write_all(ostream, *text, len,
+ &bytes_written, NULL, &err)) {
+ gchar *result = NULL;
+
+ g_output_stream_flush(ostream, NULL, NULL);
+ html2text[1] = g_file_get_path(html_data);
+ if (g_spawn_sync(NULL, html2text, NULL,
+ G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
+ &result, NULL, NULL, &err)) {
+ g_free(*text);
+ *text = result;
+ }
+ g_free(html2text[1]);
+ }
+ g_output_stream_close(ostream, NULL, NULL);
+ g_object_unref(G_OBJECT(stream));
+ g_file_delete(html_data, NULL, NULL);
+ g_object_unref(G_OBJECT(html_data));
+ }
+ if (err != NULL) {
+ libbalsa_information(LIBBALSA_INFORMATION_ERROR,
+ _("Could not convert HTML part to text: %s"),
+ err ? err->message : "Unknown error");
+ g_error_free(err);
+ }
+}
+
+#else
+
+#define html2text(p, l)
+
+#endif
+
# if defined(USE_WEBKIT2)
/*
@@ -607,9 +658,8 @@ libbalsa_html_new(LibBalsaMessageBody * body,
void
libbalsa_html_to_string(gchar ** text, size_t len)
{
- return; /* this widget does not support conversion to a string. The
- * string won't be altered. Other alternative would be to set
- * it to an empty string. */
+ /* this widget does not support conversion to a string. */
+ html2text(text, len);
}
/*
@@ -1259,9 +1309,8 @@ libbalsa_html_new(LibBalsaMessageBody * body,
void
libbalsa_html_to_string(gchar ** text, size_t len)
{
- return; /* this widget does not support conversion to a string. The
- * string won't be altered. Other alternative would be to set
- * it to an empty string. */
+ /* this widget does not support conversion to a string. */
+ html2text(text, len);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]