[Evolution-hackers] workaround for multipart/alternative



Hi all,

I propose the following patch for dealing with non-alternative
multipart/alternative's:

If there are alternative text/plain parts, assume the sender is broken
and use the *first* of those (after all, if you wanted to maximally
violate RFC 2046 thats where you would hide the information).

For me this fixes some Eudora-written emails.

This patch also fixes a memory leak if want_plain==TRUE in
find_preferred_alternative(), so even if you dislike the workaround you
might want to fix that.

Best regards,
Volker

--- mail/mail-format.c.old	2003-04-28 16:09:48.000000000 +0200
+++ mail/mail-format.c	2003-04-28 16:24:49.000000000 +0200
@@ -1620,6 +1620,11 @@
 	int i, nparts;
 	CamelMimePart *preferred_part = NULL;
 	MailMimeHandler *handler;
+
+        /* workaround for broken senders: if there are alternative 
+           text/plain parts (wtf is that?), display the first one of those */
+	gboolean broken_sender = FALSE;
+	CamelMimePart *first_text_plain_part = NULL;
 	
 	nparts = camel_multipart_get_number (multipart);
 	for (i = 0; i < nparts; i++) {
@@ -1628,15 +1633,25 @@
 		char *mime_type = header_content_type_simple (type);
 		
 		camel_strdown (mime_type);
-		if (want_plain && !strcmp (mime_type, "text/plain"))
-			return part;
+		if (0 == strcmp (mime_type, "text/plain")) {
+			if (!first_text_plain_part) 
+				first_text_plain_part = part;
+			else /* workaround */
+				broken_sender = TRUE;
+			if (want_plain)
+				preferred_part = part;
+		}
 		handler = mail_lookup_handler (mime_type);
-		if (handler && (!preferred_part || !handler->generic))
+		if (handler && (!preferred_part || !handler->generic) 
+		            && !want_plain)
 			preferred_part = part;
 		g_free (mime_type);
 	}
 	
-	return preferred_part;
+	if (broken_sender)
+		return first_text_plain_part;
+	else 
+		return preferred_part;
 }
 
 static gboolean


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