<<< Date Index >>>     <<< Thread Index >>>

[PATCH] introduce error codes to mutt body handlers, for decode-save



Here's a patch that should close #1919 (decode-save may delete a
message even if it wasn't successfully decoded or decrypted). It
touches quite a bit more code than would be ideal (albeit in fairly
trivial ways), so I'd appreciate another set of eyes.
Index: copy.c
===================================================================
RCS file: /home/roessler/cvs/mutt/copy.c,v
retrieving revision 3.21
diff -u -p -r3.21 copy.c
--- copy.c      9 Aug 2005 16:10:40 -0000       3.21
+++ copy.c      10 Aug 2005 17:25:08 -0000
@@ -546,6 +546,7 @@ _mutt_copy_message (FILE *fpout, FILE *f
   char prefix[SHORT_STRING];
   STATE s;
   long new_offset = -1;
+  int rc = 0;
 
   if (flags & M_CM_PREFIX)
   {
@@ -657,7 +658,7 @@ _mutt_copy_message (FILE *fpout, FILE *f
     if (WithCrypto && flags & M_CM_VERIFY)
       s.flags |= M_VERIFY;
 
-    mutt_body_handler (body, &s);
+    rc = mutt_body_handler (body, &s);
   }
   else if (WithCrypto
            && (flags & M_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT))
@@ -725,7 +726,7 @@ _mutt_copy_message (FILE *fpout, FILE *f
     mutt_free_body (&body->parts);
   }
 
-  return 0;
+  return rc;
 }
 
 int
Index: crypt-gpgme.c
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt-gpgme.c,v
retrieving revision 3.6
diff -u -p -r3.6 crypt-gpgme.c
--- crypt-gpgme.c       9 Aug 2005 16:24:15 -0000       3.6
+++ crypt-gpgme.c       10 Aug 2005 17:25:10 -0000
@@ -1882,7 +1882,7 @@ static void copy_clearsigned (gpgme_data
 
 
 /* Support for classic_application/pgp */
-void pgp_gpgme_application_handler (BODY *m, STATE *s)
+int pgp_gpgme_application_handler (BODY *m, STATE *s)
 {
   int needpass = -1, pgp_keyblock = 0;
   int clearsign = 0;
@@ -1891,7 +1891,7 @@ void pgp_gpgme_application_handler (BODY
   char buf[HUGE_STRING];
   FILE *pgpout = NULL;
 
-  gpgme_error_t err;
+  gpgme_error_t err = 0;
   gpgme_data_t armored_data = NULL;
 
   short maybe_goodsig = 1;
@@ -2130,9 +2130,11 @@ void pgp_gpgme_application_handler (BODY
     {
       state_attach_puts (_("[-- Error: could not find beginning"
                            " of PGP message! --]\n\n"), s);
-      return;
+      return -1;
     }
   dprint (2, (debugfile, "Leaving pgp_application_pgp handler\n"));
+
+  return err;
 }
 
 /* 
@@ -2140,13 +2142,14 @@ void pgp_gpgme_application_handler (BODY
  */
 
 /* MIME handler for pgp/mime encrypted messages. */
-void pgp_gpgme_encrypted_handler (BODY *a, STATE *s)
+int pgp_gpgme_encrypted_handler (BODY *a, STATE *s)
 {
   char tempfile[_POSIX_PATH_MAX];
   FILE *fpout;
   BODY *tattach;
   BODY *orig_body = a;
   int is_signed;
+  int rc = 0;
   
   dprint (2, (debugfile, "Entering pgp_encrypted handler\n"));
   a = a->parts;
@@ -2158,7 +2161,7 @@ void pgp_gpgme_encrypted_handler (BODY *
       if (s->flags & M_DISPLAY)
         state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"),
                            s);
-      return;
+      return -1;
     }
 
   /* Move forward to the application/pgp-encrypted body. */
@@ -2170,7 +2173,7 @@ void pgp_gpgme_encrypted_handler (BODY *
       if (s->flags & M_DISPLAY)
         state_attach_puts (_("[-- Error: could not create temporary file! "
                              "--]\n"), s);
-      return;
+      return -1;
     }
 
   tattach = decrypt_part (a, s, fpout, 0, &is_signed);
@@ -2187,7 +2190,7 @@ void pgp_gpgme_encrypted_handler (BODY *
       {
         FILE *savefp = s->fpin;
         s->fpin = fpout;
-        mutt_body_handler (tattach, s);
+        rc = mutt_body_handler (tattach, s);
         s->fpin = savefp;
       }
 
@@ -2214,16 +2217,18 @@ void pgp_gpgme_encrypted_handler (BODY *
   fclose (fpout);
   mutt_unlink(tempfile);
   dprint (2, (debugfile, "Leaving pgp_encrypted handler\n"));
+
+  return rc;
 }
 
 /* Support for application/smime */
-void smime_gpgme_application_handler (BODY *a, STATE *s)
+int smime_gpgme_application_handler (BODY *a, STATE *s)
 {
   char tempfile[_POSIX_PATH_MAX];
   FILE *fpout;
   BODY *tattach;
   int is_signed;
-
+  int rc = 0;
 
   dprint (2, (debugfile, "Entering smime_encrypted handler\n"));
   
@@ -2234,7 +2239,7 @@ void smime_gpgme_application_handler (BO
       if (s->flags & M_DISPLAY)
         state_attach_puts (_("[-- Error: could not create temporary file! "
                              "--]\n"), s);
-      return;
+      return -1;
     }
 
   tattach = decrypt_part (a, s, fpout, 1, &is_signed);
@@ -2251,7 +2256,7 @@ void smime_gpgme_application_handler (BO
       {
         FILE *savefp = s->fpin;
         s->fpin = fpout;
-        mutt_body_handler (tattach, s);
+        rc = mutt_body_handler (tattach, s);
         s->fpin = savefp;
       }
 
@@ -2286,6 +2291,8 @@ void smime_gpgme_application_handler (BO
   fclose (fpout);
   mutt_unlink(tempfile);
   dprint (2, (debugfile, "Leaving smime_encrypted handler\n"));
+  
+  return rc;
 }
 
 
Index: crypt-gpgme.h
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt-gpgme.h,v
retrieving revision 3.1
diff -u -p -r3.1 crypt-gpgme.h
--- crypt-gpgme.h       28 Jan 2005 13:17:22 -0000      3.1
+++ crypt-gpgme.h       10 Aug 2005 17:25:10 -0000
@@ -35,9 +35,9 @@ int smime_gpgme_decrypt_mime (FILE *fpin
 
 int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only);
 
-void pgp_gpgme_application_handler (BODY *m, STATE *s);
-void smime_gpgme_application_handler (BODY *a, STATE *s);
-void pgp_gpgme_encrypted_handler (BODY *a, STATE *s);
+int pgp_gpgme_application_handler (BODY *m, STATE *s);
+int smime_gpgme_application_handler (BODY *a, STATE *s);
+int pgp_gpgme_encrypted_handler (BODY *a, STATE *s);
 
 BODY *pgp_gpgme_make_key_attachment (char *tempf);
 
@@ -50,4 +50,5 @@ int smime_gpgme_verify_one (BODY *sigbdy
 int pgp_gpgme_send_menu (HEADER *msg, int *redraw);
 int smime_gpgme_send_menu (HEADER *msg, int *redraw);
 
+int smime_gpgme_verify_sender (HEADER *h);
 #endif
Index: crypt-mod-pgp-classic.c
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt-mod-pgp-classic.c,v
retrieving revision 3.2
diff -u -p -r3.2 crypt-mod-pgp-classic.c
--- crypt-mod-pgp-classic.c     3 Feb 2005 17:01:43 -0000       3.2
+++ crypt-mod-pgp-classic.c     10 Aug 2005 17:25:10 -0000
@@ -41,9 +41,9 @@ static int crypt_mod_pgp_decrypt_mime (F
 {
   return pgp_decrypt_mime (a, b, c, d);
 }
-static void crypt_mod_pgp_application_handler (BODY *m, STATE *s)
+static int crypt_mod_pgp_application_handler (BODY *m, STATE *s)
 {
-  pgp_application_pgp_handler (m, s);
+  return pgp_application_pgp_handler (m, s);
 }
 
 static char *crypt_mod_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
@@ -86,9 +86,9 @@ static BODY *crypt_mod_pgp_traditional_e
   return pgp_traditional_encryptsign (a, flags, keylist);
 }
 
-static void crypt_mod_pgp_encrypted_handler (BODY *m, STATE *s)
+static int crypt_mod_pgp_encrypted_handler (BODY *m, STATE *s)
 {
-  pgp_encrypted_handler (m, s);
+  return pgp_encrypted_handler (m, s);
 }
 
 static void crypt_mod_pgp_invoke_getkeys (ADDRESS *addr)
Index: crypt-mod-pgp-gpgme.c
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt-mod-pgp-gpgme.c,v
retrieving revision 3.2
diff -u -p -r3.2 crypt-mod-pgp-gpgme.c
--- crypt-mod-pgp-gpgme.c       3 Feb 2005 17:01:43 -0000       3.2
+++ crypt-mod-pgp-gpgme.c       10 Aug 2005 17:25:10 -0000
@@ -50,14 +50,14 @@ static int crypt_mod_pgp_decrypt_mime (F
   return pgp_gpgme_decrypt_mime (a, b, c, d);
 }
 
-static void crypt_mod_pgp_application_handler (BODY *m, STATE *s)
+static int crypt_mod_pgp_application_handler (BODY *m, STATE *s)
 {
-  pgp_gpgme_application_handler (m, s);
+  return pgp_gpgme_application_handler (m, s);
 }
 
-static void crypt_mod_pgp_encrypted_handler (BODY *m, STATE *s)
+static int crypt_mod_pgp_encrypted_handler (BODY *m, STATE *s)
 {
-  pgp_gpgme_encrypted_handler (m, s);
+  return pgp_gpgme_encrypted_handler (m, s);
 }
 
 static int crypt_mod_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
Index: crypt-mod-smime-classic.c
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt-mod-smime-classic.c,v
retrieving revision 3.2
diff -u -p -r3.2 crypt-mod-smime-classic.c
--- crypt-mod-smime-classic.c   3 Feb 2005 17:01:43 -0000       3.2
+++ crypt-mod-smime-classic.c   10 Aug 2005 17:25:10 -0000
@@ -41,9 +41,9 @@ static int crypt_mod_smime_decrypt_mime 
 {
   return smime_decrypt_mime (a, b, c, d);
 }
-static void crypt_mod_smime_application_handler (BODY *m, STATE *s)
+static int crypt_mod_smime_application_handler (BODY *m, STATE *s)
 {
-  smime_application_smime_handler (m, s);
+  return smime_application_smime_handler (m, s);
 }
 
 static char *crypt_mod_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
Index: crypt-mod-smime-gpgme.c
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt-mod-smime-gpgme.c,v
retrieving revision 3.2
diff -u -p -r3.2 crypt-mod-smime-gpgme.c
--- crypt-mod-smime-gpgme.c     3 Feb 2005 17:01:43 -0000       3.2
+++ crypt-mod-smime-gpgme.c     10 Aug 2005 17:25:10 -0000
@@ -50,9 +50,9 @@ static int crypt_mod_smime_decrypt_mime 
   return smime_gpgme_decrypt_mime (a, b, c, d);
 }
 
-static void crypt_mod_smime_application_handler (BODY *m, STATE *s)
+static int crypt_mod_smime_application_handler (BODY *m, STATE *s)
 {
-  smime_gpgme_application_handler (m, s);
+  return smime_gpgme_application_handler (m, s);
 }
 
 static char *crypt_mod_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
Index: crypt-mod.h
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt-mod.h,v
retrieving revision 3.1
diff -u -p -r3.1 crypt-mod.h
--- crypt-mod.h 17 Jun 2004 20:36:13 -0000      3.1
+++ crypt-mod.h 10 Aug 2005 17:25:10 -0000
@@ -34,8 +34,8 @@ typedef int (*crypt_func_valid_passphras
 typedef int (*crypt_func_decrypt_mime_t) (FILE *a, FILE **b,
                                           BODY *c, BODY **d);
 
-typedef void (*crypt_func_application_handler_t) (BODY *m, STATE *s);
-typedef void (*crypt_func_encrypted_handler_t) (BODY *m, STATE *s);
+typedef int (*crypt_func_application_handler_t) (BODY *m, STATE *s);
+typedef int (*crypt_func_encrypted_handler_t) (BODY *m, STATE *s);
 
 typedef void (*crypt_func_pgp_invoke_getkeys_t) (ADDRESS *addr);
 typedef int (*crypt_func_pgp_check_traditional_t) (FILE *fp, BODY *b,
Index: crypt.c
===================================================================
RCS file: /home/roessler/cvs/mutt/crypt.c,v
retrieving revision 3.28
diff -u -p -r3.28 crypt.c
--- crypt.c     24 Jun 2005 22:32:38 -0000      3.28
+++ crypt.c     10 Aug 2005 17:25:10 -0000
@@ -758,7 +758,7 @@ static void crypt_fetch_signatures (BODY
  * This routine verifies a  "multipart/signed"  body.
  */
 
-void mutt_signed_handler (BODY *a, STATE *s)
+int mutt_signed_handler (BODY *a, STATE *s)
 {
   char tempfile[_POSIX_PATH_MAX];
   char *protocol;
@@ -770,9 +770,10 @@ void mutt_signed_handler (BODY *a, STATE
   int sigcnt = 0;
   int i;
   short goodsig = 1;
+  int rc = 0;
 
   if (!WithCrypto)
-    return;
+    return -1;
 
   protocol = mutt_get_parameter ("protocol", a->parameter);
   a = a->parts;
@@ -801,8 +802,7 @@ void mutt_signed_handler (BODY *a, STATE
     state_attach_puts (_("[-- Error: "
                          "Inconsistent multipart/signed structure! --]\n\n"),
                        s);
-    mutt_body_handler (a, s);
-    return;
+    return mutt_body_handler (a, s);
   }
 
   
@@ -823,8 +823,7 @@ void mutt_signed_handler (BODY *a, STATE
     state_printf (s, _("[-- Error: "
                        "Unknown multipart/signed protocol %s! --]\n\n"),
                   protocol);
-    mutt_body_handler (a, s);
-    return;
+    return mutt_body_handler (a, s);
   }
   
   if (s->flags & M_DISPLAY)
@@ -881,10 +880,12 @@ void mutt_signed_handler (BODY *a, STATE
       state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"), 
s);
   }
   
-  mutt_body_handler (a, s);
+  rc = mutt_body_handler (a, s);
   
   if (s->flags & M_DISPLAY && sigcnt)
     state_attach_puts (_("\n[-- End of signed data --]\n"), s);
+  
+  return rc;
 }
 
 
Index: cryptglue.c
===================================================================
RCS file: /home/roessler/cvs/mutt/cryptglue.c,v
retrieving revision 3.5
diff -u -p -r3.5 cryptglue.c
--- cryptglue.c 3 Feb 2005 17:01:43 -0000       3.5
+++ cryptglue.c 10 Aug 2005 17:25:11 -0000
@@ -147,17 +147,21 @@ int crypt_pgp_decrypt_mime (FILE *a, FIL
 }
 
 /* MIME handler for the application/pgp content-type. */
-void crypt_pgp_application_pgp_handler (BODY *m, STATE *s)
+int crypt_pgp_application_pgp_handler (BODY *m, STATE *s)
 {
   if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
-    (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
+    return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
+  
+  return -1;
 }
 
 /* MIME handler for an PGP/MIME encrypted message. */
-void crypt_pgp_encrypted_handler (BODY *a, STATE *s)
+int crypt_pgp_encrypted_handler (BODY *a, STATE *s)
 {
   if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
-    (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
+    return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
+  
+  return -1;
 }
 
 /* fixme: needs documentation. */
@@ -290,10 +294,12 @@ int crypt_smime_decrypt_mime (FILE *a, F
 }
 
 /* MIME handler for the application/smime content-type. */
-void crypt_smime_application_smime_handler (BODY *m, STATE *s)
+int crypt_smime_application_smime_handler (BODY *m, STATE *s)
 {
   if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
-    (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
+    return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
+  
+  return -1;
 }
 
 /* MIME handler for an PGP/MIME encrypted message. */
Index: handler.c
===================================================================
RCS file: /home/roessler/cvs/mutt/handler.c,v
retrieving revision 3.19
diff -u -p -r3.19 handler.c
--- handler.c   3 Feb 2005 17:01:43 -0000       3.19
+++ handler.c   10 Aug 2005 17:25:11 -0000
@@ -41,8 +41,7 @@
 #define BUFO_SIZE 2000
 
 
-typedef void handler_f (BODY *, STATE *);
-typedef handler_f *handler_t;
+typedef int (*handler_t) (BODY *, STATE *);
 
 int Index_hex[128] = {
     -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
@@ -767,7 +766,7 @@ static void enriched_set_flags (const ch
   }
 }
 
-void text_enriched_handler (BODY *a, STATE *s)
+int text_enriched_handler (BODY *a, STATE *s)
 {
   enum {
     TEXT, LANGLE, TAG, BOGUS_TAG, NEWLINE, ST_EOF, DONE
@@ -889,6 +888,8 @@ void text_enriched_handler (BODY *a, STA
   FREE (&(stte.buffer));
   FREE (&(stte.line));
   FREE (&(stte.param));
+
+  return 0;
 }                                                                              
 
 /*
@@ -963,7 +964,7 @@ static int flowed_visual_strlen (char *l
   return j;
 }
 
-static void text_plain_flowed_handler (BODY *a, STATE *s)
+static int text_plain_flowed_handler (BODY *a, STATE *s)
 {
   char line[LONG_STRING];
   char indent[LONG_STRING];
@@ -1185,7 +1186,8 @@ static void text_plain_flowed_handler (B
 
   if (col)
     state_putc ('\n', s);
-  
+
+  return 0;
 }
 
 
@@ -1197,7 +1199,7 @@ static void text_plain_flowed_handler (B
 #define TXTPLAIN    2
 #define TXTENRICHED 3
 
-static void alternative_handler (BODY *a, STATE *s)
+static int alternative_handler (BODY *a, STATE *s)
 {
   BODY *choice = NULL;
   BODY *b;
@@ -1205,6 +1207,7 @@ static void alternative_handler (BODY *a
   char buf[STRING];
   int type = 0;
   int mustfree = 0;
+  int rc = 0;
 
   if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE ||
       a->encoding == ENCUUENCODED)
@@ -1347,18 +1350,22 @@ static void alternative_handler (BODY *a
     /* didn't find anything that we could display! */
     state_mark_attach (s);
     state_puts(_("[-- Error:  Could not display any parts of 
Multipart/Alternative! --]\n"), s);
+    rc = -1;
   }
 
   if (mustfree)
     mutt_free_body(&a);
+
+  return rc;
 }
 
 /* handles message/rfc822 body parts */
-void message_handler (BODY *a, STATE *s)
+int message_handler (BODY *a, STATE *s)
 {
   struct stat st;
   BODY *b;
   long off_start;
+  int rc = 0;
 
   off_start = ftell (s->fpin);
   if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE || 
@@ -1382,12 +1389,14 @@ void message_handler (BODY *a, STATE *s)
       state_puts (s->prefix, s);
     state_putc ('\n', s);
 
-    mutt_body_handler (b->parts, s);
+    rc = mutt_body_handler (b->parts, s);
   }
 
   if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE ||
       a->encoding == ENCUUENCODED)
     mutt_free_body (&b);
+  
+  return rc;
 }
 
 /* returns 1 if decoding the attachment will produce output */
@@ -1431,12 +1440,13 @@ int mutt_can_decode (BODY *a)
   return (0);
 }
 
-void multipart_handler (BODY *a, STATE *s)
+int multipart_handler (BODY *a, STATE *s)
 {
   BODY *b, *p;
   char length[5];
   struct stat st;
   int count;
+  int rc = 0;
 
   if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE ||
       a->encoding == ENCUUENCODED)
@@ -1487,19 +1497,21 @@ void multipart_handler (BODY *a, STATE *
        state_printf(s, "%s: \n", p->form_name);
 
     }
-    mutt_body_handler (p, s);
+    rc = mutt_body_handler (p, s);
     state_putc ('\n', s);
-    if ((s->flags & M_REPLYING)
-       && (option (OPTINCLUDEONLYFIRST)) && (s->flags & M_FIRSTDONE))
+    if (rc || ((s->flags & M_REPLYING)
+               && (option (OPTINCLUDEONLYFIRST)) && (s->flags & M_FIRSTDONE)))
       break;
   }
 
   if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE ||
       a->encoding == ENCUUENCODED)
     mutt_free_body (&b);
+  
+  return rc;
 }
 
-void autoview_handler (BODY *a, STATE *s)
+int autoview_handler (BODY *a, STATE *s)
 {
   rfc1524_entry *entry = rfc1524_new_entry ();
   char buffer[LONG_STRING];
@@ -1512,6 +1524,7 @@ void autoview_handler (BODY *a, STATE *s
   FILE *fperr = NULL;
   int piped = FALSE;
   pid_t thepid;
+  int rc = 0;
 
   snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype);
   rfc1524_mailcap_lookup (a, type, entry, M_AUTOVIEW);
@@ -1539,7 +1552,7 @@ void autoview_handler (BODY *a, STATE *s
     {
       mutt_perror ("fopen");
       rfc1524_free_entry (&entry);
-      return;
+      return -1;
     }
     
     mutt_copy_bytes (s->fpin, fpin, a->length);
@@ -1566,6 +1579,7 @@ void autoview_handler (BODY *a, STATE *s
        state_mark_attach (s);
        state_printf (s, _("[-- Can't run %s. --]\n"), command);
       }
+      rc = -1;
       goto bail;
     }
     
@@ -1626,9 +1640,11 @@ void autoview_handler (BODY *a, STATE *s
       mutt_clear_error ();
   }
   rfc1524_free_entry (&entry);
+
+  return rc;
 }
 
-static void external_body_handler (BODY *b, STATE *s)
+static int external_body_handler (BODY *b, STATE *s)
 {
   const char *access_type;
   const char *expiration;
@@ -1642,7 +1658,7 @@ static void external_body_handler (BODY 
       state_mark_attach (s);
       state_puts (_("[-- Error: message/external-body has no access-type 
parameter --]\n"), s);
     }
-    return;
+    return -1;
   }
 
   expiration = mutt_get_parameter ("expiration", b->parameter);
@@ -1718,6 +1734,8 @@ static void external_body_handler (BODY 
                     CH_DECODE , NULL);
     }
   }
+  
+  return 0;
 }
 
 void mutt_decode_attachment (BODY *b, STATE *s)
@@ -1753,7 +1771,7 @@ void mutt_decode_attachment (BODY *b, ST
     iconv_close (cd);
 }
 
-void mutt_body_handler (BODY *b, STATE *s)
+int mutt_body_handler (BODY *b, STATE *s)
 {
   int decode = 0;
   int plaintext = 0;
@@ -1763,6 +1781,7 @@ void mutt_body_handler (BODY *b, STATE *
   long tmpoffset = 0;
   size_t tmplength = 0;
   char type[STRING];
+  int rc = 0;
 
   int oflags = s->flags;
   
@@ -1913,7 +1932,7 @@ void mutt_body_handler (BODY *b, STATE *
     /* process the (decoded) body part */
     if (handler)
     {
-      handler (b, s);
+      rc = handler (b, s);
 
       if (decode)
       {
@@ -1941,7 +1960,9 @@ void mutt_body_handler (BODY *b, STATE *
     }
     fputs (" --]\n", s->fpout);
   }
-  
+
   bail:
   s->flags = oflags | (s->flags & M_FIRSTDONE);
+
+  return rc;
 }
Index: mutt_crypt.h
===================================================================
RCS file: /home/roessler/cvs/mutt/mutt_crypt.h,v
retrieving revision 3.8
diff -u -p -r3.8 mutt_crypt.h
--- mutt_crypt.h        17 Jun 2004 20:36:13 -0000      3.8
+++ mutt_crypt.h        10 Aug 2005 17:25:11 -0000
@@ -117,7 +117,7 @@ int mutt_is_application_pgp (BODY *);
 
 int mutt_is_application_smime (BODY *);
 
-void mutt_signed_handler (BODY *, STATE *);
+int mutt_signed_handler (BODY *, STATE *);
 
 int mutt_parse_crypt_hdr (char *, int);
 
@@ -171,10 +171,10 @@ int crypt_pgp_valid_passphrase (void);
 int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d);
 
 /* MIME handler for the application/pgp content-type. */
-void crypt_pgp_application_pgp_handler (BODY *m, STATE *s);
+int crypt_pgp_application_pgp_handler (BODY *m, STATE *s);
 
 /* MIME handler for an PGP/MIME encrypted message. */
-void crypt_pgp_encrypted_handler (BODY *a, STATE *s);
+int crypt_pgp_encrypted_handler (BODY *a, STATE *s);
 
 /* fixme: needs documentation. */
 void crypt_pgp_invoke_getkeys (ADDRESS *addr);
@@ -233,7 +233,7 @@ int crypt_smime_valid_passphrase (void);
 int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d);
 
 /* MIME handler for the application/smime content-type. */
-void crypt_smime_application_smime_handler (BODY *m, STATE *s);
+int crypt_smime_application_smime_handler (BODY *m, STATE *s);
 
 /* fixme: Needs documentation. */
 void crypt_smime_getkeys (ENVELOPE *env);
Index: pgp.c
===================================================================
RCS file: /home/roessler/cvs/mutt/pgp.c,v
retrieving revision 3.49
diff -u -p -r3.49 pgp.c
--- pgp.c       9 Aug 2005 17:41:31 -0000       3.49
+++ pgp.c       10 Aug 2005 17:25:12 -0000
@@ -233,7 +233,7 @@ static void pgp_copy_clearsigned (FILE *
 
 /* Support for the Application/PGP Content Type. */
 
-void pgp_application_pgp_handler (BODY *m, STATE *s)
+int pgp_application_pgp_handler (BODY *m, STATE *s)
 {
   int needpass = -1, pgp_keyblock = 0;
   int clearsign = 0, rv, rc;
@@ -300,7 +300,7 @@ void pgp_application_pgp_handler (BODY *
       if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL)
       {
        mutt_perror (tmpfname);
-       return;
+       return -1;
       }
       
       fputs (buf, tmpfp);
@@ -330,7 +330,7 @@ void pgp_application_pgp_handler (BODY *
        if ((pgpout = safe_fopen (outfile, "w+")) == NULL)
        {
          mutt_perror (tmpfname);
-         return;
+         return -1;
        }
        
        if ((thepid = pgp_invoke_decode (&pgpin, NULL, &pgperr, -1,
@@ -384,6 +384,7 @@ void pgp_application_pgp_handler (BODY *
         {
           mutt_error _("Could not decrypt PGP message");
           pgp_void_passphrase ();
+          rc = -1;
           
           goto out;
         }
@@ -446,6 +447,8 @@ void pgp_application_pgp_handler (BODY *
     }
   }
 
+  rc = 0;
+
 out:
   m->goodsig = (maybe_goodsig && have_any_sigs);
 
@@ -463,8 +466,10 @@ out:
   if (needpass == -1)
   {
     state_attach_puts (_("[-- Error: could not find beginning of PGP message! 
--]\n\n"), s);
-    return;
+    return -1;
   }
+  
+  return rc;
 }
 
 static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
@@ -816,7 +821,11 @@ BODY *pgp_decrypt_part (BODY *a, STATE *
   rewind (fpout);
   
   if (fgetc (fpout) == EOF)
+  {
+    mutt_error _("Decryption failed");
+    pgp_void_passphrase ();
     return NULL;
+  }
 
   rewind (fpout);
   
@@ -870,12 +879,13 @@ int pgp_decrypt_mime (FILE *fpin, FILE *
   return (0);
 }
 
-void pgp_encrypted_handler (BODY *a, STATE *s)
+int pgp_encrypted_handler (BODY *a, STATE *s)
 {
   char tempfile[_POSIX_PATH_MAX];
   FILE *fpout, *fpin;
   BODY *tattach;
   BODY *p = a;
+  int rc = 0;
   
   a = a->parts;
   if (!a || a->type != TYPEAPPLICATION || !a->subtype || 
@@ -885,7 +895,7 @@ void pgp_encrypted_handler (BODY *a, STA
   {
     if (s->flags & M_DISPLAY)
       state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"), 
s);
-    return;
+    return -1;
   }
 
   /*
@@ -898,7 +908,7 @@ void pgp_encrypted_handler (BODY *a, STA
   {
     if (s->flags & M_DISPLAY)
       state_attach_puts (_("[-- Error: could not create temporary file! 
--]\n"), s);
-    return;
+    return -1;
   }
 
   if (s->flags & M_DISPLAY) crypt_current_time (s, "PGP");
@@ -910,7 +920,7 @@ void pgp_encrypted_handler (BODY *a, STA
 
     fpin = s->fpin;
     s->fpin = fpout;
-    mutt_body_handler (tattach, s);
+    rc = mutt_body_handler (tattach, s);
     s->fpin = fpin;
 
     /* 
@@ -938,10 +948,13 @@ void pgp_encrypted_handler (BODY *a, STA
     mutt_error _("Could not decrypt PGP message");
     /* void the passphrase, even if it's not necessarily the problem */
     pgp_void_passphrase ();
+    rc = -1;
   }
 
   fclose (fpout);
   mutt_unlink(tempfile);
+
+  return rc;
 }
 
 /* ----------------------------------------------------------------------------
Index: pgp.h
===================================================================
RCS file: /home/roessler/cvs/mutt/pgp.h,v
retrieving revision 3.6
diff -u -p -r3.6 pgp.h
--- pgp.h       17 Jun 2004 20:36:13 -0000      3.6
+++ pgp.h       10 Aug 2005 17:25:12 -0000
@@ -52,8 +52,8 @@ pgp_key_t pgp_getkeybystr (char *, short
 char *pgp_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc);
 
 void pgp_forget_passphrase (void);
-void pgp_application_pgp_handler (BODY *, STATE *);
-void pgp_encrypted_handler (BODY *, STATE *);
+int pgp_application_pgp_handler (BODY *, STATE *);
+int pgp_encrypted_handler (BODY *, STATE *);
 void pgp_extract_keys_from_attachment_list (FILE * fp, int tag, BODY * top);
 void pgp_void_passphrase (void);
 int pgp_valid_passphrase (void);
Index: protos.h
===================================================================
RCS file: /home/roessler/cvs/mutt/protos.h,v
retrieving revision 3.33
diff -u -p -r3.33 protos.h
--- protos.h    7 Aug 2005 16:45:35 -0000       3.33
+++ protos.h    10 Aug 2005 17:25:13 -0000
@@ -161,7 +161,7 @@ void mutt_allow_interrupt (int);
 void mutt_attach_init (BODY *);
 void mutt_block_signals (void);
 void mutt_block_signals_system (void);
-void mutt_body_handler (BODY *, STATE *);
+int mutt_body_handler (BODY *, STATE *);
 int  mutt_bounce_message (FILE *fp, HEADER *, ADDRESS *);
 void mutt_break_thread (HEADER *);
 void mutt_buffy (char *, size_t);
Index: smime.c
===================================================================
RCS file: /home/roessler/cvs/mutt/smime.c,v
retrieving revision 3.39
diff -u -p -r3.39 smime.c
--- smime.c     24 Jul 2005 14:23:25 -0000      3.39
+++ smime.c     10 Aug 2005 17:25:14 -0000
@@ -1929,11 +1929,9 @@ bail:
 }
 
 
-void smime_application_smime_handler (BODY *m, STATE *s)
+int smime_application_smime_handler (BODY *m, STATE *s)
 {
-    
-    smime_handle_entity (m, s, NULL);
-
+  return smime_handle_entity (m, s, NULL) ? 0 : -1;
 }
 
 int smime_send_menu (HEADER *msg, int *redraw)
Index: smime.h
===================================================================
RCS file: /home/roessler/cvs/mutt/smime.h,v
retrieving revision 3.10
diff -u -p -r3.10 smime.h
--- smime.h     17 Jun 2004 20:36:13 -0000      3.10
+++ smime.h     10 Aug 2005 17:25:14 -0000
@@ -31,7 +31,7 @@ int smime_valid_passphrase (void);
 
 int   smime_decrypt_mime (FILE *, FILE **, BODY *, BODY **);
 
-void  smime_application_smime_handler (BODY *, STATE *);
+int  smime_application_smime_handler (BODY *, STATE *);
 
 
 BODY* smime_sign_message (BODY *);

Attachment: pgp4kLE5PcU5a.pgp
Description: PGP signature