Filewatcher File Search
FTP Search
  
Directory (beta)
  
Content Search (beta)
   
pkg://evolution-1.2.2-5.src.rpm:13950729/evolution-1.2.2-safer-contentid-parse.patch  info  downloads

2003-03-13  Jeffrey Stedfast  <fejj@ximian.com>

	* camel-mime-part.c (process_header): Use
	header_contentid_decode() as this new function should be safer
	than the hack that we had before.

	* camel-mime-utils.c (header_contentid_decode): New function to
	try and parse a content-id string in such a way as to work around
	some of the known bugs in other MIME implementations. Try to be as
	"safe" as we can - ie. don't allow for more than 1 @ (since the
	mailer uses "@@@%d" as a fake content-id value for parts without
	content-ids) and don't allow for invalid content-type chars.

Index: camel-mime-part.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-part.c,v
retrieving revision 1.145
diff -u -r1.145 camel-mime-part.c
--- camel/camel-mime-part.c	6 Mar 2003 15:15:41 -0000	1.145
+++ camel/camel-mime-part.c	13 Mar 2003 23:55:46 -0000
@@ -234,21 +234,7 @@
 		break;
 	case HEADER_CONTENT_ID:
 		g_free (mime_part->content_id);
-		if (!(mime_part->content_id = header_msgid_decode (header_value))) {
-			while (*header_value && strchr (" \t\r\n", *header_value))
-				header_value++;
-			if (*header_value == '<') {
-				p = header_value;
-				while (*p && *p != '>')
-					p++;
-				mime_part->content_id = g_strndup (header_value, p - header_value);
-			} else if (*header_value) {
-				mime_part->content_id = g_strdup (header_value);
-			}
-			
-			if (mime_part->content_id)
-				g_strstrip (mime_part->content_id);
-		}
+		mime_part->content_id = header_contentid_decode (header_value);
 		break;
 	case HEADER_ENCODING:
 		text = header_token_decode (header_value);
Index: camel-mime-utils.h
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.h,v
retrieving revision 1.40
diff -u -r1.40 camel-mime-utils.h
--- camel/camel-mime-utils.h	8 Apr 2002 17:34:12 -0000	1.40
+++ camel/camel-mime-utils.h	13 Mar 2003 23:55:47 -0000
@@ -184,6 +184,7 @@
 
 /* decode a message id */
 char *header_msgid_decode (const char *in);
+char *header_contentid_decode (const char *in);
 
 /* generate msg id */
 char *header_msgid_generate (void);
Index: camel-mime-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-utils.c,v
retrieving revision 1.178
diff -u -r1.178 camel-mime-utils.c
--- camel/camel-mime-utils.c	25 Feb 2003 19:43:22 -0000	1.178
+++ camel/camel-mime-utils.c	13 Mar 2003 23:55:49 -0000
@@ -2629,6 +2629,73 @@
 	return header_msgid_decode_internal(&in);
 }
 
+char *
+header_contentid_decode (const char *in)
+{
+	const char *inptr = in;
+	gboolean at = FALSE;
+	GString *addr;
+	char *buf;
+	
+	d(printf("decoding Content-ID: '%s'\n", in));
+	
+	header_decode_lwsp (&inptr);
+	
+	/* some lame mailers quote the Content-Id */
+	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 = header_msgid_decode (inptr)) != NULL && *buf)
+		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 == '<') {
+		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;
+}
+
 void
 header_references_list_append_asis(struct _header_references **list, char *ref)
 {
Results 1 - 1
Help - FTP Sites List - Software Dir.
Searching half a billion files worldwide
© 1997-2008 Oliver Maruhn