2011-01-06 [colin] 3.7.8cvs31
[claws.git] / src / unmime.c
index 6abd31ebd94f2bb4ae339605ce6f7138ac0d2990..6feb016fd076648c366db81819f1a0e4086d5cfb 100644 (file)
@@ -34,7 +34,7 @@
 
 /* Decodes headers based on RFC2045 and RFC2047. */
 
-gchar *unmime_header(const gchar *encoded_str)
+gchar *unmime_header(const gchar *encoded_str, gboolean addr_field)
 {
        const gchar *p = encoded_str;
        const gchar *eword_begin_p, *encoding_begin_p, *text_begin_p,
@@ -45,11 +45,13 @@ gchar *unmime_header(const gchar *encoded_str)
        GString *outbuf;
        gchar *out_str;
        gsize out_len;
+       int in_quote = FALSE;
 
        outbuf = g_string_sized_new(strlen(encoded_str) * 2);
 
        while (*p != '\0') {
                gchar *decoded_text = NULL;
+               const gchar *quote_p;
                gint len;
 
                eword_begin_p = strstr(p, ENCODED_WORD_BEGIN);
@@ -57,6 +59,18 @@ gchar *unmime_header(const gchar *encoded_str)
                        g_string_append(outbuf, p);
                        break;
                }
+               
+               quote_p = p;
+               while ((quote_p = strchr(quote_p, '"')) != NULL) {
+                       if (quote_p && quote_p < eword_begin_p) {
+                               /* Found a quote before the encoded word. */
+                               in_quote = !in_quote;
+                               quote_p++;
+                       }
+                       if (quote_p >= eword_begin_p)
+                               break;
+               }
+
                encoding_begin_p = strchr(eword_begin_p + 2, '?');
                if (!encoding_begin_p) {
                        g_string_append(outbuf, p);
@@ -119,7 +133,7 @@ gchar *unmime_header(const gchar *encoded_str)
                 * We check there are no quotes just to be sure. If there
                 * are, well, the comma won't pose a problem, probably.
                 */
-               if (strchr(decoded_text, ',') && !strchr(decoded_text, '"')) {
+               if (addr_field && strchr(decoded_text, ',') && !in_quote) {
                        gchar *tmp = g_strdup_printf("\"%s\"", decoded_text);
                        g_free(decoded_text);
                        decoded_text = tmp;