Commit f66cd3e1 authored by Milan Crha's avatar Milan Crha
Browse files

eds-I#3 - [GPG] Mails that are not encrypted look encrypted

Related to evolution-data-server#3
parent d25bc841
......@@ -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);
}
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
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