Package: mutt-patched
Severity: wishlist
Tags: patch
Hi,
please include a patch to automatically select a key if only one trusted key of
the recipient is available.
The patch adds a configuration option to enable it. It's disabled by default.
The attached patch is based on top of the existing patches, the patch is
originally from Dale Woolridge, see http://www.woolridge.org/mutt/crypt-
autoselectkey.html
Best,
Philip
-- System Information:
Debian Release: jessie/sid
APT prefers testing
APT policy: (700, 'testing'), (550, 'unstable'), (101, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.14-2-amd64 (SMP w/4 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
--- a/init.h
+++ b/init.h
@@ -499,6 +499,16 @@
** $$crypt_replyencrypt,
** $$crypt_autosign, $$crypt_replysign and $$smime_is_default.
*/
+
+
+ { "pgp_autoselectkey", DT_SYN, R_NONE, UL "crypt_autoselectkey", 0 },
+ { "crypt_autoselectkey", DT_BOOL, R_NONE, OPTCRYPTAUTOSELECT, 0 },
+ /*
+ ** .pp
+ ** If set, then a list of keys is not presented for selection when only
+ ** one matching key is available. This may be useful in conjunction with
+ ** the \fIcrypt-hook\fP command.
+ */
{ "pgp_autosign", DT_SYN, R_NONE, UL "crypt_autosign", 0 },
{ "crypt_autosign", DT_BOOL, R_NONE, OPTCRYPTAUTOSIGN, 0 },
/*
--- a/mutt.h
+++ b/mutt.h
@@ -485,6 +485,7 @@
/* PGP options */
+ OPTCRYPTAUTOSELECT,
OPTCRYPTAUTOSIGN,
OPTCRYPTAUTOENCRYPT,
OPTCRYPTAUTOPGP,
--- a/pgpkey.c
+++ b/pgpkey.c
@@ -440,8 +440,13 @@
return rv;
}
+
+#define pgp_trusted_id(uid) (!option(OPTPGPCHECKTRUST) \
+ || (pgp_id_is_valid((uid)) \
+ && pgp_id_is_strong((uid))))
+
static pgp_key_t pgp_select_key (pgp_key_t keys,
- ADDRESS * p, const char *s)
+ ADDRESS * p, const char *s)
{
int keymax;
pgp_uid_t **KeyTable;
@@ -455,6 +460,7 @@
pgp_uid_t *a;
int (*f) (const void *, const void *);
+ int keymatch = 0; /* count matching keys */
int unusable = 0;
keymax = 0;
@@ -484,6 +490,7 @@
KeyTable[i++] = a;
}
+ keymatch++;
}
if (!i && unusable)
@@ -492,6 +499,21 @@
mutt_sleep (1);
return NULL;
}
+ else if (keymatch == 1 && option(OPTCRYPTAUTOSELECT))
+ {
+ /*
+ * Only one matching key...see if there's an id with enough trust to auto-select
+ */
+ kp = KeyTable[0]->parent;
+ for (a = kp->address; a; a = a->next)
+ {
+ if (pgp_trusted_id(a))
+ {
+ safe_free ((void **) &KeyTable);
+ return (kp);
+ }
+ }
+ }
switch (PgpSortKeys & SORT_MASK)
{
@@ -601,9 +623,7 @@
break;
}
- if (option (OPTPGPCHECKTRUST) &&
- (!pgp_id_is_valid (KeyTable[menu->current])
- || !pgp_id_is_strong (KeyTable[menu->current])))
+ if (!pgp_trusted_id(KeyTable[menu->current]))
{
char *s = "";
char buff[LONG_STRING];