--- pgp-hook/PATCHES Nov 2001 19:16:52 -0000 2.4 +++ pgp-hook/PATCHES Mar 2003 11:25:04 -0000 @@ -0,0 +1 @@ +patch-1.4.1.dw.pgp-hook.3 --- pgp-hook/hook.c Jun 2001 10:06:14 -0000 2.20 +++ pgp-hook/hook.c Mar 2003 11:25:04 -0000 @@ -117,3 +117,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER { +#ifdef M_PGPHOOK + if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK | M_PGPHOOK)) +#else if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK)) +#endif /* M_PGPHOOK */ { @@ -444,5 +448,21 @@ char *mutt_iconv_hook (const char *chs) #ifdef HAVE_PGP -char *mutt_pgp_hook (ADDRESS *adr) +LIST *mutt_pgp_hook (ADDRESS *adr) { - return _mutt_string_hook (adr->mailbox, M_PGPHOOK); + HOOK *hook; + LIST *key_list = NULL; + + if (!adr && !adr->mailbox) + return (NULL); + + for (hook = Hooks; hook; hook = hook->next) + { + if (!hook->command) + continue; + if (!(hook->type & M_PGPHOOK)) + continue; + + if ((regexec (hook->rx.rx, adr->mailbox, 0, NULL, 0) == 0) ^ hook->rx.not) + key_list = mutt_add_list (key_list, hook->command); + } + return (key_list); } --- pgp-hook/init.h Jul 2002 08:41:29 -0000 2.143.2.11 +++ pgp-hook/init.h Mar 2003 11:25:05 -0000 @@ -1171,2 +1171,10 @@ struct option_t MuttVars[] = { + { "pgp_autoselectkey", DT_BOOL, R_NONE, OPTPGPAUTOSELECT, 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 \fIpgp-hook\fP command (with ``$$pgp_confirmhook'' set) and the + ** ``$$pgp_ignore_subkeys'' variable. + */ { "pgp_autosign", DT_BOOL, R_NONE, OPTPGPAUTOSIGN, 0 }, @@ -1187,2 +1195,10 @@ struct option_t MuttVars[] = { ** requested as well. + */ + { "pgp_confirmhook", DT_BOOL, R_NONE, OPTPGPCONFIRMHOOK, 1 }, + /* + ** .pp + ** If set, then you will be prompted for confirmation of keys when using + ** the \fIpgp-hook\fP command. If unset, no such confirmation prompt will + ** be presented. This is generally considered unsafe, especially where + ** typos are concerned. */ --- pgp-hook/mutt.h Jul 2002 09:46:58 -0000 2.111.2.2 +++ pgp-hook/mutt.h Mar 2003 11:25:05 -0000 @@ -424,4 +424,6 @@ enum #ifdef HAVE_PGP + OPTPGPAUTOSELECT, OPTPGPAUTOSIGN, OPTPGPAUTOENCRYPT, + OPTPGPCONFIRMHOOK, OPTPGPIGNORESUB, --- pgp-hook/pgp.c Jan 2002 15:39:28 -0000 2.45 +++ pgp-hook/pgp.c Mar 2003 11:25:05 -0000 @@ -1329,2 +1329,4 @@ char *pgp_findKeys (ADDRESS *to, ADDRESS size_t keylist_used = 0; + LIST *hook_list = NULL; + LIST *hook = NULL; ADDRESS *tmp = NULL, *addr = NULL; @@ -1362,58 +1364,84 @@ char *pgp_findKeys (ADDRESS *to, ADDRESS q = p; - k_info = NULL; - if ((keyID = mutt_pgp_hook (p)) != NULL) + /* + * grab the list of matching hooks (matching on recipient address) + * process each entry singly so that auto key selection still works + */ + hook_list = mutt_pgp_hook (p); + hook = hook_list; + while (1) { int r; - snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), keyID, p->mailbox); - if ((r = mutt_yesorno (buf, M_YES)) == M_YES) + + k_info = NULL; + + if (hook) { - /* check for e-mail address */ - if ((t = strchr (keyID, '@')) && - (addr = rfc822_parse_adrlist (NULL, keyID))) + keyID = (char *)hook->data; + snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), keyID, p->mailbox); + if (!option(OPTPGPCONFIRMHOOK) || (r = mutt_yesorno (buf, M_YES)) == M_YES) { - if (fqdn) rfc822_qualify (addr, fqdn); - q = addr; + /* check for e-mail address */ + if ((t = strchr (keyID, '@')) && + (addr = rfc822_parse_adrlist (NULL, keyID))) + { + if (fqdn) rfc822_qualify (addr, fqdn); + q = addr; + } + else + k_info = pgp_getkeybystr (keyID, KEYFLAG_CANENCRYPT, PGP_PUBRING); + } + else if (r == -1) + { + /* + * yes, this implies that if one key fails they all do + */ + safe_free ((void **) &keylist); + rfc822_free_address (&tmp); + rfc822_free_address (&addr); + mutt_free_list (&hook_list); + return NULL; } - else - k_info = pgp_getkeybystr (keyID, KEYFLAG_CANENCRYPT, PGP_PUBRING); } - else if (r == -1) + + if (k_info == NULL) + pgp_invoke_getkeys (q); + + if (k_info == NULL && (k_info = pgp_getkeybyaddr (q, KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) { - safe_free ((void **) &keylist); - rfc822_free_address (&tmp); - rfc822_free_address (&addr); - return NULL; + snprintf (buf, sizeof (buf), _("Enter keyID for %s: "), q->mailbox); + + if ((key = pgp_ask_for_key (buf, q->mailbox, + KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) + { + safe_free ((void **)&keylist); + rfc822_free_address (&tmp); + rfc822_free_address (&addr); + mutt_free_list (&hook_list); + return NULL; + } } - } + else + key = k_info; - if (k_info == NULL) - pgp_invoke_getkeys (q); + keyID = pgp_keyid (key); + + keylist_size += mutt_strlen (keyID) + 4; + safe_realloc ((void **)&keylist, keylist_size); + sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", /* __SPRINTF_CHECKED__ */ + keyID); + keylist_used = mutt_strlen (keylist); - if (k_info == NULL && (k_info = pgp_getkeybyaddr (q, KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) - { - snprintf (buf, sizeof (buf), _("Enter keyID for %s: "), q->mailbox); + pgp_free_key (&key); + rfc822_free_address (&addr); - if ((key = pgp_ask_for_key (buf, q->mailbox, - KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) - { - safe_free ((void **)&keylist); - rfc822_free_address (&tmp); - rfc822_free_address (&addr); - return NULL; - } - } - else - key = k_info; + if (!hook_list) + break; - keyID = pgp_keyid (key); - - keylist_size += mutt_strlen (keyID) + 4; - safe_realloc ((void **)&keylist, keylist_size); - sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", /* __SPRINTF_CHECKED__ */ - keyID); - keylist_used = mutt_strlen (keylist); + hook = hook->next; + if (!hook) + break; - pgp_free_key (&key); - rfc822_free_address (&addr); + } + mutt_free_list (&hook_list); --- pgp-hook/pgpkey.c Jan 2002 09:04:28 -0000 2.39 +++ pgp-hook/pgpkey.c Mar 2003 11:25:05 -0000 @@ -437,2 +437,7 @@ static int pgp_id_matches_addr (ADDRESS + +#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, @@ -452,2 +457,3 @@ static pgp_key_t *pgp_select_key (pgp_ke + int keymatch = 0; /* count matching keys */ int unusable = 0; @@ -481,2 +487,3 @@ static pgp_key_t *pgp_select_key (pgp_ke } + keymatch++; } @@ -489,2 +496,17 @@ static pgp_key_t *pgp_select_key (pgp_ke } + else if (keymatch == 1 && option(OPTPGPAUTOSELECT)) + { + /* + * 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); + } + } + } @@ -599,5 +621,3 @@ static pgp_key_t *pgp_select_key (pgp_ke - if (option (OPTPGPCHECKTRUST) && - (!pgp_id_is_valid (KeyTable[menu->current]) - || !pgp_id_is_strong (KeyTable[menu->current]))) + if (!pgp_trusted_id(KeyTable[menu->current])) { --- pgp-hook/protos.h Apr 2002 17:12:18 -0000 2.86.2.1 +++ pgp-hook/protos.h Mar 2003 11:25:05 -0000 @@ -132,3 +132,3 @@ char *mutt_get_parameter (const char *, #ifdef HAVE_PGP -char *mutt_pgp_hook (ADDRESS *); +LIST *mutt_pgp_hook (ADDRESS *); #endif /* HAVE_PGP */ --- pgp-hook/doc/manual.sgml.head Oct 2002 09:43:11 -0000 1.73.2.5 +++ pgp-hook/doc/manual.sgml.head Mar 2003 11:25:05 -0000 @@ -1390,3 +1390,5 @@ normally use. The pgp-hook command prov specify the ID of the public key to be used when encrypting messages to -a certain recipient. +a certain recipient. You may use multiple pgp-hook's with the same +pattern; multiple matching pgp-hook's result in the use of multiple +keyids for recipient. --- pgp-hook/doc/muttrc.man.head May 2002 09:51:46 -0000 1.16.2.1 +++ pgp-hook/doc/muttrc.man.head Mar 2003 11:25:05 -0000 @@ -259,3 +259,5 @@ The pgp-hook command provides a method b specify the ID of the public key to be used when encrypting messages -to a certain recipient. +to a certain recipient. You may use multiple \fBpgp-hook\fPs with the +same \fIpattern\fP; multiple matching \fBpgp-hook\fPs result in the use +of multiple \fIkey-id\fPs for recipient. .TP