commit 179c736dbf494c20d6812e5310254b65aadb7904
parent aba296bd2f1beaa750add7656003d809dc763381
Author: Ricardo Mones <ricardo@mones.org>
Date: Fri, 26 Jul 2019 12:31:57 +0200
Don't show mojibake when encoding is not UTF-8
Litehtml expect displayed strings in UTF-8, so convert message part
before displaying.
Diffstat:
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git 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);