[evolution/gnome-3-6] Bug #691732 - multipart/related hides attachments



commit 8850b60bb9ee8e79920c5043cad05d347c30169d
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 17 20:07:41 2013 +0100

    Bug #691732 - multipart/related hides attachments

 em-format/e-mail-parser-multipart-related.c |   27 +++++++++++++++++++++++++-
 em-format/e-mail-part-utils.c               |   28 +++++++++++++++++++++++++++
 em-format/e-mail-part-utils.h               |    2 +
 3 files changed, 56 insertions(+), 1 deletions(-)
---
diff --git a/em-format/e-mail-parser-multipart-related.c b/em-format/e-mail-parser-multipart-related.c
index e72b61e..491e126 100644
--- a/em-format/e-mail-parser-multipart-related.c
+++ b/em-format/e-mail-parser-multipart-related.c
@@ -66,6 +66,8 @@ empe_mp_related_parse (EMailParserExtension *extension,
 {
 	CamelMultipart *mp;
 	CamelMimePart *body_part, *display_part = NULL;
+	CamelContentType *display_content_type;
+	gchar *html_body = NULL;
 	gint i, nparts, partidlen, displayid = 0;
 	GSList *parts;
 
@@ -88,6 +90,27 @@ empe_mp_related_parse (EMailParserExtension *extension,
 				cancellable);
 	}
 
+	display_content_type = camel_mime_part_get_content_type (display_part);
+	if (display_content_type &&
+	    camel_content_type_is (display_content_type, "text", "html")) {
+		CamelDataWrapper *dw;
+
+		dw = camel_medium_get_content ((CamelMedium *) display_part);
+		if (dw) {
+			CamelStream *mem = camel_stream_mem_new ();
+			GByteArray *bytes;
+
+			camel_data_wrapper_decode_to_stream_sync (dw, mem, cancellable, NULL);
+			camel_stream_close (mem, cancellable, NULL);
+
+			bytes = camel_stream_mem_get_byte_array	(CAMEL_STREAM_MEM (mem));
+			if (bytes && bytes->len)
+				html_body = g_strndup ((const gchar *) bytes->data, bytes->len);
+
+			g_object_unref (mem);
+		}
+	}
+
 	/* The to-be-displayed part goes first */
 	partidlen = part_id->len;
 	g_string_append_printf (part_id, ".related.%d", displayid);
@@ -122,13 +145,15 @@ empe_mp_related_parse (EMailParserExtension *extension,
 				continue;
 
 			/* Don't render the part on it's own! */
-			if (mail_part->cid != NULL)
+			if (e_mail_part_utils_body_refers (html_body, mail_part->cid))
 				mail_part->is_hidden = TRUE;
 		}
 
 		parts = g_slist_concat (parts, list);
 	}
 
+	g_free (html_body);
+
 	return parts;
 }
 
diff --git a/em-format/e-mail-part-utils.c b/em-format/e-mail-part-utils.c
index b1c514d..97f539a 100644
--- a/em-format/e-mail-part-utils.c
+++ b/em-format/e-mail-part-utils.c
@@ -551,3 +551,31 @@ e_mail_part_is_inline (CamelMimePart *mime_part,
 	return (e_mail_parser_extension_get_flags (extension) &
 			E_MAIL_PARSER_EXTENSION_INLINE) != 0;
 }
+
+/**
+ * e_mail_part_utils_body_refers:
+ * @body: text body to search for references in; can be %NULL, then returns %FALSE
+ * @cid: a Content-ID to search for; if found in body, it should be of form "cid:xxxxx"; can be %NULL
+ *
+ * Returns whether @body contains a reference to @cid enclosed in quotes;
+ *    returns %FALSE if any of the arguments is %NULL.
+ **/
+gboolean
+e_mail_part_utils_body_refers (const gchar *body,
+			       const gchar *cid)
+{
+	const gchar *ptr;
+
+	if (!body || !cid || !*cid)
+		return FALSE;
+
+	ptr = body;
+	while (ptr = strstr (ptr, cid), ptr != NULL) {
+		if (ptr - body > 1 && ptr[-1] == '\"' && ptr[strlen (cid)] == '\"')
+			return TRUE;
+
+		ptr++;
+	}
+
+	return FALSE;
+}
diff --git a/em-format/e-mail-part-utils.h b/em-format/e-mail-part-utils.h
index 97c483d..54d98e2 100644
--- a/em-format/e-mail-part-utils.h
+++ b/em-format/e-mail-part-utils.h
@@ -53,6 +53,8 @@ gchar *		e_mail_part_describe		(CamelMimePart *part,
 gboolean	e_mail_part_is_inline		(CamelMimePart *part,
 						 GQueue *extensions);
 
+gboolean	e_mail_part_utils_body_refers	(const gchar *body,
+						 const gchar *cid);
 G_END_DECLS
 
 #endif /* E_MAIL_PART_UTILS_H_ */



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