[evolution-data-server/gnome-3-8] CamelGpgContext: Enclose email addresses in brackets.



commit f7059bb37dcce485d36d769142ec9515708d8ae5
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Jul 20 13:03:24 2013 -0400

    CamelGpgContext: Enclose email addresses in brackets.
    
    The recipient list for encrypting can be specified by either key ID or
    email address.  Enclose email addresses in brackets to ensure an exact
    match, as per the gpg man page:
    
    HOW TO SPECIFY A USER ID
    
           ...
    
           By exact match on an email address.
                  This is indicated by enclosing the email address in the
                  usual way with left and right angles.
    
             <heinrichh uni-duesseldorf de>
    
    Without the brackets gpg uses a substring match, which risks selecting
    the wrong recipient.
    
    (cherry picked from commit 5d8b92c622f6927b253762ff9310479dd3ac627d)

 camel/camel-gpg-context.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index d6b7177..d1b6ef7 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -311,13 +311,25 @@ static void
 gpg_ctx_add_recipient (struct _GpgCtx *gpg,
                        const gchar *keyid)
 {
+       gchar *safe_keyid;
+
        if (gpg->mode != GPG_CTX_MODE_ENCRYPT && gpg->mode != GPG_CTX_MODE_EXPORT)
                return;
 
        if (!gpg->recipients)
                gpg->recipients = g_ptr_array_new ();
 
-       g_ptr_array_add (gpg->recipients, g_strdup (keyid));
+       g_return_if_fail (keyid != NULL);
+
+       /* If the recipient looks like an email address,
+        * enclose it in brackets to ensure an exact match. */
+       if (strchr (keyid, '@') != NULL) {
+               safe_keyid = g_strdup_printf ("<%s>", keyid);
+       } else {
+               safe_keyid = g_strdup (keyid);
+       }
+
+       g_ptr_array_add (gpg->recipients, safe_keyid);
 }
 
 static void


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