[evolution] eds-I#3 - [GPG] Mails that are not encrypted look encrypted
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] eds-I#3 - [GPG] Mails that are not encrypted look encrypted
- Date: Thu, 28 Jun 2018 16:50:48 +0000 (UTC)
commit f66cd3e1db301d264563b4222a3574e2e58e2b85
Author: Milan Crha <mcrha redhat com>
Date: Thu Jun 28 18:51:40 2018 +0200
eds-I#3 - [GPG] Mails that are not encrypted look encrypted
Related to https://gitlab.gnome.org/GNOME/evolution-data-server/issues/3
src/em-format/e-mail-formatter-utils.c | 133 ++++++++++++++++------
src/em-format/e-mail-parser-application-smime.c | 5 +
src/em-format/e-mail-parser-inlinepgp-encrypted.c | 5 +
src/em-format/e-mail-parser-inlinepgp-signed.c | 5 +
src/em-format/e-mail-parser-multipart-encrypted.c | 5 +
src/em-format/e-mail-parser-multipart-signed.c | 5 +
src/em-format/e-mail-part.c | 9 ++
7 files changed, 133 insertions(+), 34 deletions(-)
---
diff --git a/src/em-format/e-mail-formatter-utils.c b/src/em-format/e-mail-formatter-utils.c
index 1c4c76595b..1113f9a2ba 100644
--- a/src/em-format/e-mail-formatter-utils.c
+++ b/src/em-format/e-mail-formatter-utils.c
@@ -554,71 +554,136 @@ e_mail_formatter_format_security_header (EMailFormatter *formatter,
EMailPart *part,
guint32 flags)
{
- const gchar* part_id;
- gchar* part_id_prefix;
- GString* tmp;
+ struct _validity_flags {
+ guint32 flags;
+ const gchar *description_complete;
+ const gchar *description_partial;
+ } validity_flags[] = {
+ { E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_SIGNED, N_("GPG signed"), N_("partially GPG
signed") },
+ { E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_ENCRYPTED, N_("GPG encrypted"),
N_("partially GPG encrypted") },
+ { E_MAIL_PART_VALIDITY_SMIME | E_MAIL_PART_VALIDITY_SIGNED, N_("S/MIME signed"),
N_("partially S/MIME signed") },
+ { E_MAIL_PART_VALIDITY_SMIME | E_MAIL_PART_VALIDITY_ENCRYPTED, N_("S/MIME encrypted"),
N_("partially S/MIME encrypted") }
+ };
+ const gchar *part_id;
+ gchar *part_id_prefix;
GQueue queue = G_QUEUE_INIT;
GList *head, *link;
+ guint32 check_valid_flags = 0;
+ gint part_id_prefix_len;
+ gboolean is_partial = FALSE;
+ guint ii;
g_return_if_fail (E_IS_MAIL_PART_HEADERS (part));
/* Get prefix of this PURI */
part_id = e_mail_part_get_id (part);
part_id_prefix = g_strndup (part_id, g_strrstr (part_id, ".") - part_id);
-
- /* Add encryption/signature header */
- tmp = g_string_new ("");
+ part_id_prefix_len = strlen (part_id_prefix);
e_mail_part_list_queue_parts (context->part_list, NULL, &queue);
head = g_queue_peek_head_link (&queue);
- /* Find first secured part. */
- for (link = head; link != NULL; link = g_list_next(link)) {
+ /* Ignore the main message, the headers and the end parts */
+ #define should_skip_part(_id) \
+ (g_strcmp0 (_id, part_id_prefix) == 0 || \
+ (_id && g_str_has_suffix (_id, ".rfc822.end")) || \
+ (_id && strlen (_id) == part_id_prefix_len + 8 /* strlen (".headers") */ && \
+ g_strcmp0 (_id + part_id_prefix_len, ".headers") == 0))
+
+ /* Check parts for this ID. */
+ for (link = head; link != NULL; link = g_list_next (link)) {
EMailPart *mail_part = link->data;
+ const gchar *id = e_mail_part_get_id (mail_part);
- if (!e_mail_part_has_validity (mail_part))
+ if (!e_mail_part_id_has_prefix (mail_part, part_id_prefix))
continue;
- if (!e_mail_part_id_has_prefix (mail_part, part_id_prefix))
+ if (should_skip_part (id))
continue;
- if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_PGP |
E_MAIL_PART_VALIDITY_SIGNED)) {
- g_string_append (tmp, _("GPG signed"));
+ if (!e_mail_part_has_validity (mail_part)) {
+ /* A part without validity, thus it's partially signed/encrypted */
+ is_partial = TRUE;
+ } else {
+ guint32 validies = 0;
+ for (ii = 0; ii < G_N_ELEMENTS (validity_flags); ii++) {
+ if (e_mail_part_get_validity (mail_part, validity_flags[ii].flags))
+ validies |= validity_flags[ii].flags;
+ }
+ check_valid_flags |= validies;
}
- if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_PGP |
E_MAIL_PART_VALIDITY_ENCRYPTED)) {
- if (tmp->len > 0)
- g_string_append (tmp, ", ");
- g_string_append (tmp, _("GPG encrypted"));
- }
+ /* Do not traverse sub-messages */
+ if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822") &&
+ !g_str_equal (e_mail_part_get_id (mail_part), part_id_prefix))
+ link = e_mail_formatter_find_rfc822_end_iter (link);
+ }
+
+ if (check_valid_flags) {
+ GString *tmp;
+
+ if (!is_partial) {
+ for (link = head; link != NULL && !is_partial; link = g_list_next (link)) {
+ EMailPart *mail_part = link->data;
+ const gchar *id = e_mail_part_get_id (mail_part);
- if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_SMIME |
E_MAIL_PART_VALIDITY_SIGNED)) {
- if (tmp->len > 0)
- g_string_append (tmp, ", ");
- g_string_append (tmp, _("S/MIME signed"));
+ if (!e_mail_part_id_has_prefix (mail_part, part_id_prefix))
+ continue;
+
+ if (should_skip_part (id))
+ continue;
+
+ if (!e_mail_part_has_validity (mail_part)) {
+ /* A part without validity, thus it's partially signed/encrypted */
+ is_partial = TRUE;
+ break;
+ }
+
+ is_partial = !e_mail_part_get_validity (mail_part, check_valid_flags);
+
+ /* Do not traverse sub-messages */
+ if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822") &&
+ !g_str_equal (e_mail_part_get_id (mail_part), part_id_prefix))
+ link = e_mail_formatter_find_rfc822_end_iter (link);
+ }
}
- if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_SMIME |
E_MAIL_PART_VALIDITY_ENCRYPTED)) {
- if (tmp->len > 0)
- g_string_append (tmp, ", ");
- g_string_append (tmp, _("S/MIME encrypted"));
+ /* Add encryption/signature header */
+ tmp = g_string_new ("");
+
+ for (link = head; link; link = g_list_next (link)) {
+ EMailPart *mail_part = link->data;
+ const gchar *id = e_mail_part_get_id (mail_part);
+
+ if (!e_mail_part_has_validity (mail_part) ||
+ !e_mail_part_id_has_prefix (mail_part, part_id_prefix))
+ continue;
+
+ if (should_skip_part (id))
+ continue;
+
+ for (ii = 0; ii < G_N_ELEMENTS (validity_flags); ii++) {
+ if (e_mail_part_get_validity (mail_part, validity_flags[ii].flags)) {
+ if (tmp->len > 0)
+ g_string_append (tmp, ", ");
+ g_string_append (tmp, is_partial ?
_(validity_flags[ii].description_partial) : _(validity_flags[ii].description_complete));
+ }
+ }
+
+ break;
}
- break;
- }
+ if (tmp->len > 0)
+ e_mail_formatter_format_header (formatter, buffer, _("Security"), tmp->str, flags,
"UTF-8");
- if (tmp->len > 0) {
- e_mail_formatter_format_header (
- formatter, buffer,
- _("Security"), tmp->str,
- flags,
- "UTF-8");
+ g_string_free (tmp, TRUE);
}
+ #undef should_skip_part
+
while (!g_queue_is_empty (&queue))
g_object_unref (g_queue_pop_head (&queue));
- g_string_free (tmp, TRUE);
g_free (part_id_prefix);
}
diff --git a/src/em-format/e-mail-parser-application-smime.c b/src/em-format/e-mail-parser-application-smime.c
index d4b52bd3e6..c3f6a2f8d0 100644
--- a/src/em-format/e-mail-parser-application-smime.c
+++ b/src/em-format/e-mail-parser-application-smime.c
@@ -22,6 +22,7 @@
#include <e-util/e-util.h>
+#include "e-mail-formatter-utils.h"
#include "e-mail-parser-extension.h"
#include "e-mail-part-utils.h"
@@ -104,6 +105,10 @@ empe_app_smime_parse (EMailParserExtension *extension,
mail_part, valid,
E_MAIL_PART_VALIDITY_ENCRYPTED |
E_MAIL_PART_VALIDITY_SMIME);
+
+ /* Do not traverse sub-messages */
+ if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
+ link = e_mail_formatter_find_rfc822_end_iter (link);
}
e_queue_transfer (&work_queue, out_mail_parts);
diff --git a/src/em-format/e-mail-parser-inlinepgp-encrypted.c
b/src/em-format/e-mail-parser-inlinepgp-encrypted.c
index c66195cece..e342825651 100644
--- a/src/em-format/e-mail-parser-inlinepgp-encrypted.c
+++ b/src/em-format/e-mail-parser-inlinepgp-encrypted.c
@@ -22,6 +22,7 @@
#include <e-util/e-util.h>
+#include "e-mail-formatter-utils.h"
#include "e-mail-parser-extension.h"
#include "e-mail-part-utils.h"
@@ -135,6 +136,10 @@ empe_inlinepgp_encrypted_parse (EMailParserExtension *extension,
mail_part, valid,
E_MAIL_PART_VALIDITY_ENCRYPTED |
E_MAIL_PART_VALIDITY_PGP);
+
+ /* Do not traverse sub-messages */
+ if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
+ link = e_mail_formatter_find_rfc822_end_iter (link);
}
e_queue_transfer (&work_queue, out_mail_parts);
diff --git a/src/em-format/e-mail-parser-inlinepgp-signed.c b/src/em-format/e-mail-parser-inlinepgp-signed.c
index 2ac8c3a910..3235a1cf66 100644
--- a/src/em-format/e-mail-parser-inlinepgp-signed.c
+++ b/src/em-format/e-mail-parser-inlinepgp-signed.c
@@ -22,6 +22,7 @@
#include <e-util/e-util.h>
+#include "e-mail-formatter-utils.h"
#include "e-mail-parser-extension.h"
#include "e-mail-part-utils.h"
@@ -142,6 +143,10 @@ empe_inlinepgp_signed_parse (EMailParserExtension *extension,
mail_part, valid,
E_MAIL_PART_VALIDITY_SIGNED |
E_MAIL_PART_VALIDITY_PGP);
+
+ /* Do not traverse sub-messages */
+ if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
+ link = e_mail_formatter_find_rfc822_end_iter (link);
}
e_queue_transfer (&work_queue, out_mail_parts);
diff --git a/src/em-format/e-mail-parser-multipart-encrypted.c
b/src/em-format/e-mail-parser-multipart-encrypted.c
index ee25863bc8..7faf4ab1ab 100644
--- a/src/em-format/e-mail-parser-multipart-encrypted.c
+++ b/src/em-format/e-mail-parser-multipart-encrypted.c
@@ -21,6 +21,7 @@
#include <libedataserver/libedataserver.h>
+#include "e-mail-formatter-utils.h"
#include "e-mail-parser-extension.h"
#include "e-mail-part-utils.h"
@@ -126,6 +127,10 @@ empe_mp_encrypted_parse (EMailParserExtension *extension,
mail_part, valid,
E_MAIL_PART_VALIDITY_ENCRYPTED |
E_MAIL_PART_VALIDITY_PGP);
+
+ /* Do not traverse sub-messages */
+ if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
+ link = e_mail_formatter_find_rfc822_end_iter (link);
}
e_queue_transfer (&work_queue, out_mail_parts);
diff --git a/src/em-format/e-mail-parser-multipart-signed.c b/src/em-format/e-mail-parser-multipart-signed.c
index a76ca619d7..ca0133a00d 100644
--- a/src/em-format/e-mail-parser-multipart-signed.c
+++ b/src/em-format/e-mail-parser-multipart-signed.c
@@ -21,6 +21,7 @@
#include <libedataserver/libedataserver.h>
+#include "e-mail-formatter-utils.h"
#include "e-mail-parser-extension.h"
#include "e-mail-part-utils.h"
@@ -170,6 +171,10 @@ empe_mp_signed_parse (EMailParserExtension *extension,
e_mail_part_update_validity (
mail_part, valid,
validity_type | E_MAIL_PART_VALIDITY_SIGNED);
+
+ /* Do not traverse sub-messages */
+ if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
+ link = e_mail_formatter_find_rfc822_end_iter (link);
}
e_queue_transfer (&work_queue, out_mail_parts);
diff --git a/src/em-format/e-mail-part.c b/src/em-format/e-mail-part.c
index 135005e3fa..03271ceb2e 100644
--- a/src/em-format/e-mail-part.c
+++ b/src/em-format/e-mail-part.c
@@ -662,6 +662,15 @@ e_mail_part_update_validity (EMailPart *part,
mask = E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_SMIME;
+ /* Auto-add flags when the related part is present */
+ if (!(validity_type & E_MAIL_PART_VALIDITY_SIGNED) &&
+ validity->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)
+ validity_type |= E_MAIL_PART_VALIDITY_SIGNED;
+
+ if (!(validity_type & E_MAIL_PART_VALIDITY_ENCRYPTED) &&
+ validity->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE)
+ validity_type |= E_MAIL_PART_VALIDITY_ENCRYPTED;
+
pair = mail_part_find_validity_pair (part, validity_type & mask);
if (pair != NULL) {
pair->validity_type |= validity_type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]