Hi all,

I have made a small (2K) patch against mutt-1.2i to extend pgp-hook
to allow multiple keys to be used:

        pgp-hook pattern keyID1,keyID2,keyID3,...
        
This will make mutt use the keys keyID1,keyID2,keyID3, etc.
to encrypt messages whose To:,Bc: or Bcc: headers matches
the pattern.

There is also a new option

        php_hook_confirm
        
which is set by default. When set, mutt will confirm each keyID
which is expanded (which is similar to the unpatched behavior).
When unset mutt will skip this confirmation of each of the listed
keyIDs key. This can be very useful if there are a lot of keyIDs
in the list, and you are sure that they are correct.
The default behavior should be completely backward compatible.

The patch has some rough edges, but it seems useful for my
purposes, so I thought I'd share it with the rest of you.
I've attached the patch to this post. Your mileage may vary.

-- 
Bardur Arantsson
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>

-- In the beginning the Universe was created. This has made a lot
   of people very angry and been widely regarded as a bad move.
                                                 -- Douglas Adams
diff -ur mutt-1.2.pristine/init.h mutt-1.2/init.h
--- mutt-1.2.pristine/init.h    Wed Apr 26 09:32:40 2000
+++ mutt-1.2/init.h     Thu Jun  8 22:58:24 2000
@@ -1086,6 +1086,12 @@
   { "pgp_entry_format", DT_STR,  R_NONE, UL &PgpEntryFormat, UL "%4n %t%f %4l/0x%k 
%-4a %2c %u" },
   /*
   ** .pp
+  ** If set (the default), ask for confirmation on keys expanded by
+  ** \fIpgp_hook\fP.
+  */
+  { "pgp_hook_confirm",        DT_BOOL, R_NONE, OPTPGPHOOKCONFIRM, 1 },
+  /*
+  ** .pp
   ** This variable allows you to customize the PGP key selection menu to
   ** your personal taste. This string is similar to ``$$index_format'', but
   ** has its own set of printf()-like sequences:
diff -ur mutt-1.2.pristine/mutt.h mutt-1.2/mutt.h
--- mutt-1.2.pristine/mutt.h    Wed Apr 26 09:32:40 2000
+++ mutt-1.2/mutt.h     Thu Jun  8 22:59:14 2000
@@ -360,6 +360,7 @@
 #ifdef HAVE_PGP
   OPTPGPAUTOSIGN,
   OPTPGPAUTOENCRYPT,
+  OPTPGPHOOKCONFIRM,
   OPTPGPLONGIDS,
   OPTPGPREPLYENCRYPT,
   OPTPGPREPLYSIGN,
diff -ur mutt-1.2.pristine/pgp.c mutt-1.2/pgp.c
--- mutt-1.2.pristine/pgp.c     Fri Mar  3 11:10:11 2000
+++ mutt-1.2/pgp.c      Thu Jun  8 23:31:00 2000
@@ -1159,6 +1159,7 @@
   ADDRESS *p, *q;
   int i;
   pgp_key_t *k_info, *key;
+  char *keyID_list = NULL;
 
   const char *fqdn = mutt_fqdn (1);
   
@@ -1182,18 +1183,32 @@
 
   tmp = mutt_remove_duplicates (tmp);
   
-  for (p = tmp; p ; p = p->next)
+  for (p = tmp; p ; )
   {
     char buf[LONG_STRING];
 
     q = p;
     k_info = NULL;
 
-    if ((keyID = mutt_pgp_hook (p)) != NULL)
-    {
+    /* any keys listed in pgp_hook? */
+    if ((keyID_list==NULL) && ((keyID_list = mutt_pgp_hook (p)) != NULL))
+      ;
+
+    /* expanding keys from pgp_hook? */
+    if (keyID_list) 
+      {
+      /* proceed to next key in list */
+      if ((keyID = strsep(&keyID_list,",")) != NULL) 
+       {
+      /* confirm usage of each key in the list */
       int r;
       snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), keyID, 
p->mailbox);
-      if ((r = mutt_yesorno (buf, M_YES)) == M_YES)
+      
+      if (option (OPTPGPHOOKCONFIRM) == 0) 
+       r = M_YES; /* auto-confirm */
+
+      if (r == M_YES ||
+         (r = mutt_yesorno (buf, M_YES)) == M_YES)
       {
        /* check for e-mail address */
        if ((t = strchr (keyID, '@')) && 
@@ -1212,7 +1229,11 @@
        rfc822_free_address (&addr);
        return NULL;
       }
-    }
+       }
+      else
+       keyID_list = NULL;
+    };
+
 
     if (k_info == NULL)
       pgp_invoke_getkeys (q);
@@ -1244,6 +1265,8 @@
     pgp_free_key (&key);
     rfc822_free_address (&addr);
 
+    if (!keyID_list)
+      p = p->next;
   }
   rfc822_free_address (&tmp);
   return (keylist);

Reply via email to