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



commit 37699de983b6085e5be6a92eafbee07bdcc70854
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 17 20:07:03 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 f58a5a0..a1cbbf7 100644
--- a/em-format/e-mail-parser-multipart-related.c
+++ b/em-format/e-mail-parser-multipart-related.c
@@ -52,6 +52,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;
 
 	mp = (CamelMultipart *) camel_medium_get_content ((CamelMedium *) part);
@@ -69,6 +71,27 @@ empe_mp_related_parse (EMailParserExtension *extension,
 			parser, part, part_id, "multipart/mixed",
 			cancellable, out_mail_parts);
 
+	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);
@@ -103,13 +126,15 @@ empe_mp_related_parse (EMailParserExtension *extension,
 			EMailPart *mail_part = link->data;
 
 			/* 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;
 		}
 
 		e_queue_transfer (&work_queue, out_mail_parts);
 	}
 
+	g_free (html_body);
+
 	return TRUE;
 }
 
diff --git a/em-format/e-mail-part-utils.c b/em-format/e-mail-part-utils.c
index 2e2b5f6..4fa7a85 100644
--- a/em-format/e-mail-part-utils.c
+++ b/em-format/e-mail-part-utils.c
@@ -552,3 +552,31 @@ e_mail_part_is_inline (CamelMimePart *mime_part,
 	/* Otherwise, use the default for this handler type. */
 	return (class->flags & 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]