[evolution/wip/webkit2] Bug 758856 - [GPG] Option to prefer inline sign/encrypt of pure text/plain mails



commit 777c89da95af6d8bc02bcf2692b602e148a9792c
Author: Milan Crha <mcrha redhat com>
Date:   Wed Dec 2 19:17:45 2015 +0100

    Bug 758856 - [GPG] Option to prefer inline sign/encrypt of pure text/plain mails

 composer/e-msg-composer.c          |   49 +++++++++++++++++++++++++++++------
 mail/e-mail-config-security-page.c |   12 +++++++++
 2 files changed, 52 insertions(+), 9 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index adcefd9..350817b 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -719,6 +719,7 @@ composer_build_message_pgp (AsyncContext *context,
        const gchar *signing_algorithm;
        gboolean always_trust;
        gboolean encrypt_to_self;
+       gboolean prefer_inline;
 
        /* Return silently if we're not signing or encrypting with PGP. */
        if (!context->pgp_sign && !context->pgp_encrypt)
@@ -729,6 +730,7 @@ composer_build_message_pgp (AsyncContext *context,
 
        always_trust = e_source_openpgp_get_always_trust (extension);
        encrypt_to_self = e_source_openpgp_get_encrypt_to_self (extension);
+       prefer_inline = e_source_openpgp_get_prefer_inline (extension);
        pgp_key_id = e_source_openpgp_get_key_id (extension);
        signing_algorithm = e_source_openpgp_get_signing_algorithm (extension);
 
@@ -756,8 +758,8 @@ composer_build_message_pgp (AsyncContext *context,
                npart = camel_mime_part_new ();
 
                cipher = camel_gpg_context_new (context->session);
-               camel_gpg_context_set_always_trust (
-                       CAMEL_GPG_CONTEXT (cipher), always_trust);
+               camel_gpg_context_set_always_trust (CAMEL_GPG_CONTEXT (cipher), always_trust);
+               camel_gpg_context_set_prefer_inline (CAMEL_GPG_CONTEXT (cipher), prefer_inline);
 
                success = camel_cipher_context_sign_sync (
                        cipher, pgp_key_id,
@@ -790,8 +792,8 @@ composer_build_message_pgp (AsyncContext *context,
                                g_strdup (pgp_key_id));
 
                cipher = camel_gpg_context_new (context->session);
-               camel_gpg_context_set_always_trust (
-                       CAMEL_GPG_CONTEXT (cipher), always_trust);
+               camel_gpg_context_set_always_trust (CAMEL_GPG_CONTEXT (cipher), always_trust);
+               camel_gpg_context_set_prefer_inline (CAMEL_GPG_CONTEXT (cipher), prefer_inline);
 
                success = camel_cipher_context_encrypt_sync (
                        cipher, pgp_key_id, context->recipients,
@@ -1518,15 +1520,44 @@ composer_build_message_finish (EMsgComposer *composer,
 
        /* Finalize some details before returning. */
 
-       if (!context->skip_content)
-               camel_medium_set_content (
-                       CAMEL_MEDIUM (context->message),
-                       context->top_level_part);
+       if (!context->skip_content) {
+               if (context->top_level_part != context->text_plain_part &&
+                   CAMEL_IS_MIME_PART (context->top_level_part)) {
+                       CamelDataWrapper *content;
+                       CamelMedium *imedium, *omedium;
+                       GArray *headers;
 
-       if (context->top_level_part == context->text_plain_part)
+                       imedium = CAMEL_MEDIUM (context->top_level_part);
+                       omedium = CAMEL_MEDIUM (context->message);
+
+                       content = camel_medium_get_content (imedium);
+                       camel_medium_set_content (omedium, content);
+                       omedium->parent.encoding = imedium->parent.encoding;
+
+                       headers = camel_medium_get_headers (imedium);
+                       if (headers) {
+                               gint ii;
+
+                               for (ii = 0; ii < headers->len; ii++) {
+                                       CamelMediumHeader *hdr = &g_array_index (headers, CamelMediumHeader, 
ii);
+
+                                       camel_medium_set_header (omedium, hdr->name, hdr->value);
+                               }
+
+                               camel_medium_free_headers (imedium, headers);
+                       }
+               } else {
+                       camel_medium_set_content (
+                               CAMEL_MEDIUM (context->message),
+                               context->top_level_part);
+               }
+       }
+
+       if (context->top_level_part == context->text_plain_part) {
                camel_mime_part_set_encoding (
                        CAMEL_MIME_PART (context->message),
                        context->plain_encoding);
+       }
 
        return g_object_ref (context->message);
 }
diff --git a/mail/e-mail-config-security-page.c b/mail/e-mail-config-security-page.c
index 2542453..441159f 100644
--- a/mail/e-mail-config-security-page.c
+++ b/mail/e-mail-config-security-page.c
@@ -499,6 +499,18 @@ mail_config_security_page_constructed (GObject *object)
                G_BINDING_SYNC_CREATE |
                G_BINDING_BIDIRECTIONAL);
 
+       text = _("Prefer _inline sign/encrypt for plain text messages");
+       widget = gtk_check_button_new_with_mnemonic (text);
+       gtk_widget_set_margin_left (widget, 12);
+       gtk_grid_attach (GTK_GRID (container), widget, 0, 7, 2, 1);
+       gtk_widget_show (widget);
+
+       e_binding_bind_property (
+               openpgp_ext, "prefer-inline",
+               widget, "active",
+               G_BINDING_SYNC_CREATE |
+               G_BINDING_BIDIRECTIONAL);
+
 #if defined (HAVE_NSS)
 
        /*** Security MIME (S/MIME) ***/


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