From c21b3a8e3db223eb215ef17d0ea1762de694ea73 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 10 Sep 2014 17:45:30 +0100 Subject: [PATCH] Fix bug with charset conversion. Glib iconv understands only uppercase for charset names. --- src/libmime/message.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/libmime/message.c b/src/libmime/message.c index fff55b4fe..f4ab2211f 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -824,7 +824,7 @@ charset_validate (rspamd_mempool_t *pool, const gchar *in, gchar **out) * with alphanumeric */ const gchar *begin, *end; - gboolean changed = FALSE; + gboolean changed = FALSE, to_uppercase = FALSE; begin = in; @@ -832,6 +832,10 @@ charset_validate (rspamd_mempool_t *pool, const gchar *in, gchar **out) begin ++; changed = TRUE; } + if (!g_ascii_islower(*begin)) { + changed = TRUE; + to_uppercase = TRUE; + } end = begin + strlen (begin) - 1; while (!g_ascii_isalnum (*end)) { end --; @@ -843,7 +847,22 @@ charset_validate (rspamd_mempool_t *pool, const gchar *in, gchar **out) } else { *out = rspamd_mempool_alloc (pool, end - begin + 2); - rspamd_strlcpy (*out, begin, end - begin + 2); + if (to_uppercase) { + gchar *o = *out; + + while (begin != end + 1) { + if (g_ascii_islower (*begin)) { + *o++ = g_ascii_toupper (*begin ++); + } + else { + *o++ = *begin++; + } + } + *o = '\0'; + } + else { + rspamd_strlcpy (*out, begin, end - begin + 2); + } } return TRUE; @@ -908,6 +927,7 @@ convert_text_to_utf (struct rspamd_task *task, ocharset, err ? err->message : "unknown problem"); text_part->is_raw = TRUE; + g_error_free (err); return part_content; } -- 2.39.5