Commit 37699de9 authored by Milan Crha's avatar Milan Crha
Browse files

Bug #691732 - multipart/related hides attachments

parent af24ac86
......@@ -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;
}
......
......@@ -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;
}
......@@ -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_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment