[evolution] Bug 791044 - Do not print HTML attachments created by Prefer Plain plugin
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 791044 - Do not print HTML attachments created by Prefer Plain plugin
- Date: Tue, 26 Feb 2019 11:59:37 +0000 (UTC)
commit bfa7a389791381e5bd0c98fb2da5416c2a319624
Author: Milan Crha <mcrha redhat com>
Date: Tue Feb 26 12:58:22 2019 +0100
Bug 791044 - Do not print HTML attachments created by Prefer Plain plugin
Closes https://bugzilla.gnome.org/show_bug.cgi?id=791044
src/em-format/e-mail-formatter-print-headers.c | 3 +-
src/em-format/e-mail-formatter-print.c | 3 ++
src/em-format/e-mail-formatter.c | 4 ++
src/em-format/e-mail-parser.c | 10 +++--
src/em-format/e-mail-part.c | 49 ++++++++++++++++++++++
src/em-format/e-mail-part.h | 3 ++
.../prefer-plain/e-mail-parser-prefer-plain.c | 30 ++++++++++++-
7 files changed, 95 insertions(+), 7 deletions(-)
---
diff --git a/src/em-format/e-mail-formatter-print-headers.c b/src/em-format/e-mail-formatter-print-headers.c
index a7e8eb2000..e35224aa06 100644
--- a/src/em-format/e-mail-formatter-print-headers.c
+++ b/src/em-format/e-mail-formatter-print-headers.c
@@ -137,7 +137,8 @@ emfpe_headers_format (EMailFormatterExtension *extension,
if (!e_mail_part_get_is_attachment (mail_part))
continue;
- if (mail_part->is_hidden)
+ if (mail_part->is_hidden ||
+ !e_mail_part_get_is_printable (mail_part))
continue;
if (e_mail_part_get_cid (mail_part) != NULL)
diff --git a/src/em-format/e-mail-formatter-print.c b/src/em-format/e-mail-formatter-print.c
index ed7ae8f074..1f6cff2721 100644
--- a/src/em-format/e-mail-formatter-print.c
+++ b/src/em-format/e-mail-formatter-print.c
@@ -146,6 +146,9 @@ mail_formatter_print_run (EMailFormatter *formatter,
continue;
}
+ if (!e_mail_part_get_is_printable (part))
+ continue;
+
mime_type = e_mail_part_get_mime_type (part);
if (mime_type == NULL)
continue;
diff --git a/src/em-format/e-mail-formatter.c b/src/em-format/e-mail-formatter.c
index 2d3002098a..ce738a85e2 100644
--- a/src/em-format/e-mail-formatter.c
+++ b/src/em-format/e-mail-formatter.c
@@ -421,6 +421,10 @@ mail_formatter_run (EMailFormatter *formatter,
continue;
}
+ if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING &&
+ !e_mail_part_get_is_printable (part))
+ continue;
+
/* Force formatting as source if needed */
if (context->mode != E_MAIL_FORMATTER_MODE_SOURCE) {
const gchar *mime_type;
diff --git a/src/em-format/e-mail-parser.c b/src/em-format/e-mail-parser.c
index b601600ffa..0af44e6fe8 100644
--- a/src/em-format/e-mail-parser.c
+++ b/src/em-format/e-mail-parser.c
@@ -456,12 +456,13 @@ e_mail_parser_parse_sync (EMailParser *parser,
printf (
" id: %s | cid: %s | mime_type: %s | "
- "is_hidden: %d | is_attachment: %d\n",
+ "is_hidden: %d | is_attachment: %d | is_printable: %d\n",
e_mail_part_get_id (part),
e_mail_part_get_cid (part),
e_mail_part_get_mime_type (part),
part->is_hidden ? 1 : 0,
- e_mail_part_get_is_attachment (part) ? 1 : 0);
+ e_mail_part_get_is_attachment (part) ? 1 : 0,
+ e_mail_part_get_is_printable (part) ? 1 : 0);
g_object_unref (part);
}
@@ -560,12 +561,13 @@ e_mail_parser_parse_finish (EMailParser *parser,
printf (
" id: %s | cid: %s | mime_type: %s | "
- "is_hidden: %d | is_attachment: %d\n",
+ "is_hidden: %d | is_attachment: %d | is_printable: %d\n",
e_mail_part_get_id (part),
e_mail_part_get_cid (part),
e_mail_part_get_mime_type (part),
part->is_hidden ? 1 : 0,
- e_mail_part_get_is_attachment (part) ? 1 : 0);
+ e_mail_part_get_is_attachment (part) ? 1 : 0,
+ e_mail_part_get_is_printable (part) ? 1 : 0);
g_object_unref (part);
}
diff --git a/src/em-format/e-mail-part.c b/src/em-format/e-mail-part.c
index 03271ceb2e..4fccd77168 100644
--- a/src/em-format/e-mail-part.c
+++ b/src/em-format/e-mail-part.c
@@ -48,6 +48,7 @@ struct _EMailPartPrivate {
gchar *mime_type;
gboolean is_attachment;
+ gboolean is_printable;
gboolean converted_to_utf8;
};
@@ -57,6 +58,7 @@ enum {
PROP_CONVERTED_TO_UTF8,
PROP_ID,
PROP_IS_ATTACHMENT,
+ PROP_IS_PRINTABLE,
PROP_MIME_PART,
PROP_MIME_TYPE,
PROP_PART_LIST
@@ -132,6 +134,12 @@ mail_part_set_property (GObject *object,
g_value_get_boolean (value));
return;
+ case PROP_IS_PRINTABLE:
+ e_mail_part_set_is_printable (
+ E_MAIL_PART (object),
+ g_value_get_boolean (value));
+ return;
+
case PROP_MIME_PART:
mail_part_set_mime_part (
E_MAIL_PART (object),
@@ -189,6 +197,13 @@ mail_part_get_property (GObject *object,
E_MAIL_PART (object)));
return;
+ case PROP_IS_PRINTABLE:
+ g_value_set_boolean (
+ value,
+ e_mail_part_get_is_printable (
+ E_MAIL_PART (object)));
+ return;
+
case PROP_MIME_PART:
g_value_take_object (
value,
@@ -315,6 +330,18 @@ e_mail_part_class_init (EMailPartClass *class)
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (
+ object_class,
+ PROP_IS_PRINTABLE,
+ g_param_spec_boolean (
+ "is-printable",
+ "Is Printable",
+ "Whether this part can be printed",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (
object_class,
PROP_MIME_PART,
@@ -581,6 +608,28 @@ e_mail_part_set_is_attachment (EMailPart *part,
g_object_notify (G_OBJECT (part), "is-attachment");
}
+gboolean
+e_mail_part_get_is_printable (EMailPart *part)
+{
+ g_return_val_if_fail (E_IS_MAIL_PART (part), FALSE);
+
+ return part->priv->is_printable;
+}
+
+void
+e_mail_part_set_is_printable (EMailPart *part,
+ gboolean is_printable)
+{
+ g_return_if_fail (E_IS_MAIL_PART (part));
+
+ if ((is_printable ? 1 : 0) == (part->priv->is_printable ? 1 : 0))
+ return;
+
+ part->priv->is_printable = is_printable;
+
+ g_object_notify (G_OBJECT (part), "is-printable");
+}
+
void
e_mail_part_bind_dom_element (EMailPart *part,
EWebView *web_view,
diff --git a/src/em-format/e-mail-part.h b/src/em-format/e-mail-part.h
index 3e3d38a7b6..b872119979 100644
--- a/src/em-format/e-mail-part.h
+++ b/src/em-format/e-mail-part.h
@@ -123,6 +123,9 @@ void e_mail_part_set_part_list (EMailPart *part,
gboolean e_mail_part_get_is_attachment (EMailPart *part);
void e_mail_part_set_is_attachment (EMailPart *part,
gboolean is_attachment);
+gboolean e_mail_part_get_is_printable (EMailPart *part);
+void e_mail_part_set_is_printable (EMailPart *part,
+ gboolean is_printable);
void e_mail_part_bind_dom_element (EMailPart *part,
EWebView *web_view,
guint64 page_id,
diff --git a/src/modules/prefer-plain/e-mail-parser-prefer-plain.c
b/src/modules/prefer-plain/e-mail-parser-prefer-plain.c
index 357473fd0b..bce556235d 100644
--- a/src/modules/prefer-plain/e-mail-parser-prefer-plain.c
+++ b/src/modules/prefer-plain/e-mail-parser-prefer-plain.c
@@ -99,6 +99,19 @@ enum {
PROP_SHOW_SUPPRESSED
};
+static void
+mark_parts_not_printable (GQueue *parts)
+{
+ GList *link;
+
+ for (link = g_queue_peek_head_link (parts); link; link = g_list_next (link)) {
+ EMailPart *part = link->data;
+
+ if (part)
+ e_mail_part_set_is_printable (part, FALSE);
+ }
+}
+
static void
make_part_attachment (EMailParser *parser,
CamelMimePart *part,
@@ -114,8 +127,11 @@ make_part_attachment (EMailParser *parser,
if (camel_content_type_is (ct, "text", "html")) {
GQueue work_queue = G_QUEUE_INIT;
EMailPart *mail_part;
+ gboolean was_attachment;
gint len;
+ was_attachment = e_mail_part_is_attachment (part);
+
/* always show HTML as attachments and not inline */
camel_mime_part_set_disposition (part, "attachment");
@@ -138,6 +154,9 @@ make_part_attachment (EMailParser *parser,
e_mail_parser_wrap_as_attachment (
parser, part, part_id, &work_queue);
+ if (!was_attachment && !force_html)
+ mark_parts_not_printable (&work_queue);
+
e_queue_transfer (&work_queue, out_mail_parts);
} else if (force_html && CAMEL_IS_MIME_MESSAGE (part)) {
@@ -234,7 +253,7 @@ empe_prefer_plain_parse (EMailParserExtension *extension,
* as attachment to not show empty message preview, which
* is confusing. */
make_part_attachment (
- parser, part, part_id, FALSE,
+ parser, part, part_id, TRUE,
cancellable, out_mail_parts);
return TRUE;
@@ -315,9 +334,15 @@ empe_prefer_plain_parse (EMailParserExtension *extension,
if (multipart_has_html && !prefer_html) {
if (emp_pp->show_suppressed) {
+ GQueue suppressed_queue = G_QUEUE_INIT;
+
e_mail_parser_wrap_as_attachment (
parser, sp, part_id,
- &inner_queue);
+ &suppressed_queue);
+
+ mark_parts_not_printable (&suppressed_queue);
+
+ e_queue_transfer (&suppressed_queue, &inner_queue);
} else {
hide_parts (&inner_queue);
}
@@ -358,6 +383,7 @@ empe_prefer_plain_parse (EMailParserExtension *extension,
if (mpart && mpart->is_hidden && g_strcmp0 (mime_type, "text/html") == 0) {
e_mail_part_set_is_attachment (mpart, TRUE);
+ e_mail_part_set_is_printable (mpart, FALSE);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]