From 0a15f82edefc3cef19c0dcb7c70b8e7ac7f0b60e Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 2 Apr 2012 20:01:58 +0300 Subject: [PATCH] * mu-msg-file.c: correctly display utf-8 encoded messages without explicit charset (such as mu4e draft messages) --- src/mu-msg-file.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/mu-msg-file.c b/src/mu-msg-file.c index 8b0198d9..9b2b4e1e 100644 --- a/src/mu-msg-file.c +++ b/src/mu-msg-file.c @@ -479,23 +479,29 @@ convert_to_utf8 (GMimePart *part, char *buffer) ctype = g_mime_object_get_content_type (GMIME_OBJECT(part)); g_return_val_if_fail (GMIME_IS_CONTENT_TYPE(ctype), NULL); - charset = g_mime_content_type_get_parameter (ctype, "charset"); - if (charset) - charset = g_mime_charset_iconv_name (charset); - /* of course, the charset specified may be incorrect... */ + charset = g_mime_content_type_get_parameter (ctype, "charset"); if (charset) { char *utf8; - utf8 = mu_str_convert_to_utf8 (buffer, charset); + utf8 = mu_str_convert_to_utf8 + (buffer, + g_mime_charset_iconv_name (charset)); if (utf8) { g_free (buffer); return utf8; } + } else if (g_utf8_validate (buffer, -1, NULL)) { + /* check if the buffer is valid utf8, even if it doesn't + * say so explicitly... if that is the case, return it as-is */ + + /* nothing to do, buffer is already utf8 */ + + } else { + /* hmmm.... no charset at all, or conversion failed; ugly + * hack: replace all non-ascii chars with '.' */ + mu_str_asciify_in_place (buffer); } - /* hmmm.... no charset at all, or conversion failed; ugly - * hack: replace all non-ascii chars with '.' */ - mu_str_asciify_in_place (buffer); return buffer; }