Link Here
|
|
|
1 |
Base: http://home.woolridge.ca/mutt/patches/patch-1.5.1.dw.pgp-hook.3 |
2 |
--- PATCHES 24 Jan 2002 12:10:47 -0000 3.0 |
3 |
+++ PATCHES 31 Aug 2002 22:01:56 -0000 |
4 |
@@ -0,0 +1 @@ |
5 |
+patch-1.5.1.dw.pgp-hook.3 |
6 |
--- hook.c 5 Feb 2002 21:30:31 -0000 3.3 |
7 |
+++ hook.c 31 Aug 2002 22:01:56 -0000 |
8 |
@@ -118,7 +118,11 @@ int mutt_parse_hook (BUFFER *buf, BUFFER |
9 |
ptr->rx.not == not && |
10 |
!mutt_strcmp (pattern.data, ptr->rx.pattern)) |
11 |
{ |
12 |
+#ifdef M_CRYPTHOOK |
13 |
+ if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK | M_CRYPTHOOK)) |
14 |
+#else |
15 |
if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK)) |
16 |
+#endif /* M_CRYPTHOOK */ |
17 |
{ |
18 |
/* these hooks allow multiple commands with the same |
19 |
* pattern, so if we've already seen this pattern/command pair, just |
20 |
@@ -445,9 +449,25 @@ char *mutt_iconv_hook (const char *chs) |
21 |
} |
22 |
|
23 |
#if defined(HAVE_PGP) || defined(HAVE_SMIME) |
24 |
-char *mutt_crypt_hook (ADDRESS *adr) |
25 |
+LIST *mutt_crypt_hook (ADDRESS *adr) |
26 |
{ |
27 |
- return _mutt_string_hook (adr->mailbox, M_CRYPTHOOK); |
28 |
+ HOOK *hook; |
29 |
+ LIST *key_list = NULL; |
30 |
+ |
31 |
+ if (!adr && !adr->mailbox) |
32 |
+ return (NULL); |
33 |
+ |
34 |
+ for (hook = Hooks; hook; hook = hook->next) |
35 |
+ { |
36 |
+ if (!hook->command) |
37 |
+ continue; |
38 |
+ if (!(hook->type & M_CRYPTHOOK)) |
39 |
+ continue; |
40 |
+ |
41 |
+ if ((regexec (hook->rx.rx, adr->mailbox, 0, NULL, 0) == 0) ^ hook->rx.not) |
42 |
+ key_list = mutt_add_list (key_list, hook->command); |
43 |
+ } |
44 |
+ return (key_list); |
45 |
} |
46 |
#endif /* HAVE_PGP */ |
47 |
|
48 |
--- init.h 25 Apr 2002 13:26:26 -0000 3.15 |
49 |
+++ init.h 31 Aug 2002 22:01:57 -0000 |
50 |
@@ -1180,6 +1180,16 @@ struct option_t MuttVars[] = { |
51 |
|
52 |
#if defined(HAVE_PGP) || defined(HAVE_SMIME) |
53 |
# ifdef HAVE_PGP |
54 |
+ { "pgp_autoselectkey", DT_SYN, R_NONE, UL "crypt_autoselectkey", 0 }, |
55 |
+# endif |
56 |
+ { "crypt_autoselectkey", DT_BOOL, R_NONE, OPTCRYPTAUTOSELECT, 0 }, |
57 |
+ /* |
58 |
+ ** .pp |
59 |
+ ** If set, then a list of keys is not presented for selection when only |
60 |
+ ** one matching key is available. This may be useful in conjunction with |
61 |
+ ** the \fIcrypt-hook\fP command (with ``$$crypt_confirmhook'' set). |
62 |
+ */ |
63 |
+# ifdef HAVE_PGP |
64 |
{ "pgp_autosign", DT_SYN, R_NONE, UL "crypt_autosign", 0 }, |
65 |
# endif |
66 |
{ "crypt_autosign", DT_BOOL, R_NONE, OPTCRYPTAUTOSIGN, 0 }, |
67 |
@@ -1205,6 +1215,17 @@ struct option_t MuttVars[] = { |
68 |
** requested as well. IF ``$$smime_is_default'' is set, then |
69 |
** OpenSSL is used instead to create S/MIME messages and settings can |
70 |
** be overridden by use of the \fIsmime-menu\fP. |
71 |
+ */ |
72 |
+# ifdef HAVE_PGP |
73 |
+ { "pgp_confirmhook", DT_SYN, R_NONE, UL "crypt_confirmhook", 1 }, |
74 |
+# endif |
75 |
+ { "crypt_confirmhook", DT_BOOL, R_NONE, OPTCRYPTCONFIRMHOOK, 1 }, |
76 |
+ /* |
77 |
+ ** .pp |
78 |
+ ** If set, then you will be prompted for confirmation of keys when using |
79 |
+ ** the \fIcrypt-hook\fP command. If unset, no such confirmation prompt will |
80 |
+ ** be presented. This is generally considered unsafe, especially where |
81 |
+ ** typos are concerned. |
82 |
*/ |
83 |
#ifdef HAVE_PGP |
84 |
{ "pgp_ignore_subkeys", DT_BOOL, R_NONE, OPTPGPIGNORESUB, 1}, |
85 |
--- mutt.h 20 Apr 2002 08:11:13 -0000 3.8 |
86 |
+++ mutt.h 31 Aug 2002 22:01:58 -0000 |
87 |
@@ -422,6 +422,7 @@ enum |
88 |
/* PGP options */ |
89 |
|
90 |
#if defined(HAVE_PGP) || defined(HAVE_SMIME) |
91 |
+ OPTCRYPTAUTOSELECT, |
92 |
OPTCRYPTAUTOSIGN, |
93 |
OPTCRYPTAUTOENCRYPT, |
94 |
OPTCRYPTREPLYENCRYPT, |
95 |
@@ -433,6 +434,7 @@ enum |
96 |
OPTASKCERTLABEL, |
97 |
OPTSDEFAULTDECRYPTKEY, |
98 |
#endif |
99 |
+ OPTCRYPTCONFIRMHOOK, |
100 |
#ifdef HAVE_PGP |
101 |
OPTPGPIGNORESUB, |
102 |
OPTPGPLONGIDS, |
103 |
--- pgp.c 4 Apr 2002 06:50:12 -0000 3.13 |
104 |
+++ pgp.c 31 Aug 2002 22:01:58 -0000 |
105 |
@@ -1037,6 +1037,8 @@ char *pgp_findKeys (ADDRESS *to, ADDRESS |
106 |
char *keyID, *keylist = NULL, *t; |
107 |
size_t keylist_size = 0; |
108 |
size_t keylist_used = 0; |
109 |
+ LIST *hook_list = NULL; |
110 |
+ LIST *hook = NULL; |
111 |
ADDRESS *tmp = NULL, *addr = NULL; |
112 |
ADDRESS **last = &tmp; |
113 |
ADDRESS *p, *q; |
114 |
@@ -1070,62 +1072,88 @@ char *pgp_findKeys (ADDRESS *to, ADDRESS |
115 |
char buf[LONG_STRING]; |
116 |
|
117 |
q = p; |
118 |
- k_info = NULL; |
119 |
|
120 |
- if ((keyID = mutt_crypt_hook (p)) != NULL) |
121 |
+ /* |
122 |
+ * grab the list of matching hooks (matching on recipient address) |
123 |
+ * process each entry singly so that auto key selection still works |
124 |
+ */ |
125 |
+ hook_list = mutt_crypt_hook (p); |
126 |
+ hook = hook_list; |
127 |
+ while (1) |
128 |
{ |
129 |
int r; |
130 |
- snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), keyID, p->mailbox); |
131 |
- if ((r = mutt_yesorno (buf, M_YES)) == M_YES) |
132 |
+ |
133 |
+ k_info = NULL; |
134 |
+ |
135 |
+ if (hook) |
136 |
{ |
137 |
- /* check for e-mail address */ |
138 |
- if ((t = strchr (keyID, '@')) && |
139 |
- (addr = rfc822_parse_adrlist (NULL, keyID))) |
140 |
+ keyID = (char *)hook->data; |
141 |
+ snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), keyID, p->mailbox); |
142 |
+ if (!option(OPTCRYPTCONFIRMHOOK) || (r = mutt_yesorno (buf, M_YES)) == M_YES) |
143 |
{ |
144 |
- if (fqdn) rfc822_qualify (addr, fqdn); |
145 |
- q = addr; |
146 |
+ /* check for e-mail address */ |
147 |
+ if ((t = strchr (keyID, '@')) && |
148 |
+ (addr = rfc822_parse_adrlist (NULL, keyID))) |
149 |
+ { |
150 |
+ if (fqdn) rfc822_qualify (addr, fqdn); |
151 |
+ q = addr; |
152 |
+ } |
153 |
+ else |
154 |
+ k_info = pgp_getkeybystr (keyID, KEYFLAG_CANENCRYPT, PGP_PUBRING); |
155 |
+ } |
156 |
+ else if (r == -1) |
157 |
+ { |
158 |
+ /* |
159 |
+ * yes, this implies that if one key fails they all do |
160 |
+ */ |
161 |
+ safe_free ((void **) &keylist); |
162 |
+ rfc822_free_address (&tmp); |
163 |
+ rfc822_free_address (&addr); |
164 |
+ mutt_free_list (&hook_list); |
165 |
+ return NULL; |
166 |
} |
167 |
- else |
168 |
- k_info = pgp_getkeybystr (keyID, KEYFLAG_CANENCRYPT, PGP_PUBRING); |
169 |
} |
170 |
- else if (r == -1) |
171 |
+ |
172 |
+ if (k_info == NULL) |
173 |
+ pgp_invoke_getkeys (q); |
174 |
+ |
175 |
+ if (k_info == NULL && (k_info = pgp_getkeybyaddr (q, KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) |
176 |
{ |
177 |
- safe_free ((void **) &keylist); |
178 |
- rfc822_free_address (&tmp); |
179 |
- rfc822_free_address (&addr); |
180 |
- return NULL; |
181 |
+ snprintf (buf, sizeof (buf), _("Enter keyID for %s: "), q->mailbox); |
182 |
+ |
183 |
+ if ((key = pgp_ask_for_key (buf, q->mailbox, |
184 |
+ KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) |
185 |
+ { |
186 |
+ safe_free ((void **)&keylist); |
187 |
+ rfc822_free_address (&tmp); |
188 |
+ rfc822_free_address (&addr); |
189 |
+ mutt_free_list (&hook_list); |
190 |
+ return NULL; |
191 |
+ } |
192 |
} |
193 |
- } |
194 |
+ else |
195 |
+ key = k_info; |
196 |
|
197 |
- if (k_info == NULL) |
198 |
- pgp_invoke_getkeys (q); |
199 |
+ keyID = pgp_keyid (key); |
200 |
+ |
201 |
+ keylist_size += mutt_strlen (keyID) + 4; |
202 |
+ safe_realloc ((void **)&keylist, keylist_size); |
203 |
+ sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", /* __SPRINTF_CHECKED__ */ |
204 |
+ keyID); |
205 |
+ keylist_used = mutt_strlen (keylist); |
206 |
|
207 |
- if (k_info == NULL && (k_info = pgp_getkeybyaddr (q, KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) |
208 |
- { |
209 |
- snprintf (buf, sizeof (buf), _("Enter keyID for %s: "), q->mailbox); |
210 |
+ pgp_free_key (&key); |
211 |
+ rfc822_free_address (&addr); |
212 |
|
213 |
- if ((key = pgp_ask_for_key (buf, q->mailbox, |
214 |
- KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) |
215 |
- { |
216 |
- safe_free ((void **)&keylist); |
217 |
- rfc822_free_address (&tmp); |
218 |
- rfc822_free_address (&addr); |
219 |
- return NULL; |
220 |
- } |
221 |
- } |
222 |
- else |
223 |
- key = k_info; |
224 |
+ if (!hook_list) |
225 |
+ break; |
226 |
|
227 |
- keyID = pgp_keyid (key); |
228 |
- |
229 |
- keylist_size += mutt_strlen (keyID) + 4; |
230 |
- safe_realloc ((void **)&keylist, keylist_size); |
231 |
- sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", /* __SPRINTF_CHECKED__ */ |
232 |
- keyID); |
233 |
- keylist_used = mutt_strlen (keylist); |
234 |
+ hook = hook->next; |
235 |
+ if (!hook) |
236 |
+ break; |
237 |
|
238 |
- pgp_free_key (&key); |
239 |
- rfc822_free_address (&addr); |
240 |
+ } |
241 |
+ mutt_free_list (&hook_list); |
242 |
|
243 |
} |
244 |
rfc822_free_address (&tmp); |
245 |
--- pgpkey.c 24 Jan 2002 12:10:51 -0000 3.0 |
246 |
+++ pgpkey.c 31 Aug 2002 22:01:58 -0000 |
247 |
@@ -435,6 +435,11 @@ static int pgp_id_matches_addr (ADDRESS |
248 |
return rv; |
249 |
} |
250 |
|
251 |
+ |
252 |
+#define pgp_trusted_id(uid) (!option(OPTPGPCHECKTRUST) \ |
253 |
+ || (pgp_id_is_valid((uid)) \ |
254 |
+ && pgp_id_is_strong((uid)))) |
255 |
+ |
256 |
static pgp_key_t *pgp_select_key (pgp_key_t *keys, |
257 |
ADDRESS * p, const char *s) |
258 |
{ |
259 |
@@ -450,6 +455,7 @@ static pgp_key_t *pgp_select_key (pgp_ke |
260 |
pgp_uid_t *a; |
261 |
int (*f) (const void *, const void *); |
262 |
|
263 |
+ int keymatch = 0; /* count matching keys */ |
264 |
int unusable = 0; |
265 |
|
266 |
keymax = 0; |
267 |
@@ -479,6 +485,7 @@ static pgp_key_t *pgp_select_key (pgp_ke |
268 |
|
269 |
KeyTable[i++] = a; |
270 |
} |
271 |
+ keymatch++; |
272 |
} |
273 |
|
274 |
if (!i && unusable) |
275 |
@@ -487,6 +494,21 @@ static pgp_key_t *pgp_select_key (pgp_ke |
276 |
mutt_sleep (1); |
277 |
return NULL; |
278 |
} |
279 |
+ else if (keymatch == 1 && option(OPTCRYPTAUTOSELECT)) |
280 |
+ { |
281 |
+ /* |
282 |
+ * Only one matching key...see if there's an id with enough trust to auto-select |
283 |
+ */ |
284 |
+ kp = KeyTable[0]->parent; |
285 |
+ for (a = kp->address; a; a = a->next) |
286 |
+ { |
287 |
+ if (pgp_trusted_id(a)) |
288 |
+ { |
289 |
+ safe_free ((void **) &KeyTable); |
290 |
+ return (kp); |
291 |
+ } |
292 |
+ } |
293 |
+ } |
294 |
|
295 |
switch (PgpSortKeys & SORT_MASK) |
296 |
{ |
297 |
@@ -597,9 +619,7 @@ static pgp_key_t *pgp_select_key (pgp_ke |
298 |
break; |
299 |
} |
300 |
|
301 |
- if (option (OPTPGPCHECKTRUST) && |
302 |
- (!pgp_id_is_valid (KeyTable[menu->current]) |
303 |
- || !pgp_id_is_strong (KeyTable[menu->current]))) |
304 |
+ if (!pgp_trusted_id(KeyTable[menu->current])) |
305 |
{ |
306 |
char *s = ""; |
307 |
char buff[LONG_STRING]; |
308 |
--- protos.h 29 Apr 2002 17:12:00 -0000 3.7 |
309 |
+++ protos.h 31 Aug 2002 22:01:59 -0000 |
310 |
@@ -130,7 +130,7 @@ char *mutt_get_body_charset (char *, siz |
311 |
char *mutt_get_name (ADDRESS *); |
312 |
char *mutt_get_parameter (const char *, PARAMETER *); |
313 |
#if defined(HAVE_PGP) || defined(HAVE_SMIME) |
314 |
-char *mutt_crypt_hook (ADDRESS *); |
315 |
+LIST *mutt_crypt_hook (ADDRESS *); |
316 |
#endif /* HAVE_PGP */ |
317 |
char *mutt_make_date (char *, size_t); |
318 |
|
319 |
--- doc/manual.sgml.head 25 Apr 2002 13:28:23 -0000 3.3 |
320 |
+++ doc/manual.sgml.head 31 Aug 2002 22:02:00 -0000 |
321 |
@@ -1388,7 +1388,9 @@ recipient's public key can't be deduced |
322 |
or because, for some reasons, you need to override the key Mutt would |
323 |
normally use. The pgp-hook command provides a method by which you can |
324 |
specify the ID of the public key to be used when encrypting messages to |
325 |
-a certain recipient. |
326 |
+a certain recipient. You may use multiple pgp-hook's with the same |
327 |
+pattern; multiple matching pgp-hook's result in the use of multiple |
328 |
+keyids for recipient. |
329 |
|
330 |
<sect1>Adding key sequences to the keyboard buffer<label id="push"> |
331 |
<p> |
332 |
--- doc/muttrc.man.head.orig2 Mon Sep 2 17:36:11 2002 |
333 |
+++ doc/muttrc.man.head Mon Sep 2 17:37:22 2002 |
334 |
@@ -272,5 +272,7 @@ |
335 |
The pgp-hook command provides a method by which you can |
336 |
specify the ID of the public key to be used when encrypting messages |
337 |
-to a certain recipient. |
338 |
+to a certain recipient. You may use multiple \fBpgp-hook\fPs with the |
339 |
+same \fIpattern\fP; multiple matching \fBpgp-hook\fPs result in the use |
340 |
+of multiple \fIkey-id\fPs for recipient. |
341 |
.PP |
342 |
.nf |