- fprintf (pgpin, "%s\n", PgpPass);
- }
-
- safe_fclose (&pgpin);
-
- if (s->flags & M_DISPLAY)
- {
- crypt_current_time (s, "PGP");
- rc = pgp_copy_checksig (pgperr, s->fpout);
- }
-
- safe_fclose (&pgperr);
- rv = mutt_wait_filter (thepid);
-
- if (s->flags & M_DISPLAY)
- {
- if (rc == 0) have_any_sigs = 1;
-/*
- * Sig is bad if
- * gpg_good_sign-pattern did not match || pgp_decode_command returned not 0
- * Sig _is_ correct if
- * gpg_good_sign="" && pgp_decode_command returned 0
- */
- if (rc == -1 || rv) maybe_goodsig = 0;
-
- state_putc ('\n', s);
- state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
- }
- }
+ fprintf (pgpin, "%s\n", PgpPass);
+ }
+
+ safe_fclose (&pgpin);
+
+ if (s->flags & M_DISPLAY) {
+ crypt_current_time (s, "PGP");
+ rc = pgp_copy_checksig (pgperr, s->fpout);
+ }
+
+ safe_fclose (&pgperr);
+ rv = mutt_wait_filter (thepid);
+
+ if (s->flags & M_DISPLAY) {
+ if (rc == 0)
+ have_any_sigs = 1;
+
+ /*
+ * Sig is bad if
+ * gpg_good_sign-pattern did not match || pgp_decode_command returned not 0
+ * Sig _is_ correct if
+ * gpg_good_sign="" && pgp_decode_command returned 0
+ */
+ if (rc == -1 || rv)
+ maybe_goodsig = 0;
+
+ state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
+ }
+ }
+
+ /* treat empty result as sign of failure */
+ /* TODO: maybe on failure mutt should include the original undecoded text. */
+ if (pgpout) {
+ rewind (pgpout);
+ c = fgetc (pgpout);
+ ungetc (c, pgpout);
+ }
+ if (!clearsign && (!pgpout || c == EOF)) {
+ mutt_error _("Could not decrypt PGP message");
+ mutt_sleep (1);
+ pgp_void_passphrase ();
+ if (!(s->flags & M_DISPLAY)) {
+ rc = -1;
+ goto out;
+ }
+ }