From: Brendan Cully Date: Thu, 11 Aug 2005 21:16:38 +0000 (+0000) Subject: Add error results to mutt_body_handlers, and check them when doing X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23072f9bfae9f6a02fda72050d6d441c1a37f1a6;p=neomutt Add error results to mutt_body_handlers, and check them when doing decode-save. Closes: #1919. --- diff --git a/copy.c b/copy.c index a5777c083..8dbec08c6 100644 --- a/copy.c +++ b/copy.c @@ -546,6 +546,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, 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 *fpin, HEADER *hdr, BODY *body, 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 *fpin, HEADER *hdr, BODY *body, mutt_free_body (&body->parts); } - return 0; + return rc; } int diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 54773b690..feb28ed93 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -1882,7 +1882,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE *s, char *charset) /* 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 *m, STATE *s) 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 *m, STATE *s) { 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 *m, STATE *s) */ /* 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 *a, STATE *s) 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 *a, STATE *s) 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 *a, STATE *s) { 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 *a, STATE *s) 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 (BODY *a, STATE *s) 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 (BODY *a, STATE *s) { 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 (BODY *a, STATE *s) fclose (fpout); mutt_unlink(tempfile); dprint (2, (debugfile, "Leaving smime_encrypted handler\n")); + + return rc; } diff --git a/crypt-gpgme.h b/crypt-gpgme.h index 49013515d..0d66ddff7 100644 --- a/crypt-gpgme.h +++ b/crypt-gpgme.h @@ -35,9 +35,9 @@ int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur); 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, STATE *s, const char *tempfile); 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 diff --git a/crypt-mod-pgp-classic.c b/crypt-mod-pgp-classic.c index e6e3bc809..d3b471b61 100644 --- a/crypt-mod-pgp-classic.c +++ b/crypt-mod-pgp-classic.c @@ -41,9 +41,9 @@ static int crypt_mod_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) { 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_encryptsign (BODY *a, int flags, char *ke 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) diff --git a/crypt-mod-pgp-gpgme.c b/crypt-mod-pgp-gpgme.c index bab9663a4..45e5b9c81 100644 --- a/crypt-mod-pgp-gpgme.c +++ b/crypt-mod-pgp-gpgme.c @@ -50,14 +50,14 @@ static int crypt_mod_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) 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) diff --git a/crypt-mod-smime-classic.c b/crypt-mod-smime-classic.c index cff63b240..0d038732e 100644 --- a/crypt-mod-smime-classic.c +++ b/crypt-mod-smime-classic.c @@ -41,9 +41,9 @@ static int crypt_mod_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) { 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) diff --git a/crypt-mod-smime-gpgme.c b/crypt-mod-smime-gpgme.c index 761dec913..8b180c2b9 100644 --- a/crypt-mod-smime-gpgme.c +++ b/crypt-mod-smime-gpgme.c @@ -50,9 +50,9 @@ static int crypt_mod_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) 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) diff --git a/crypt-mod.h b/crypt-mod.h index 4f69c3e85..133b784bc 100644 --- a/crypt-mod.h +++ b/crypt-mod.h @@ -34,8 +34,8 @@ typedef int (*crypt_func_valid_passphrase_t) (void); 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, diff --git a/crypt.c b/crypt.c index dfe64d376..ca2fb0472 100644 --- a/crypt.c +++ b/crypt.c @@ -758,7 +758,7 @@ static void crypt_fetch_signatures (BODY ***signatures, BODY *a, int *n) * 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 *s) 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 *s) 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 *s) 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 *s) 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; } diff --git a/cryptglue.c b/cryptglue.c index f6a1bab35..e98e8625f 100644 --- a/cryptglue.c +++ b/cryptglue.c @@ -147,17 +147,21 @@ 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) { 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, 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) { 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. */ diff --git a/handler.c b/handler.c index 8dfb769dd..e7c3e3230 100644 --- a/handler.c +++ b/handler.c @@ -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 char *tag, struct enriched_state *stte) } } -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, STATE *s) FREE (&(stte.buffer)); FREE (&(stte.line)); FREE (&(stte.param)); + + return 0; } /* @@ -963,7 +964,7 @@ static int flowed_visual_strlen (char *l, int i) 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 (BODY *a, STATE *s) if (col) state_putc ('\n', s); - + + return 0; } @@ -1197,7 +1199,7 @@ static void text_plain_flowed_handler (BODY *a, STATE *s) #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, STATE *s) 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, STATE *s) /* 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 *s) 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 *b, STATE *s) 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 *b, STATE *s) CH_DECODE , NULL); } } + + return 0; } void mutt_decode_attachment (BODY *b, STATE *s) @@ -1753,7 +1771,7 @@ void mutt_decode_attachment (BODY *b, STATE *s) 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 *s) 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 *s) /* 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 *s) } fputs (" --]\n", s->fpout); } - + bail: s->flags = oflags | (s->flags & M_FIRSTDONE); + + return rc; } diff --git a/mutt_crypt.h b/mutt_crypt.h index 6b57382ec..acb356fe0 100644 --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -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); diff --git a/pgp.c b/pgp.c index 587ab73cb..ac482baad 100644 --- a/pgp.c +++ b/pgp.c @@ -233,7 +233,7 @@ static void pgp_copy_clearsigned (FILE *fpin, STATE *s, char *charset) /* 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; @@ -301,7 +301,7 @@ void pgp_application_pgp_handler (BODY *m, STATE *s) if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL) { mutt_perror (tmpfname); - return; + return -1; } fputs (buf, tmpfp); @@ -331,7 +331,7 @@ void pgp_application_pgp_handler (BODY *m, STATE *s) if ((pgpout = safe_fopen (outfile, "w+")) == NULL) { mutt_perror (tmpfname); - return; + return -1; } if ((thepid = pgp_invoke_decode (&pgpin, NULL, &pgperr, -1, @@ -386,6 +386,7 @@ void pgp_application_pgp_handler (BODY *m, STATE *s) { mutt_error _("Could not decrypt PGP message"); pgp_void_passphrase (); + rc = -1; goto out; } @@ -449,6 +450,8 @@ void pgp_application_pgp_handler (BODY *m, STATE *s) } } + rc = 0; + out: m->goodsig = (maybe_goodsig && have_any_sigs); @@ -466,8 +469,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) @@ -819,7 +824,11 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p) rewind (fpout); if (fgetc (fpout) == EOF) + { + mutt_error _("Decryption failed"); + pgp_void_passphrase (); return NULL; + } rewind (fpout); @@ -873,12 +882,13 @@ int pgp_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) 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 || @@ -888,7 +898,7 @@ void pgp_encrypted_handler (BODY *a, STATE *s) { if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"), s); - return; + return -1; } /* @@ -901,7 +911,7 @@ void pgp_encrypted_handler (BODY *a, STATE *s) { 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"); @@ -913,7 +923,7 @@ void pgp_encrypted_handler (BODY *a, STATE *s) fpin = s->fpin; s->fpin = fpout; - mutt_body_handler (tattach, s); + rc = mutt_body_handler (tattach, s); s->fpin = fpin; /* @@ -941,10 +951,13 @@ void pgp_encrypted_handler (BODY *a, STATE *s) 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; } /* ---------------------------------------------------------------------------- diff --git a/pgp.h b/pgp.h index 31718720d..52d930f5b 100644 --- a/pgp.h +++ b/pgp.h @@ -52,8 +52,8 @@ pgp_key_t pgp_getkeybystr (char *, short, pgp_ring_t); 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); diff --git a/protos.h b/protos.h index 5b23ee4bb..faa6a2fa0 100644 --- a/protos.h +++ b/protos.h @@ -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); diff --git a/smime.c b/smime.c index 7cbd987ab..476484e4c 100644 --- a/smime.c +++ b/smime.c @@ -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) diff --git a/smime.h b/smime.h index dba0a0fc4..138129455 100644 --- a/smime.h +++ b/smime.h @@ -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 *);