* mu-msg-file.c, mu-str.[ch]: ensure we only return valid UTF8 (because GMime

returns invalid UTF8 from invalidly encoded messages in some cases)
This commit is contained in:
Dirk-Jan C. Binnema
2011-07-17 14:35:59 +03:00
parent 59645ba268
commit 5695077514
3 changed files with 104 additions and 45 deletions

View File

@ -349,7 +349,6 @@ gint64
mu_str_size_parse_bkm (const char* str)
{
gint64 num;
const char *cur;
g_return_val_if_fail (str, -1);
@ -547,6 +546,46 @@ mu_str_escape_c_literal (const gchar* str)
}
/* turn \0-terminated buf into ascii (which is a utf8 subset); convert
* any non-ascii into '.'
*/
char*
mu_str_asciify_in_place (char *buf)
{
char *c;
for (c = buf; c && *c; ++c)
if (!isascii(*c))
c[0] = '.';
return buf;
}
gchar*
mu_str_convert_to_utf8 (const char* buffer, const char *charset)
{
GError *err;
gchar * utf8;
g_return_val_if_fail (buffer, NULL);
g_return_val_if_fail (charset, NULL );
err = NULL;
utf8 = g_convert_with_fallback (buffer, -1, "UTF-8",
charset, NULL,
NULL, NULL, &err);
if (!utf8) {
g_debug ("%s: conversion failed from %s: %s",
__FUNCTION__, charset, err ? err->message : "");
if (err)
g_error_free (err);
}
return utf8;
}
gchar*
mu_str_guess_last_name (const char *name)
{