e4457a8c341f07bc0a4a77857d5fef7acbcfafe7
[apps/madmutt.git] / lib-crypt / crypt.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
5  * Copyright (C) 2001  Thomas Roessler <roessler@does-not-exist.org>
6  *                     Oliver Ehli <elmy@acm.org>
7  * Copyright (C) 2003  Werner Koch <wk@gnupg.org>
8  * Copyright (C) 2004 g10code GmbH
9  *
10  * This file is part of mutt-ng, see http://www.muttng.org/.
11  * It's licensed under the GNU General Public License,
12  * please see the file GPL in the top level source directory.
13  */
14
15 #if HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18
19 #include <lib-lib/str.h>
20 #include <lib-lib/file.h>
21 #include <lib-lib/ascii.h>
22 #include <lib-lib/mem.h>
23 #include <lib-lib/macros.h>
24
25 #include <lib-mime/mime.h>
26
27 #include <lib-ui/curses.h>
28
29 #include "mutt.h"
30 #include "handler.h"
31 #include "copy.h"
32 #include "crypt.h"
33 #include "pgp.h"
34
35
36 #include <sys/wait.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <sys/stat.h>
41 #include <errno.h>
42 #include <ctype.h>
43
44 #ifdef HAVE_LOCALE_H
45 #include <locale.h>
46 #endif
47
48 #ifdef HAVE_SYS_TIME_H
49 # include <sys/time.h>
50 #endif
51
52 #ifdef HAVE_SYS_RESOURCE_H
53 # include <sys/resource.h>
54 #endif
55
56
57 /* print the current time to avoid spoofing of the signature output */
58 void crypt_current_time (STATE * s, const char *app_name)
59 {
60   time_t t;
61   char p[STRING], tmp[STRING];
62
63   if (option (OPTCRYPTTIMESTAMP)) {
64     t = time (NULL);
65     setlocale (LC_TIME, "");
66     strftime (p, sizeof (p), _(" (current time: %c)"), localtime (&t));
67     setlocale (LC_TIME, "C");
68   }
69   else
70     *p = '\0';
71
72   snprintf (tmp, sizeof (tmp), _("[-- %s output follows%s --]\n"),
73             NONULL (app_name), p);
74   state_attach_puts (tmp, s);
75 }
76
77
78
79 void crypt_forget_passphrase (void)
80 {
81     crypt_pgp_void_passphrase ();
82     crypt_smime_void_passphrase ();
83     mutt_message _("Passphrase(s) forgotten.");
84 }
85
86
87 #if defined(HAVE_SETRLIMIT) && (!defined(DEBUG))
88
89 static void disable_coredumps (void)
90 {
91   struct rlimit rl = { 0, 0 };
92   static short done = 0;
93
94   if (!done) {
95     setrlimit (RLIMIT_CORE, &rl);
96     done = 1;
97   }
98 }
99
100 #endif /* HAVE_SETRLIMIT */
101
102
103 int crypt_valid_passphrase (int flags)
104 {
105   int ret = 0;
106
107 # if defined(HAVE_SETRLIMIT) &&(!defined(DEBUG))
108   disable_coredumps ();
109 # endif
110
111   if (flags & APPLICATION_PGP)
112     ret = crypt_pgp_valid_passphrase ();
113
114   if (flags & APPLICATION_SMIME)
115     ret = crypt_smime_valid_passphrase ();
116
117   return ret;
118 }
119
120
121
122 int mutt_protect (HEADER * msg, char *keylist)
123 {
124   BODY *pbody = NULL, *tmp_pbody = NULL;
125   BODY *tmp_smime_pbody = NULL;
126   BODY *tmp_pgp_pbody = NULL;
127   int flags = msg->security;
128   int i;
129
130   if ((msg->security & SIGN) && !crypt_valid_passphrase (msg->security))
131     return (-1);
132
133   if ((msg->security & PGPINLINE) == PGPINLINE) {
134     /* they really want to send it inline... go for it */
135     if (!isendwin ())
136       mutt_endwin _("Invoking PGP...");
137
138     pbody = crypt_pgp_traditional_encryptsign (msg->content, flags, keylist);
139     if (pbody) {
140       msg->content = pbody;
141       return 0;
142     }
143
144     /* otherwise inline won't work...ask for revert */
145     if ((i =
146          query_quadoption (OPT_PGPMIMEAUTO,
147                            _
148                            ("Message can't be sent inline.  Revert to using PGP/MIME?")))
149         != M_YES) {
150       mutt_error _("Mail not sent.");
151
152       return -1;
153     }
154
155     /* go ahead with PGP/MIME */
156   }
157
158   if (!isendwin ())
159     mutt_endwin (NULL);
160
161   tmp_smime_pbody = msg->content;
162   tmp_pgp_pbody = msg->content;
163
164   if (msg->security & SIGN) {
165     if (msg->security & APPLICATION_SMIME) {
166       if (!(tmp_pbody = crypt_smime_sign_message (msg->content)))
167         return -1;
168       pbody = tmp_smime_pbody = tmp_pbody;
169     }
170
171     if ((msg->security & APPLICATION_PGP)
172         && (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG))) {
173       if (!(tmp_pbody = crypt_pgp_sign_message (msg->content)))
174         return -1;
175
176       flags &= ~SIGN;
177       pbody = tmp_pgp_pbody = tmp_pbody;
178     }
179
180     if ((msg->security & APPLICATION_SMIME)
181         && (msg->security & APPLICATION_PGP)) {
182       /* here comes the draft ;-) */
183     }
184   }
185
186
187   if (msg->security & ENCRYPT) {
188     if ((msg->security & APPLICATION_SMIME)) {
189       if (!(tmp_pbody = crypt_smime_build_smime_entity (tmp_smime_pbody,
190                                                         keylist))) {
191         /* signed ? free it! */
192         return (-1);
193       }
194       /* free tmp_body if messages was signed AND encrypted ... */
195       if (tmp_smime_pbody != msg->content && tmp_smime_pbody != tmp_pbody) {
196         /* detatch and dont't delete msg->content,
197            which tmp_smime_pbody->parts after signing. */
198         tmp_smime_pbody->parts = tmp_smime_pbody->parts->next;
199         msg->content->next = NULL;
200         mutt_free_body (&tmp_smime_pbody);
201       }
202       pbody = tmp_pbody;
203     }
204
205     if ((msg->security & APPLICATION_PGP)) {
206       if (!(pbody = crypt_pgp_encrypt_message (tmp_pgp_pbody, keylist,
207                                                flags & SIGN))) {
208
209         /* did we perform a retainable signature? */
210         if (flags != msg->security) {
211           /* remove the outer multipart layer */
212           tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody);
213           /* get rid of the signature */
214           mutt_free_body (&tmp_pgp_pbody->next);
215         }
216
217         return (-1);
218       }
219
220       /* destroy temporary signature envelope when doing retainable 
221        * signatures.
222
223        */
224       if (flags != msg->security) {
225         tmp_pgp_pbody = mutt_remove_multipart (tmp_pgp_pbody);
226         mutt_free_body (&tmp_pgp_pbody->next);
227       }
228     }
229   }
230
231   if (pbody)
232     msg->content = pbody;
233
234   return 0;
235 }
236
237
238
239
240 int mutt_is_multipart_signed (BODY * b)
241 {
242   char *p;
243
244   if (!b || !(b->type == TYPEMULTIPART) ||
245       !b->subtype || ascii_strcasecmp (b->subtype, "signed"))
246     return 0;
247
248   if (!(p = mutt_get_parameter ("protocol", b->parameter)))
249     return 0;
250
251   if (!(ascii_strcasecmp (p, "multipart/mixed")))
252     return SIGN;
253
254   if (!(ascii_strcasecmp (p, "application/pgp-signature")))
255     return PGPSIGN;
256
257   if (!(ascii_strcasecmp (p, "application/x-pkcs7-signature")))
258     return SMIMESIGN;
259   if (!(ascii_strcasecmp (p, "application/pkcs7-signature")))
260     return SMIMESIGN;
261
262   return 0;
263 }
264
265
266 int mutt_is_multipart_encrypted (BODY * b)
267 {
268   char *p;
269
270   if (!b || b->type != TYPEMULTIPART ||
271       !b->subtype || ascii_strcasecmp (b->subtype, "encrypted") ||
272       !(p = mutt_get_parameter ("protocol", b->parameter)) ||
273       ascii_strcasecmp (p, "application/pgp-encrypted"))
274     return 0;
275
276   return PGPENCRYPT;
277 }
278
279
280 int mutt_is_application_pgp (BODY * m)
281 {
282   int t = 0;
283   char *p;
284
285   if (m->type == TYPEAPPLICATION) {
286     if (!ascii_strcasecmp (m->subtype, "pgp")
287         || !ascii_strcasecmp (m->subtype, "x-pgp-message")) {
288       if ((p = mutt_get_parameter ("x-action", m->parameter))
289           && (!ascii_strcasecmp (p, "sign")
290               || !ascii_strcasecmp (p, "signclear")))
291         t |= PGPSIGN;
292
293       if ((p = mutt_get_parameter ("format", m->parameter)) &&
294           !ascii_strcasecmp (p, "keys-only"))
295         t |= PGPKEY;
296
297       if (!t)
298         t |= PGPENCRYPT;        /* not necessarily correct, but... */
299     }
300
301     if (!ascii_strcasecmp (m->subtype, "pgp-signed"))
302       t |= PGPSIGN;
303
304     if (!ascii_strcasecmp (m->subtype, "pgp-keys"))
305       t |= PGPKEY;
306   }
307   else if (m->type == TYPETEXT && ascii_strcasecmp ("plain", m->subtype) == 0) {
308     if (((p = mutt_get_parameter ("x-mutt-action", m->parameter))
309          || (p = mutt_get_parameter ("x-action", m->parameter))
310          || (p = mutt_get_parameter ("action", m->parameter)))
311         && !ascii_strncasecmp ("pgp-sign", p, 8))
312       t |= PGPSIGN;
313     else if (p && !ascii_strncasecmp ("pgp-encrypt", p, 11))
314       t |= PGPENCRYPT;
315     else if (p && !ascii_strncasecmp ("pgp-keys", p, 7))
316       t |= PGPKEY;
317   }
318   if (t)
319     t |= PGPINLINE;
320
321   return t;
322 }
323
324 int mutt_is_application_smime (BODY * m)
325 {
326   char *t = NULL;
327   int len, complain = 0;
328
329   if (!m)
330     return 0;
331
332   if ((m->type & TYPEAPPLICATION) && m->subtype) {
333     /* S/MIME MIME types don't need x- anymore, see RFC2311 */
334     if (!ascii_strcasecmp (m->subtype, "x-pkcs7-mime") ||
335         !ascii_strcasecmp (m->subtype, "pkcs7-mime")) {
336       if ((t = mutt_get_parameter ("smime-type", m->parameter))) {
337         if (!ascii_strcasecmp (t, "enveloped-data"))
338           return SMIMEENCRYPT;
339         else if (!ascii_strcasecmp (t, "signed-data"))
340           return (SMIMESIGN | SMIMEOPAQUE);
341         else
342           return 0;
343       }
344       /* Netscape 4.7 uses 
345        * Content-Description: S/MIME Encrypted Message
346        * instead of Content-Type parameter
347        */
348       if (!ascii_strcasecmp (m->description, "S/MIME Encrypted Message"))
349         return SMIMEENCRYPT;
350       complain = 1;
351     }
352     else if (ascii_strcasecmp (m->subtype, "octet-stream"))
353       return 0;
354
355     t = mutt_get_parameter ("name", m->parameter);
356
357     if (!t)
358       t = m->d_filename;
359     if (!t)
360       t = m->filename;
361     if (!t) {
362       if (complain)
363         mutt_message (_
364                       ("S/MIME messages with no hints on content are unsupported."));
365       return 0;
366     }
367
368     /* no .p7c, .p10 support yet. */
369
370     len = m_strlen(t) - 4;
371     if (len > 0 && *(t + len) == '.') {
372       len++;
373       if (!ascii_strcasecmp ((t + len), "p7m"))
374 #if 0
375         return SMIMEENCRYPT;
376 #else
377         /* Not sure if this is the correct thing to do, but 
378            it's required for compatibility with Outlook */
379         return (SMIMESIGN | SMIMEOPAQUE);
380 #endif
381       else if (!ascii_strcasecmp ((t + len), "p7s"))
382         return (SMIMESIGN | SMIMEOPAQUE);
383     }
384   }
385
386   return 0;
387 }
388
389
390
391
392
393
394 int crypt_query (BODY * m)
395 {
396   int t = 0;
397
398   if (!m)
399     return 0;
400
401   if (m->type == TYPEAPPLICATION) {
402     t |= mutt_is_application_pgp (m);
403
404     t |= mutt_is_application_smime (m);
405     if (t && m->goodsig)
406       t |= GOODSIGN;
407     if (t && m->badsig)
408       t |= BADSIGN;
409   }
410   else if (m->type == TYPETEXT) {
411     t |= mutt_is_application_pgp (m);
412     if (t && m->goodsig)
413       t |= GOODSIGN;
414   }
415
416   if (m->type == TYPEMULTIPART) {
417     t |= mutt_is_multipart_encrypted (m);
418     t |= mutt_is_multipart_signed (m);
419
420     if (t && m->goodsig)
421       t |= GOODSIGN;
422   }
423
424   if (m->type == TYPEMULTIPART || m->type == TYPEMESSAGE) {
425     BODY *p;
426     int u, v, w;
427
428     u = m->parts ? 0xffffffff : 0;      /* Bits set in all parts */
429     w = 0;                      /* Bits set in any part  */
430
431     for (p = m->parts; p; p = p->next) {
432       v = crypt_query (p);
433       u &= v;
434       w |= v;
435     }
436     t |= u | (w & ~GOODSIGN);
437
438     if ((w & GOODSIGN) && !(u & GOODSIGN))
439       t |= PARTSIGN;
440   }
441
442   return t;
443 }
444
445
446
447
448 int crypt_write_signed (BODY * a, STATE * s, const char *tempfile)
449 {
450   FILE *fp;
451   int c;
452   short hadcr;
453   size_t bytes;
454
455   if (!(fp = safe_fopen (tempfile, "w"))) {
456     mutt_perror (tempfile);
457     return -1;
458   }
459
460   fseeko (s->fpin, a->hdr_offset, 0);
461   bytes = a->length + a->offset - a->hdr_offset;
462   hadcr = 0;
463   while (bytes > 0) {
464     if ((c = fgetc (s->fpin)) == EOF)
465       break;
466
467     bytes--;
468
469     if (c == '\r')
470       hadcr = 1;
471     else {
472       if (c == '\n' && !hadcr)
473         fputc ('\r', fp);
474
475       hadcr = 0;
476     }
477
478     fputc (c, fp);
479
480   }
481   fclose (fp);
482
483   return 0;
484 }
485
486
487
488 void convert_to_7bit (BODY * a)
489 {
490   while (a) {
491     if (a->type == TYPEMULTIPART) {
492       if (a->encoding != ENC7BIT) {
493         a->encoding = ENC7BIT;
494         convert_to_7bit (a->parts);
495       }
496       else if (option (OPTPGPSTRICTENC))
497         convert_to_7bit (a->parts);
498     }
499     else if (a->type == TYPEMESSAGE &&
500              m_strcasecmp(a->subtype, "delivery-status")) {
501       if (a->encoding != ENC7BIT)
502         mutt_message_to_7bit (a, NULL);
503     }
504     else if (a->encoding == ENC8BIT)
505       a->encoding = ENCQUOTEDPRINTABLE;
506     else if (a->encoding == ENCBINARY)
507       a->encoding = ENCBASE64;
508     else if (a->content && a->encoding != ENCBASE64 &&
509              (a->content->from || (a->content->space &&
510                                    option (OPTPGPSTRICTENC))))
511       a->encoding = ENCQUOTEDPRINTABLE;
512     a = a->next;
513   }
514 }
515
516
517
518
519 void crypt_extract_keys_from_messages (HEADER * h)
520 {
521   int i;
522   char tempfname[_POSIX_PATH_MAX], *mbox;
523   address_t *tmp = NULL;
524   FILE *fpout;
525
526   mutt_mktemp (tempfname);
527   if (!(fpout = safe_fopen (tempfname, "w"))) {
528     mutt_perror (tempfname);
529     return;
530   }
531
532   set_option (OPTDONTHANDLEPGPKEYS);
533
534   if (!h) {
535     for (i = 0; i < Context->vcount; i++) {
536       if (Context->hdrs[Context->v2r[i]]->tagged) {
537         mutt_parse_mime_message (Context, Context->hdrs[Context->v2r[i]]);
538         if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT &&
539             !crypt_valid_passphrase (Context->hdrs[Context->v2r[i]]->
540                                      security)) {
541           fclose (fpout);
542           break;
543         }
544
545         if (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP) {
546           mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
547                              M_CM_DECODE | M_CM_CHARCONV, 0);
548           fflush (fpout);
549
550           mutt_endwin (_("Trying to extract PGP keys...\n"));
551           crypt_pgp_invoke_import (tempfname);
552         }
553
554         if (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME) {
555           if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT)
556             mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
557                                M_CM_NOHEADER | M_CM_DECODE_CRYPT
558                                | M_CM_DECODE_SMIME, 0);
559           else
560             mutt_copy_message (fpout, Context,
561                                Context->hdrs[Context->v2r[i]], 0, 0);
562           fflush (fpout);
563
564           if (Context->hdrs[Context->v2r[i]]->env->from)
565             tmp = mutt_expand_aliases (h->env->from);
566           else if (Context->hdrs[Context->v2r[i]]->env->sender)
567             tmp = mutt_expand_aliases (Context->hdrs[Context->v2r[i]]
568                                        ->env->sender);
569           mbox = tmp ? tmp->mailbox : NULL;
570           if (mbox) {
571             mutt_endwin (_("Trying to extract S/MIME certificates...\n"));
572             crypt_smime_invoke_import (tempfname, mbox);
573             tmp = NULL;
574           }
575         }
576
577         rewind (fpout);
578       }
579     }
580   }
581   else {
582     mutt_parse_mime_message (Context, h);
583     if (!(h->security & ENCRYPT && !crypt_valid_passphrase (h->security))) {
584       if (h->security & APPLICATION_PGP) {
585         mutt_copy_message (fpout, Context, h, M_CM_DECODE | M_CM_CHARCONV, 0);
586         fflush (fpout);
587         mutt_endwin (_("Trying to extract PGP keys...\n"));
588         crypt_pgp_invoke_import (tempfname);
589       }
590
591       if (h->security & APPLICATION_SMIME) {
592         if (h->security & ENCRYPT)
593           mutt_copy_message (fpout, Context, h, M_CM_NOHEADER
594                              | M_CM_DECODE_CRYPT | M_CM_DECODE_SMIME, 0);
595         else
596           mutt_copy_message (fpout, Context, h, 0, 0);
597
598         fflush (fpout);
599         if (h->env->from)
600           tmp = mutt_expand_aliases (h->env->from);
601         else if (h->env->sender)
602           tmp = mutt_expand_aliases (h->env->sender);
603         mbox = tmp ? tmp->mailbox : NULL;
604         if (mbox) {             /* else ? */
605           mutt_message (_("Trying to extract S/MIME certificates...\n"));
606           crypt_smime_invoke_import (tempfname, mbox);
607         }
608       }
609     }
610   }
611
612   fclose (fpout);
613   if (isendwin ())
614     mutt_any_key_to_continue (NULL);
615
616   mutt_unlink (tempfname);
617
618   unset_option (OPTDONTHANDLEPGPKEYS);
619 }
620
621
622
623 int crypt_get_keys (HEADER * msg, char **keylist)
624 {
625   /* Do a quick check to make sure that we can find all of the encryption
626    * keys if the user has requested this service.
627    */
628
629   set_option (OPTPGPCHECKTRUST);
630
631   *keylist = NULL;
632
633   if (msg->security & ENCRYPT) {
634     if (msg->security & APPLICATION_PGP) {
635       if ((*keylist = crypt_pgp_findkeys (msg->env->to, msg->env->cc,
636                                           msg->env->bcc)) == NULL)
637         return (-1);
638       unset_option (OPTPGPCHECKTRUST);
639     }
640     if (msg->security & APPLICATION_SMIME) {
641       if ((*keylist = crypt_smime_findkeys (msg->env->to, msg->env->cc,
642                                             msg->env->bcc)) == NULL)
643         return (-1);
644     }
645   }
646
647   return (0);
648 }
649
650
651
652 static void crypt_fetch_signatures (BODY ***signatures, BODY * a, int *n)
653 {
654   for (; a; a = a->next) {
655     if (a->type == TYPEMULTIPART)
656       crypt_fetch_signatures (signatures, a->parts, n);
657     else {
658       if ((*n % 5) == 0)
659         p_realloc(signatures, *n + 6);
660
661       (*signatures)[(*n)++] = a;
662     }
663   }
664 }
665
666
667 /*
668  * This routine verifies a  "multipart/signed"  body.
669  */
670
671 int mutt_signed_handler (BODY * a, STATE * s)
672 {
673   char tempfile[_POSIX_PATH_MAX];
674   char *protocol;
675   int protocol_major = TYPEOTHER;
676   char *protocol_minor = NULL;
677
678   BODY *b = a;
679   BODY **signatures = NULL;
680   int sigcnt = 0;
681   int i;
682   short goodsig = 1;
683   int rc = 0;
684
685   protocol = mutt_get_parameter ("protocol", a->parameter);
686   a = a->parts;
687
688   /* extract the protocol information */
689
690   if (protocol) {
691     char major[STRING];
692     char *t;
693
694     if ((protocol_minor = strchr (protocol, '/')))
695       protocol_minor++;
696
697     m_strcpy(major, sizeof(major), protocol);
698     if ((t = strchr (major, '/')))
699       *t = '\0';
700
701     protocol_major = mutt_check_mime_type (major);
702   }
703
704   /* consistency check */
705
706   if (!(a && a->next && a->next->type == protocol_major &&
707         !m_strcasecmp(a->next->subtype, protocol_minor))) {
708     state_attach_puts (_("[-- Error: "
709                          "Inconsistent multipart/signed structure! --]\n\n"),
710                        s);
711     return mutt_body_handler (a, s);
712   }
713
714
715   if (protocol_major == TYPEAPPLICATION
716       && !m_strcasecmp(protocol_minor, "pgp-signature"));
717   else if (protocol_major == TYPEAPPLICATION
718            && !(m_strcasecmp(protocol_minor, "x-pkcs7-signature")
719                 && m_strcasecmp(protocol_minor, "pkcs7-signature")));
720   else if (protocol_major == TYPEMULTIPART
721            && !m_strcasecmp(protocol_minor, "mixed"));
722   else {
723     state_printf (s, _("[-- Error: "
724                        "Unknown multipart/signed protocol %s! --]\n\n"),
725                   protocol);
726     return mutt_body_handler (a, s);
727   }
728
729   if (s->flags & M_DISPLAY) {
730
731     crypt_fetch_signatures (&signatures, a->next, &sigcnt);
732
733     if (sigcnt) {
734       mutt_mktemp (tempfile);
735       if (crypt_write_signed (a, s, tempfile) == 0) {
736         for (i = 0; i < sigcnt; i++) {
737           if (signatures[i]->type == TYPEAPPLICATION
738               && !m_strcasecmp(signatures[i]->subtype, "pgp-signature")) {
739             if (crypt_pgp_verify_one (signatures[i], s, tempfile) != 0)
740               goodsig = 0;
741
742             continue;
743           }
744
745           if (signatures[i]->type == TYPEAPPLICATION
746           && (!m_strcasecmp(signatures[i]->subtype, "x-pkcs7-signature")
747                || !m_strcasecmp(signatures[i]->subtype, "pkcs7-signature")))
748           {
749             if (crypt_smime_verify_one (signatures[i], s, tempfile) != 0)
750               goodsig = 0;
751
752             continue;
753           }
754
755           state_printf (s, _("[-- Warning: "
756                              "We can't verify %s/%s signatures. --]\n\n"),
757                         TYPE (signatures[i]), signatures[i]->subtype);
758         }
759       }
760
761       mutt_unlink (tempfile);
762
763       b->goodsig = goodsig;
764       b->badsig = !goodsig;
765
766       /* Now display the signed body */
767       state_attach_puts (_("[-- The following data is signed --]\n\n"), s);
768
769
770       p_delete(&signatures);
771     }
772     else
773       state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"),
774                          s);
775   }
776
777   rc = mutt_body_handler (a, s);
778
779   if (s->flags & M_DISPLAY && sigcnt)
780     state_attach_puts (_("\n[-- End of signed data --]\n"), s);
781
782   return (rc);
783 }