[gmime/gmime-2-4] Fixed broken header text/phrase decoding



commit 69a157c1d53360a48a81fe4b04d1c9c5c5000886
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Fri Sep 17 11:41:33 2010 -0400

    Fixed broken header text/phrase decoding
    
    2010-09-17  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-utils.c (g_mime_utils_header_decode_text): In the
    	workaround case, if we don't find an end marker, reset our inptr
    	to the beginning of the most recent word *plus 2* (to skip over
    	the leading "=?"), not the beginning of the input text. Also
    need
    	to reset our ascii state.
    	(g_mime_utils_header_decode_phrase): In the workaround case, if
    we
    	don't find an end marker, reset our inptr to the beginning of
    the
    	most recent word *plus 2*, to skip over the leading "=?".

 ChangeLog           |   11 +++++++++++
 gmime/gmime-utils.c |   23 +++++++++++++----------
 tests/test-mime.c   |    3 +--
 3 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b568bf1..f8ba09a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-09-17  Jeffrey Stedfast  <fejj novell com>
+
+	* gmime/gmime-utils.c (g_mime_utils_header_decode_text): In the
+	workaround case, if we don't find an end marker, reset our inptr
+	to the beginning of the most recent word *plus 2* (to skip over
+	the leading "=?"), not the beginning of the input text. Also need
+	to reset our ascii state.
+	(g_mime_utils_header_decode_phrase): In the workaround case, if we
+	don't find an end marker, reset our inptr to the beginning of the
+	most recent word *plus 2*, to skip over the leading "=?".
+
 2010-09-16  Jeffrey Stedfast  <fejj novell com>
 
 	* gmime/gmime-encodings.c (g_mime_encoding_quoted_encode_close):
diff --git a/gmime/gmime-utils.c b/gmime/gmime-utils.c
index 67aa6c1..3a5929f 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -1901,7 +1901,9 @@ g_mime_utils_header_decode_text (const char *text)
 					
 					if (*inptr == '\0') {
 						/* didn't find an end marker... */
-						inptr = text;
+						inptr = word + 2;
+						ascii = TRUE;
+						
 						goto non_rfc2047;
 					}
 					
@@ -1989,7 +1991,7 @@ g_mime_utils_header_decode_phrase (const char *phrase)
 	gboolean enable_rfc2047_workarounds = _g_mime_enable_rfc2047_workarounds ();
 	register const char *inptr = phrase;
 	gboolean encoded = FALSE;
-	const char *lwsp, *text;
+	const char *lwsp, *word;
 	size_t nlwsp, n;
 	gboolean ascii;
 	char *decoded;
@@ -2007,7 +2009,7 @@ g_mime_utils_header_decode_phrase (const char *phrase)
 		
 		nlwsp = (size_t) (inptr - lwsp);
 		
-		text = inptr;
+		word = inptr;
 		if (is_atom (*inptr)) {
 			if (G_UNLIKELY (enable_rfc2047_workarounds)) {
 				/* Make an extra effort to detect and
@@ -2034,7 +2036,7 @@ g_mime_utils_header_decode_phrase (const char *phrase)
 					
 					if (*inptr == '\0') {
 						/* didn't find an end marker... */
-						inptr = text;
+						inptr = word + 2;
 						goto non_rfc2047;
 					}
 					
@@ -2051,9 +2053,10 @@ g_mime_utils_header_decode_phrase (const char *phrase)
 					inptr++;
 			}
 			
-			n = (size_t) (inptr - text);
-			if (is_rfc2047_encoded_word (text, n)) {
-				if ((decoded = rfc2047_decode_word (text, n))) {
+			n = (size_t) (inptr - word);
+			printf ("decoding word: %.*s\n", n, word);
+			if (is_rfc2047_encoded_word (word, n)) {
+				if ((decoded = rfc2047_decode_word (word, n))) {
 					/* rfc2047 states that you must ignore all
 					 * whitespace between encoded words */
 					if (!encoded)
@@ -2082,15 +2085,15 @@ g_mime_utils_header_decode_phrase (const char *phrase)
 				inptr++;
 			}
 			
-			n = (size_t) (inptr - text);
+			n = (size_t) (inptr - word);
 			
 			if (!ascii) {
 				/* *sigh* I hate broken mailers... */
-				decoded = g_mime_utils_decode_8bit (text, n);
+				decoded = g_mime_utils_decode_8bit (word, n);
 				g_string_append (out, decoded);
 				g_free (decoded);
 			} else {
-				g_string_append_len (out, text, n);
+				g_string_append_len (out, word, n);
 			}
 			
 			encoded = FALSE;
diff --git a/tests/test-mime.c b/tests/test-mime.c
index 5e94a0e..efff07e 100644
--- a/tests/test-mime.c
+++ b/tests/test-mime.c
@@ -200,8 +200,7 @@ static struct {
 } broken_addrspec[] = {
 	{ "\"Biznes=?ISO-8859-2?Q?_?=INTERIA.PL\"=?ISO-8859-2?Q?_?=<biuletyny firma interia pl>",
 	  "\"Biznes INTERIA.PL \" <biuletyny firma interia pl>",
-	  "\"Biznes INTERIA.PL\" <biuletyny firma interia pl>",
-	},
+	  "\"Biznes INTERIA.PL\" <biuletyny firma interia pl>", },
 };
 
 static void



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