From 3c59b97fc992008f2eecaab20966b691b9a464ee Mon Sep 17 00:00:00 2001 From: djcb Date: Wed, 1 Aug 2012 17:03:55 +0300 Subject: [PATCH] * mu-str.c: make mu_str_convert_to_utf8 slightly more tolerant --- lib/mu-str.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/mu-str.c b/lib/mu-str.c index d53ab824..f01a4f3d 100644 --- a/lib/mu-str.c +++ b/lib/mu-str.c @@ -614,11 +614,18 @@ mu_str_convert_to_utf8 (const char* buffer, const char *charset) utf8 = g_convert_with_fallback (buffer, -1, "UTF-8", charset, NULL, NULL, NULL, &err); + if (!utf8) /* maybe the charset lied; try 8859-15 */ + utf8 = g_convert_with_fallback (buffer, -1, "UTF-8", + "ISO8859-15", NULL, + NULL, NULL, &err); + /* final attempt, maybe it was utf-8 already */ + if (!utf8 && g_utf8_validate (buffer, -1, NULL)) + utf8 = g_strdup (buffer); + if (!utf8) { - g_debug ("%s: conversion failed from %s: %s", + g_warning ("%s: conversion failed from %s: %s", __FUNCTION__, charset, err ? err->message : ""); - if (err) - g_error_free (err); + g_clear_error (&err); } return utf8;