[Commits] [SCM] claws branch, master, updated. 3.17.3-200-g739b2a5

mones at claws-mail.org mones at claws-mail.org
Fri Jul 26 12:35:02 CEST 2019


The branch, master has been updated
       via  739b2a56f654ff8c1879f338f4e617eb3aa1d642 (commit)
      from  a9dee921d8584d873dc7026d0f46a31ec4ffcf24 (commit)

Summary of changes:
 src/plugins/litehtml_viewer/lh_viewer.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)


- Log -----------------------------------------------------------------
commit 739b2a56f654ff8c1879f338f4e617eb3aa1d642
Author: Ricardo Mones <ricardo at mones.org>
Date:   Fri Jul 26 12:31:57 2019 +0200

    Don't show mojibake when encoding is not UTF-8
    
    Litehtml expect displayed strings in UTF-8, so convert message part
    before displaying.

diff --git a/src/plugins/litehtml_viewer/lh_viewer.c b/src/plugins/litehtml_viewer/lh_viewer.c
index a567d2c..bf6435b 100644
--- a/src/plugins/litehtml_viewer/lh_viewer.c
+++ b/src/plugins/litehtml_viewer/lh_viewer.c
@@ -86,13 +86,30 @@ static void lh_show_mimepart(MimeViewer *_viewer, const gchar *infile,
 {
 	debug_print("LH: show_mimepart\n");
 	LHViewer *viewer = (LHViewer *)_viewer;
-	gchar *utf8 = procmime_get_part_as_string(partinfo, TRUE);
+	gchar *string = procmime_get_part_as_string(partinfo, TRUE);
+	gchar *utf8 = NULL;
 
-	if (utf8 == NULL) {
+	if (string == NULL) {
 		g_warning("LH: couldn't get MIME part file\n");
 		return;
 	}
 
+	gchar *charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
+	if (charset != NULL && g_ascii_strcasecmp("utf-8", charset) != 0) {
+		gsize length;
+		GError *error = NULL;
+		debug_print("LH: converting mimepart to UTF-8 from %s\n", charset);
+		utf8 = g_convert(string, -1, "utf-8", charset, NULL, &length, &error);
+		if (error) {
+			g_warning("LH: failed mimepart conversion to UTF-8: %s", error->message);
+			g_free(string);
+			return;
+		}
+		debug_print("LH: successfully converted %" G_GSIZE_FORMAT " bytes\n", length);
+	} else {
+		utf8 = string;
+	}
+
 	lh_widget_set_partinfo(viewer->widget, partinfo);
 	lh_widget_open_html(viewer->widget, utf8);
 	g_free(utf8);

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list