Re: [evolution-patches] fix for bug #62771 (User-Agent doesn't get decoded in mail view)




Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.2237
diff -u -r1.2237 ChangeLog
--- ChangeLog	6 Aug 2004 19:24:03 -0000	1.2237
+++ ChangeLog	11 Aug 2004 16:45:26 -0000
@@ -1,3 +1,15 @@
+2004-08-11  Jeffrey Stedfast  <fejj novell com>
+
+	Fix for bug #62771
+
+	* camel-mime-utils.c (string_append_quoted_pair): New function to
+	append a string of text that may contain quoted-pairs.
+	(header_decode_text): Now takes a ctext argument specifying
+	whether or not to expect comments and to handle them.
+	(camel_header_decode_string): Pass FALSE as ctext argument.
+	(camel_header_format_ctext): New function to format text|comment
+	header field bodies.
+
 2004-08-06  Jeffrey Stedfast  <fejj novell com>
 
 	* providers/imap4/camel-imap4-summary.c (untagged_fetch_all): Call
Index: camel-mime-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.c,v
retrieving revision 1.212
diff -u -r1.212 camel-mime-utils.c
--- camel-mime-utils.c	30 Jul 2004 15:30:38 -0000	1.212
+++ camel-mime-utils.c	11 Aug 2004 16:45:26 -0000
@@ -1118,39 +1118,71 @@
 	
 }
 
+static void
+string_append_quoted_pair (GString *str, const char *in, int inlen)

God, where did you pull the name of this out of?  How about something a bit more sane.

append_quoted would match other functions in the file (append_latin1, etc).

+{
+	register const char *inptr = in;
+	const char *inend = in + inlen;
+	const char *start;
+	
+	while (inptr < inend) {
+		start = inptr;
+		while (inptr < inend && *inptr != '\\')
+			inptr++;
You have loops like this occasionally, much better to use memchr for this.

+		g_string_append_len (str, start, inptr - start);
+		inptr++;
+		
+		if (inptr < inend)
+			g_string_append_c (str, *inptr++);
+	}
+}

but, its still simpler just to do it char by char.

while (inptr < inend) {
    c = *inptr++;
    if (c == '\' && inptr<inend)
      g_string_append_c(str, *inptr++);
    else
    g_string_append_c(str, c);
}


 /* decodes a simple text, rfc822 + rfc2047 */
 static char *
-header_decode_text (const char *in, size_t inlen, const char *default_charset)
+header_decode_text (const char *in, size_t inlen, int ctext, const char *default_charset)
 {
 	GString *out;
 	const char *inptr, *inend, *start, *chunk, *locale_charset;
 	char *dword = NULL;
+	guint32 mask;
 	
 	locale_charset = e_iconv_locale_charset ();
 	
+	if (ctext)
+		mask = (CAMEL_MIME_IS_SPECIAL | CAMEL_MIME_IS_SPACE | CAMEL_MIME_IS_CTRL);
+	else
+		mask = (CAMEL_MIME_IS_LWSP);
+	
 	out = g_string_new ("");
 	inptr = in;
 	inend = inptr + inlen;
 	chunk = NULL;
-
+	

Oi, stop adding tabs to the files!

 	while (inptr < inend) {
 		start = inptr;
-		while (inptr < inend && camel_mime_is_lwsp(*inptr))
+		while (inptr < inend && camel_mime_is_type (*inptr, mask))
 			inptr++;
-
+		
 		if (inptr == inend) {
-			g_string_append_len(out, start, inptr-start);
+			if (ctext)
+				string_append_quoted_pair (out, start, inptr - start);
+			else
+				g_string_append_len (out, start, inptr - start);

If would be easier and more readable to use a function pointer here.

i.e. outside the loop:
void (*append)(GString *, const char *, int);

if (ctext)
    append = append_quoted;
else
    append = g_string_append_len;

inside the loop:

append(out, start, inptr-start);


 			break;
 		} else if (dword == NULL) {
-			g_string_append_len(out, start, inptr-start);
+			if (ctext)
+				string_append_quoted_pair (out, start, inptr - start);
+			else
+				g_string_append_len (out, start, inptr - start);
 		} else {
 			chunk = start;
 		}
-
+		
 		start = inptr;
-		while (inptr < inend && !camel_mime_is_lwsp(*inptr))
+		while (inptr < inend && !camel_mime_is_type (*inptr, mask))
 			inptr++;
-
+		
 		dword = rfc2047_decode_word(start, inptr-start);
 		if (dword) {
 			g_string_append(out, dword);
@@ -1178,7 +1210,15 @@
 {
 	if (in == NULL)
 		return NULL;
-	return header_decode_text (in, strlen (in), default_charset);
+	return header_decode_text (in, strlen (in), FALSE, default_charset);
+}
+
+char *
+camel_header_format_ctext (const char *in, const char *default_charset)
+{
+	if (in == NULL)
+		return NULL;
+	return header_decode_text (in, strlen (in), TRUE, default_charset);
 }
 
 /* how long a sequence of pre-encoded words should be less than, to attempt to 
@@ -2830,7 +2870,7 @@
 	node->next = NULL;
 	node->name = name;
 	if (strncmp(value, "=?", 2) == 0
-	    && (node->value = header_decode_text(value, strlen(value), NULL))) {
+	    && (node->value = header_decode_text(value, strlen(value), FALSE, NULL))) {
 		g_free(value);
 	} else if (!g_utf8_validate(value, -1, NULL)) {
 		const char * charset = e_iconv_locale_charset();
Index: camel-mime-utils.h
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.h,v
retrieving revision 1.56
diff -u -r1.56 camel-mime-utils.h
--- camel-mime-utils.h	18 Jun 2004 20:07:09 -0000	1.56
+++ camel-mime-utils.h	11 Aug 2004 16:45:26 -0000
@@ -194,6 +194,9 @@
 char *camel_header_decode_string (const char *in, const char *default_charset);
 char *camel_header_encode_string (const unsigned char *in);
 
+/* decode (text | comment) - a one-way op */
+char *camel_header_format_ctext (const char *in, const char *default_charset);
+
 /* encode a phrase, like the real name of an address */
 char *camel_header_encode_phrase (const unsigned char *in);
 

And yeah, it doesn't handled nested comments and only escaping inside comments.

But i think enough time has been wasted on this pretty pointless bug already.

(quite frankly, who gives a flying about what mailer someone used).
--
Michael Zucchi <notzed ximian com>
"born to die, live to work, it's all downhill from here"
Novell's Evolution and Free Software Developer


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