[gmime] Fixed broken header text/phrase decoding



commit fe6d243a20a097f9773a1e0af5c7571f168e7e55
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Fri Sep 17 11:43:40 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 2ca4b47..3a31901 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 51ba01f..2dac633 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -1897,7 +1897,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;
 					}
 					
@@ -1985,7 +1987,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;
@@ -2003,7 +2005,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
@@ -2030,7 +2032,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;
 					}
 					
@@ -2047,9 +2049,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)
@@ -2078,15 +2081,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]