[evolution] Bug 795447 - Enigmail GPG encrypted Subject not shown in message list



commit 106cf88cbfab3167ae8b83937307ff80c14036ba
Author: Milan Crha <mcrha redhat com>
Date:   Tue Apr 24 11:56:02 2018 +0200

    Bug 795447 - Enigmail GPG encrypted Subject not shown in message list

 src/composer/e-msg-composer.c                     |    4 +-
 src/em-format/e-mail-parser-application-smime.c   |    4 +-
 src/em-format/e-mail-parser-multipart-encrypted.c |    4 +-
 src/em-format/e-mail-parser-multipart-mixed.c     |   59 +++++++++++++++++++++
 src/em-format/e-mail-parser.c                     |   36 +++++++++++++
 src/em-format/e-mail-parser.h                     |    3 +
 6 files changed, 105 insertions(+), 5 deletions(-)
---
diff --git a/src/composer/e-msg-composer.c b/src/composer/e-msg-composer.c
index dd29675..1c14526 100644
--- a/src/composer/e-msg-composer.c
+++ b/src/composer/e-msg-composer.c
@@ -3146,8 +3146,10 @@ handle_multipart_encrypted (EMsgComposer *composer,
        g_object_unref (cipher);
        g_object_unref (session);
 
-       if (valid == NULL)
+       if (valid == NULL) {
+               g_object_unref (mime_part);
                return;
+       }
 
        camel_cipher_validity_free (valid);
 
diff --git a/src/em-format/e-mail-parser-application-smime.c b/src/em-format/e-mail-parser-application-smime.c
index 87f25b3..d4b52bd 100644
--- a/src/em-format/e-mail-parser-application-smime.c
+++ b/src/em-format/e-mail-parser-application-smime.c
@@ -87,7 +87,7 @@ empe_app_smime_parse (EMailParserExtension *extension,
                GList *head, *link;
                gint len = part_id->len;
 
-               g_string_append (part_id, ".encrypted");
+               g_string_append (part_id, ".encrypted-smime");
 
                e_mail_parser_parse_part (
                        parser, opart, part_id, cancellable, &work_queue);
@@ -114,7 +114,7 @@ empe_app_smime_parse (EMailParserExtension *extension,
                if (!e_mail_part_is_secured (opart)) {
                        EMailPart *mail_part;
 
-                       g_string_append (part_id, ".encrypted.button");
+                       g_string_append (part_id, ".encrypted-smime.button");
 
                        e_mail_parser_parse_part_as (
                                parser, part, part_id,
diff --git a/src/em-format/e-mail-parser-multipart-encrypted.c 
b/src/em-format/e-mail-parser-multipart-encrypted.c
index 2baa98f..ee25863 100644
--- a/src/em-format/e-mail-parser-multipart-encrypted.c
+++ b/src/em-format/e-mail-parser-multipart-encrypted.c
@@ -109,7 +109,7 @@ empe_mp_encrypted_parse (EMailParserExtension *extension,
        }
 
        len = part_id->len;
-       g_string_append (part_id, ".encrypted");
+       g_string_append (part_id, ".encrypted-pgp");
 
        g_warn_if_fail (e_mail_parser_parse_part (
                parser, opart, part_id, cancellable, &work_queue));
@@ -136,7 +136,7 @@ empe_mp_encrypted_parse (EMailParserExtension *extension,
        if (!e_mail_part_is_secured (opart)) {
                EMailPart *mail_part;
 
-               g_string_append (part_id, ".encrypted.button");
+               g_string_append (part_id, ".encrypted-pgp.button");
 
                e_mail_parser_parse_part_as (
                        parser, part, part_id,
diff --git a/src/em-format/e-mail-parser-multipart-mixed.c b/src/em-format/e-mail-parser-multipart-mixed.c
index 4b47d91..55d686c 100644
--- a/src/em-format/e-mail-parser-multipart-mixed.c
+++ b/src/em-format/e-mail-parser-multipart-mixed.c
@@ -41,6 +41,45 @@ static const gchar *parser_mime_types[] = {
        NULL
 };
 
+static void
+empe_mp_mixed_maybe_update_message_info_headers (EMailParser *parser,
+                                                const gchar *part_id,
+                                                const gchar *subject,
+                                                GCancellable *cancellable)
+{
+       EMailPartList *part_list;
+       CamelFolder *folder;
+       const gchar *message_uid;
+
+       g_return_if_fail (E_IS_MAIL_PARSER (parser));
+       g_return_if_fail (part_id != NULL);
+       g_return_if_fail (subject != NULL);
+
+       /* The Subject can be changed only if this is the top message, thus when
+          the encrypted message/part is not an attachment. */
+       if (g_strcmp0 (part_id, ".message.encrypted-pgp") != 0)
+               return;
+
+       part_list = e_mail_parser_ref_part_list_for_operation (parser, cancellable);
+       if (!part_list)
+               return;
+
+       folder = e_mail_part_list_get_folder (part_list);
+       message_uid = e_mail_part_list_get_message_uid (part_list);
+
+       if (CAMEL_IS_FOLDER (folder) && message_uid) {
+               CamelMessageInfo *info;
+
+               info = camel_folder_get_message_info (folder, message_uid);
+               if (info) {
+                       camel_message_info_set_subject (info, subject);
+                       g_clear_object (&info);
+               }
+       }
+
+       g_object_unref (part_list);
+}
+
 static gboolean
 empe_mp_mixed_parse (EMailParserExtension *extension,
                      EMailParser *parser,
@@ -138,6 +177,26 @@ empe_mp_mixed_parse (EMailParserExtension *extension,
                        continue;
                }
 
+               if (i == 0 && g_str_has_suffix (part_id->str, ".encrypted-pgp")) {
+                       ct = camel_mime_part_get_content_type (subpart);
+                       if (ct && camel_content_type_is (ct, "text", "rfc822-headers") &&
+                           camel_content_type_param (ct, "protected-headers")) {
+                               ct = camel_mime_part_get_content_type (part);
+                               if (ct && camel_content_type_param (ct, "protected-headers")) {
+                                       const gchar *subject;
+
+                                       /* The multipart/mixed contains some of the original headers */
+                                       subject = camel_medium_get_header (CAMEL_MEDIUM (part), "Subject");
+                                       if (subject) {
+                                               empe_mp_mixed_maybe_update_message_info_headers (parser, 
part_id->str, subject, cancellable);
+
+                                               /* Skip the text/rfc822-headers part, it's not needed to be 
shown */
+                                               continue;
+                                       }
+                               }
+                       }
+               }
+
                g_string_append_printf (part_id, ".mixed.%d", i);
 
                handled = FALSE;
diff --git a/src/em-format/e-mail-parser.c b/src/em-format/e-mail-parser.c
index 702259a..3cbd90d 100644
--- a/src/em-format/e-mail-parser.c
+++ b/src/em-format/e-mail-parser.c
@@ -42,6 +42,7 @@ struct _EMailParserPrivate {
        gint last_error;
 
        CamelSession *session;
+       GHashTable *ongoing_part_lists; /* GCancellable * ~> EMailPartList * */
 };
 
 enum {
@@ -91,6 +92,15 @@ mail_parser_run (EMailParser *parser,
        GList *iter;
        GString *part_id;
 
+       if (cancellable)
+               g_object_ref (cancellable);
+       else
+               cancellable = g_cancellable_new ();
+
+       g_mutex_lock (&parser->priv->mutex);
+       g_hash_table_insert (parser->priv->ongoing_part_lists, cancellable, part_list);
+       g_mutex_unlock (&parser->priv->mutex);
+
        message = e_mail_part_list_get_message (part_list);
 
        reg = e_mail_parser_get_extension_registry (parser);
@@ -138,6 +148,11 @@ mail_parser_run (EMailParser *parser,
                g_object_unref (mail_part);
        }
 
+       g_mutex_lock (&parser->priv->mutex);
+       g_hash_table_remove (parser->priv->ongoing_part_lists, cancellable);
+       g_mutex_unlock (&parser->priv->mutex);
+
+       g_clear_object (&cancellable);
        g_string_free (part_id, TRUE);
 }
 
@@ -205,6 +220,7 @@ e_mail_parser_finalize (GObject *object)
        priv = E_MAIL_PARSER_GET_PRIVATE (object);
 
        g_clear_object (&priv->session);
+       g_hash_table_destroy (priv->ongoing_part_lists);
        g_mutex_clear (&priv->mutex);
 
        /* Chain up to parent's finalize() method. */
@@ -285,6 +301,7 @@ static void
 e_mail_parser_init (EMailParser *parser)
 {
        parser->priv = E_MAIL_PARSER_GET_PRIVATE (parser);
+       parser->priv->ongoing_part_lists = g_hash_table_new (g_direct_hash, g_direct_equal);
 
        g_mutex_init (&parser->priv->mutex);
 }
@@ -816,6 +833,25 @@ e_mail_parser_get_session (EMailParser *parser)
        return parser->priv->session;
 }
 
+/* The 'operation' is not used as a GCancellable, but as an identificator
+   of an ongoing operation for which the part list is requested. */
+EMailPartList *
+e_mail_parser_ref_part_list_for_operation (EMailParser *parser,
+                                          GCancellable *operation)
+{
+       EMailPartList *part_list;
+
+       g_return_val_if_fail (E_IS_MAIL_PARSER (parser), NULL);
+
+       g_mutex_lock (&parser->priv->mutex);
+       part_list = g_hash_table_lookup (parser->priv->ongoing_part_lists, operation);
+       if (part_list)
+               g_object_ref (part_list);
+       g_mutex_unlock (&parser->priv->mutex);
+
+       return part_list;
+}
+
 EMailExtensionRegistry *
 e_mail_parser_get_extension_registry (EMailParser *parser)
 {
diff --git a/src/em-format/e-mail-parser.h b/src/em-format/e-mail-parser.h
index 9a6ccd3..e104bed 100644
--- a/src/em-format/e-mail-parser.h
+++ b/src/em-format/e-mail-parser.h
@@ -109,6 +109,9 @@ void                e_mail_parser_wrap_as_attachment
                                                 GQueue *parts_queue);
 
 CamelSession * e_mail_parser_get_session       (EMailParser *parser);
+EMailPartList *        e_mail_parser_ref_part_list_for_operation
+                                               (EMailParser *parser,
+                                                GCancellable *operation);
 
 EMailExtensionRegistry *
                e_mail_parser_get_extension_registry


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]