[evolution-patches] content-id decoding patch





The content-id decoding thing is a bit over-anal in ways which is no longer relevent, and also truncates some data.  It works properly with valid data, only the broken cases are broken ...

This simplifies things a little bit, make sure things that start looking like a content-id aren't truncated when they turn out not to be, and hopefully doesn't break anything that worked before.

Of course, like anything trying to work around brokenness, there's no doubt other brokenness which may not be exposed ...

Index: camel/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/ChangeLog,v
retrieving revision 1.2441
diff -u -p -r1.2441 ChangeLog
--- camel/ChangeLog	25 Mar 2005 18:17:16 -0000	1.2441
+++ camel/ChangeLog	12 Apr 2005 03:33:35 -0000
@@ -1,3 +1,9 @@
+2005-04-12  Not Zed  <NotZed Ximian com>
+
+	* camel-mime-utils.c (camel_header_contentid_decode): simplify
+	content-id decoding, catch truncated or badly formatted
+	content-id's better.
+
 2005-03-25  Jeffrey Stedfast  <fejj novell com>
 
 	* camel-mime-utils.c (header_append_param): Don't try to convert
Index: camel/camel-mime-utils.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-mime-utils.c,v
retrieving revision 1.227
diff -u -p -r1.227 camel-mime-utils.c
--- camel/camel-mime-utils.c	25 Mar 2005 18:17:16 -0000	1.227
+++ camel/camel-mime-utils.c	12 Apr 2005 03:33:36 -0000
@@ -2446,67 +2446,49 @@ char *
 camel_header_contentid_decode (const char *in)
 {
 	const char *inptr = in;
-	gboolean at = FALSE;
-	GString *addr;
-	char *buf;
+	char *buf, eol;
 	
 	d(printf("decoding Content-ID: '%s'\n", in));
 	
 	header_decode_lwsp (&inptr);
-	
-	/* some lame mailers quote the Content-Id */
+	in = inptr;
+
+	/* Content-ID should be a message-id, which is <addrspec>, however:
+	   Eudora has been known to use <.@> as a content-id, which parses as ""
+	   Some mailers quote, like "somestring"
+	   Some mailers just use somestring
+	   And probably everything else possible ...
+	   We do:
+	   Try a valid one first, else;
+	   If it starts with ", get the whole quoted string, dropping quotes
+	   If it is starts with < then scan for >
+	   Otherwise get a token surrounded by space.
+	*/
+
 	if (*inptr == '"')
 		inptr++;
 	
-	/* make sure the content-id is not "" which can happen if we get a
-	 * content-id such as <.@> (which Eudora likes to use...) */
-	if ((buf = camel_header_msgid_decode (inptr)) != NULL && *buf)
+	/* we check we didn't truncate the data too */
+	if ((buf = camel_header_msgid_decode (inptr)) != NULL && *buf
+	    && (*inptr == 0 || camel_mime_is_lwsp(*inptr) || *inptr=='"'))
 		return buf;
 	
 	g_free (buf);
 	
-	/* ugh, not a valid msg-id - try to get something useful out of it then? */
 	inptr = in;
-	header_decode_lwsp (&inptr);
-	if (*inptr == '<') {
+	if (*inptr == '"')
+		eol = *inptr++;
+	else if (*inptr == '<') {
+		eol = '>';
 		inptr++;
-		header_decode_lwsp (&inptr);
-	}
-	
-	/* Eudora has been known to use <.@> as a content-id */
-	if (!(buf = header_decode_word (&inptr)) && !strchr (".@", *inptr))
-		return NULL;
-	
-	addr = g_string_new ("");
-	header_decode_lwsp (&inptr);
-	while (buf != NULL || *inptr == '.' || (*inptr == '@' && !at)) {
-		if (buf != NULL) {
-			g_string_append (addr, buf);
-			g_free (buf);
-			buf = NULL;
-		}
-		
-		if (!at) {
-			if (*inptr == '.') {
-				g_string_append_c (addr, *inptr++);
-				buf = header_decode_word (&inptr);
-			} else if (*inptr == '@') {
-				g_string_append_c (addr, *inptr++);
-				buf = header_decode_word (&inptr);
-				at = TRUE;
-			}
-		} else if (strchr (".[]", *inptr)) {
-			g_string_append_c (addr, *inptr++);
-			buf = header_decode_atom (&inptr);
-		}
-		
-		header_decode_lwsp (&inptr);
-	}
-	
-	buf = addr->str;
-	g_string_free (addr, FALSE);
-	
-	return buf;
+	} else
+		eol = 0;
+
+	in = inptr;
+	while (*inptr && *inptr != eol && !camel_mime_is_type(*inptr, CAMEL_MIME_IS_CTRL|CAMEL_MIME_IS_LWSP))
+		inptr++;
+
+	return g_strndup(in, inptr-in);
 }
 
 void


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