Fix const correctness
[claws.git] / src / plugins / litehtml_viewer / lh_viewer.c
index a567d2ccbc3d1714c5c98f5e642323f667a3d4f9..03775dc789c6652c7d799a4d5d098ea818fd1158 100644 (file)
@@ -86,13 +86,32 @@ 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;
+       const gchar *charset;
 
-       if (utf8 == NULL) {
+       if (string == NULL) {
                g_warning("LH: couldn't get MIME part file\n");
                return;
        }
 
+       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);
+                       g_error_free(error);
+                       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);