From 1fc63b54bb9fe2d15729e193721752a1d49e9a20 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 10 Oct 2012 20:14:37 +0200 Subject: [PATCH 1/6] In case of multiple matching encryption keys, use the most recent one without bothering the user --- src/plugins/pgpcore/select-keys.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/plugins/pgpcore/select-keys.c b/src/plugins/pgpcore/select-keys.c index f558f4a..5ba6b6f 100644 --- a/src/plugins/pgpcore/select-keys.c +++ b/src/plugins/pgpcore/select-keys.c @@ -278,6 +278,7 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot cm_return_val_if_fail (sk, NULL); clist = sk->clist; cm_return_val_if_fail (clist, NULL); + static int use_most_recent_key = 1; debug_print ("select_keys:fill_clist: pattern '%s' proto %d\n", pattern, proto); @@ -306,7 +307,6 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot if (!key->can_encrypt || key->revoked || key->expired || key->disabled) continue; debug_print ("%% %s:%d: insert\n", __FILE__ ,__LINE__ ); - set_row (clist, key, proto ); for (; uid; uid = uid->next) { gchar *raw_mail = NULL; @@ -322,14 +322,37 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot } g_free(raw_mail); } - num_results++; - last_key = key; + if (use_most_recent_key) { + if (last_key == NULL) { + debug_print ("%s:%d: First matching key for %s has fingerprint %s\n", + __FILE__ ,__LINE__, pattern, key->subkeys->fpr); + last_key = key; + } else if (key->subkeys->timestamp > last_key->subkeys->timestamp) { + debug_print ("%s:%d: Ditching key %s in favor of the more recent %s\n", + __FILE__ ,__LINE__, last_key->subkeys->fpr, key->subkeys->fpr); + last_key = key; + } else { + debug_print ("%s:%d: Not chosing key %s as it's older than the current choice\n", + __FILE__ ,__LINE__, key->subkeys->fpr); + } + } else { + set_row (clist, key, proto ); + num_results++; + last_key = key; + } key = NULL; update_progress (sk, ++running, pattern); while (gtk_events_pending ()) gtk_main_iteration (); } - + + if (use_most_recent_key && last_key) { + debug_print ("%s:%d: The final key for %s has fingerprint %s\n", + __FILE__ ,__LINE__, pattern, last_key->subkeys->fpr); + set_row (clist, last_key, proto ); + num_results++; + } + if (exact_match == TRUE && num_results == 1) { if (last_key->uids->validity < GPGME_VALIDITY_FULL && !use_untrusted(last_key, last_uid, proto)) -- 1.8.1.3