/* 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,
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);
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);
* 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;