]> source.dussan.org Git - rspamd.git/commitdiff
Fix bug with charset conversion.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 10 Sep 2014 16:45:30 +0000 (17:45 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 10 Sep 2014 16:45:30 +0000 (17:45 +0100)
Glib iconv understands only uppercase for charset names.

src/libmime/message.c

index fff55b4fe62202d3ee0067b0376718a7e9671e03..f4ab2211f08363c992307d5ee5cb411c0396e7fb 100644 (file)
@@ -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;
        }