[evolution-data-server/gnome-3-6] Bug #686924 - Doesn't parse Gerrit encoded From address correctly



commit a0d04e1ce5dacc564782d1a8300f61d2e4a74087
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 29 15:13:41 2012 +0100

    Bug #686924 - Doesn't parse Gerrit encoded From address correctly

 camel/camel-mime-utils.c |   48 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 2 deletions(-)
---
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index 1a614b7..f4395b1 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -2050,17 +2050,61 @@ header_decode_atom (const gchar **in)
 		return NULL;
 }
 
+static gboolean
+extract_rfc2047_encoded_word (const gchar **in,
+			      gchar **word)
+{
+	const gchar *inptr = *in, *start;
+
+	header_decode_lwsp (&inptr);
+	start = inptr;
+
+	if (!strncmp (inptr, "=?", 2)) {
+		inptr += 2;
+
+		/* skip past the charset (if one is even declared, sigh) */
+		while (*inptr && *inptr != '?') {
+			inptr++;
+		}
+
+		/* sanity check encoding type */
+		if (inptr[0] != '?' || !strchr ("BbQq", inptr[1]) || !inptr[1] || inptr[2] != '?')
+			return FALSE;
+
+		inptr += 3;
+
+		/* find the end of the rfc2047 encoded word token */
+		while (*inptr && strncmp (inptr, "?=", 2) != 0) {
+			inptr++;
+		}
+
+		if (!strncmp (inptr, "?=", 2)) {
+			inptr += 2;
+
+			*in = inptr;
+			*word = g_strndup (start, inptr - start);
+
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
 static gchar *
 header_decode_word (const gchar **in)
 {
 	const gchar *inptr = *in;
+	gchar *word = NULL;
 
 	header_decode_lwsp (&inptr);
+	*in = inptr;
+
 	if (*inptr == '"') {
-		*in = inptr;
 		return header_decode_quoted_string (in);
+	} else if (*inptr == '=' && inptr[1] == '?' && extract_rfc2047_encoded_word (in, &word) && word) {
+		return word;
 	} else {
-		*in = inptr;
 		return header_decode_atom (in);
 	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]