diff -urNp -x '*.orig' mutt-2.0.6.org/PATCHES mutt-2.0.6/PATCHES --- mutt-2.0.6.org/PATCHES 2021-04-18 19:23:38.550015388 +0200 +++ mutt-2.0.6/PATCHES 2021-04-18 19:23:38.680017105 +0200 @@ -1,2 +1,3 @@ +patch-1.5.6.dw.crypt-autoselectkey.1 vvv.quote patch-1.3.27.cd.signatures_menu.2.1 diff -urNp -x '*.orig' mutt-2.0.6.org/init.h mutt-2.0.6/init.h --- mutt-2.0.6.org/init.h 2021-04-18 19:23:38.550015388 +0200 +++ mutt-2.0.6/init.h 2021-04-18 19:23:38.680017105 +0200 @@ -1203,6 +1203,16 @@ struct option_t MuttVars[] = { ** For a full listing of defined \fCprintf(3)\fP-like sequences see ** the section on $$index_format. See also $$attribution_locale. */ + + + { "pgp_autoselectkey", DT_SYN, R_NONE, {.p="crypt_autoselectkey"}, {.l=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. + */ /* L10N: $forward_attribution_trailer default value */ diff -urNp -x '*.orig' mutt-2.0.6.org/mutt.h mutt-2.0.6/mutt.h --- mutt-2.0.6.org/mutt.h 2021-04-18 19:23:38.546682010 +0200 +++ mutt-2.0.6/mutt.h 2021-04-18 19:23:38.680017105 +0200 @@ -429,6 +429,7 @@ enum #if defined(HAVE_QDBM) || defined(HAVE_TC) || defined(HAVE_KC) OPTHCACHECOMPRESS, #endif /* HAVE_QDBM */ + OPTCRYPTAUTOSELECT, #endif OPTHDRS, OPTHEADER, diff -urNp -x '*.orig' mutt-2.0.6.org/pgpkey.c mutt-2.0.6/pgpkey.c --- mutt-2.0.6.org/pgpkey.c 2020-07-25 20:22:53.000000000 +0200 +++ mutt-2.0.6/pgpkey.c 2021-04-18 19:23:38.680017105 +0200 @@ -440,8 +440,13 @@ static int pgp_id_matches_addr (ADDRESS 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; @@ -456,6 +461,7 @@ static pgp_key_t pgp_select_key (pgp_key pgp_uid_t *a; int (*f) (const void *, const void *); + int keymatch = 0; /* count matching keys */ int unusable = 0; keymax = 0; @@ -485,6 +491,7 @@ static pgp_key_t pgp_select_key (pgp_key KeyTable[i++] = a; } + keymatch++; } if (!i && unusable) @@ -493,6 +500,21 @@ static pgp_key_t pgp_select_key (pgp_key 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) { @@ -609,9 +631,7 @@ static pgp_key_t pgp_select_key (pgp_key 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];