Decryption: Pager and Dec-Copy (Re: [2005-10-11] CVS repository changes)
(May be related to PR #1919 and #2110 ?)
> 2005-10-10 18:26:31 Brendan Cully <brendan@xxxxxxxxxx> (brendan)
>
> * pgp.c: Make PGP decode failure non-fatal when displaying
> messages (as opposed to decode-saving them). I think it would be
> nicer to include the original text when decryption fails though...
So, you would find something useful in this attached patch.
0. Fall-through to raw message.
Pager will show encrypted text if decryption fails.
Decode-save/copy will copy encrypted msg as text/plain if decryption fails.
Decrypt-save/copy will copy encrypted msg as multi/enc if decryption fails.
1. Another return-value.
Current mutt:
Pager will fail to display a message (*) if copy_msg returns non-zero.
Decode/decrypt-save won't delete if copy_msg returns non-zero.
After patched:
Pager will fail to display a message (*) only if copy_msg returns -1.
Decode/decrypt-save won't delete if copy_msg returns non-zero.
Errors non-fatal for displaying will return 1 instead of -1.
(*) so all states ("[-- Error: ...--]") will be devnull'ed.
P.S.
Still, some users could complain; "I tagged a number of messages and
tried to decode-save them, and one of them failed to decrypt. But the
error-message was too ambiguous. I couldn't know what was wrong."
Neither the current mutt nor this patch cares this issue AFAIK.
--
tamo
diff -r 4c45a538cc33 copy.c
--- a/copy.c Tue Oct 11 07:04:24 2005
+++ b/copy.c Wed Oct 12 23:46:37 2005
@@ -671,7 +671,7 @@
hdr->content->type == TYPEMULTIPART)
{
if (crypt_pgp_decrypt_mime (fpin, &fp, hdr->content, &cur))
- return (-1);
+ rc = 1;
fputs ("MIME-Version: 1.0\n", fpout);
}
@@ -680,21 +680,33 @@
&& hdr->content->type == TYPEAPPLICATION)
{
if (crypt_smime_decrypt_mime (fpin, &fp, hdr->content, &cur))
- return (-1);
- }
-
- mutt_write_mime_header (cur, fpout);
- fputc ('\n', fpout);
-
- fseek (fp, cur->offset, 0);
- if (mutt_copy_bytes (fp, fpout, cur->length) == -1)
- {
+ rc = 1;
+ }
+
+ /* if decryption failed, copy it as is */
+ if (rc == 1)
+ {
+ mutt_write_mime_header (body, fpout);
+ fputc ('\n', fpout);
+ fseek (fpin, body->offset, 0);
+ if (mutt_copy_bytes (fpin, fpout, body->length) == -1)
+ return -1;
+ }
+ else
+ {
+ mutt_write_mime_header (cur, fpout);
+ fputc ('\n', fpout);
+
+ fseek (fp, cur->offset, 0);
+ if (mutt_copy_bytes (fp, fpout, cur->length) == -1)
+ {
+ fclose (fp);
+ mutt_free_body (&cur);
+ return (-1);
+ }
+ mutt_free_body (&cur);
fclose (fp);
- mutt_free_body (&cur);
- return (-1);
- }
- mutt_free_body (&cur);
- fclose (fp);
+ }
}
else
{
diff -r 4c45a538cc33 crypt.c
--- a/crypt.c Tue Oct 11 07:04:24 2005
+++ b/crypt.c Wed Oct 12 23:46:37 2005
@@ -773,7 +773,7 @@
int rc = 0;
if (!WithCrypto)
- return -1;
+ return 1;
protocol = mutt_get_parameter ("protocol", a->parameter);
a = a->parts;
@@ -802,7 +802,7 @@
state_attach_puts (_("[-- Error: "
"Inconsistent multipart/signed structure! --]\n\n"),
s);
- return mutt_body_handler (a, s);
+ return (1 | mutt_body_handler (a, s));
}
@@ -823,7 +823,7 @@
state_printf (s, _("[-- Error: "
"Unknown multipart/signed protocol %s! --]\n\n"),
protocol);
- return mutt_body_handler (a, s);
+ return (1 | mutt_body_handler (a, s));
}
if (s->flags & M_DISPLAY)
diff -r 4c45a538cc33 cryptglue.c
--- a/cryptglue.c Tue Oct 11 07:04:24 2005
+++ b/cryptglue.c Wed Oct 12 23:46:37 2005
@@ -152,7 +152,7 @@
if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
- return -1;
+ return 1;
}
/* MIME handler for an PGP/MIME encrypted message. */
@@ -161,7 +161,7 @@
if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
- return -1;
+ return 1;
}
/* fixme: needs documentation. */
@@ -299,14 +299,7 @@
if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
- return -1;
-}
-
-/* MIME handler for an PGP/MIME encrypted message. */
-void crypt_smime_encrypted_handler (BODY *a, STATE *s)
-{
- if (CRYPT_MOD_CALL_CHECK (SMIME, encrypted_handler))
- (CRYPT_MOD_CALL (SMIME, encrypted_handler)) (a, s);
+ return 1;
}
/* fixme: Needs documentation. */
diff -r 4c45a538cc33 handler.c
--- a/handler.c Tue Oct 11 07:04:24 2005
+++ b/handler.c Wed Oct 12 23:46:37 2005
@@ -1350,7 +1350,7 @@
/* 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;
+ rc = 1;
}
if (mustfree)
@@ -1497,9 +1497,9 @@
state_printf(s, "%s: \n", p->form_name);
}
- rc = mutt_body_handler (p, s);
+ rc |= mutt_body_handler (p, s);
state_putc ('\n', s);
- if (rc || ((s->flags & M_REPLYING)
+ if ((rc == -1) || ((s->flags & M_REPLYING)
&& (option (OPTINCLUDEONLYFIRST)) && (s->flags & M_FIRSTDONE)))
break;
}
@@ -1579,7 +1579,7 @@
state_mark_attach (s);
state_printf (s, _("[-- Can't run %s. --]\n"), command);
}
- rc = -1;
+ rc = 1;
goto bail;
}
@@ -1649,6 +1649,7 @@
const char *access_type;
const char *expiration;
time_t expire;
+ int rc = 0;
access_type = mutt_get_parameter ("access-type", b->parameter);
if (!access_type)
@@ -1658,7 +1659,7 @@
state_mark_attach (s);
state_puts (_("[-- Error: message/external-body has no access-type
parameter --]\n"), s);
}
- return -1;
+ return 1;
}
expiration = mutt_get_parameter ("expiration", b->parameter);
@@ -1669,6 +1670,7 @@
if (!ascii_strcasecmp (access_type, "x-mutt-deleted"))
{
+ rc = 1;
if (s->flags & (M_DISPLAY|M_PRINTING))
{
char *length;
@@ -1704,6 +1706,7 @@
}
else if(expiration && expire < time(NULL))
{
+ rc = 1;
if (s->flags & M_DISPLAY)
{
state_mark_attach (s);
@@ -1719,6 +1722,7 @@
}
else
{
+ rc = 1;
if (s->flags & M_DISPLAY)
{
state_mark_attach (s);
@@ -1735,7 +1739,7 @@
}
}
- return 0;
+ return rc;
}
void mutt_decode_attachment (BODY *b, STATE *s)
@@ -1840,7 +1844,10 @@
p = mutt_get_parameter ("protocol", b->parameter);
if (!p)
+ {
+ rc = 1;
mutt_error _("Error: multipart/signed has no protocol.");
+ }
else if (s->flags & M_VERIFY)
handler = mutt_signed_handler;
}
@@ -1850,7 +1857,10 @@
p = mutt_get_parameter ("protocol", b->parameter);
if (!p)
+ {
+ rc = 1;
mutt_error _("Error: multipart/encrypted has no protocol parameter!");
+ }
else if (ascii_strcasecmp ("application/pgp-encrypted", p) == 0)
handler = crypt_pgp_encrypted_handler;
}
@@ -1890,6 +1900,7 @@
mutt_mktemp (tempfile);
if ((s->fpout = safe_fopen (tempfile, "w")) == NULL)
{
+ rc = -1;
mutt_error _("Unable to open temporary file!");
goto bail;
}
@@ -1934,7 +1945,7 @@
/* process the (decoded) body part */
if (handler)
{
- rc = handler (b, s);
+ rc |= handler (b, s);
if (decode)
{
@@ -1950,6 +1961,7 @@
}
else if (s->flags & M_DISPLAY)
{
+ rc = 1;
state_mark_attach (s);
state_printf (s, _("[-- %s/%s is unsupported "), TYPE (b), b->subtype);
if (!option (OPTVIEWATTACH))
@@ -1962,6 +1974,8 @@
}
fputs (" --]\n", s->fpout);
}
+ else
+ rc = 1;
bail:
s->flags = oflags | (s->flags & M_FIRSTDONE);
diff -r 4c45a538cc33 pager.c
--- a/pager.c Tue Oct 11 07:04:24 2005
+++ b/pager.c Wed Oct 12 23:46:37 2005
@@ -2548,7 +2548,8 @@
0,
&redraw) == 0 && (ch == OP_SAVE || ch ==
OP_DECODE_SAVE
|| ch == OP_DECRYPT_SAVE
- ))
+ )
+ == (-1))
{
if (option (OPTRESOLVE))
{
diff -r 4c45a538cc33 pgp.c
--- a/pgp.c Tue Oct 11 07:04:24 2005
+++ b/pgp.c Wed Oct 12 23:46:37 2005
@@ -401,11 +401,9 @@
mutt_sleep (1);
pgp_void_passphrase ();
+ rc = 1;
if (!(s->flags & M_DISPLAY))
- {
- rc = -1;
goto out;
- }
}
}
@@ -449,7 +447,8 @@
if (needpass)
{
state_attach_puts (_("[-- END PGP MESSAGE --]\n"), s);
- mutt_message _("PGP message successfully decrypted.");
+ if (!rc)
+ mutt_message _("PGP message successfully decrypted.");
}
else if (pgp_keyblock)
state_attach_puts (_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s);
@@ -466,8 +465,6 @@
}
}
- rc = 0;
-
out:
m->goodsig = (maybe_goodsig && have_any_sigs);
@@ -485,7 +482,7 @@
if (needpass == -1)
{
state_attach_puts (_("[-- Error: could not find beginning of PGP message!
--]\n\n"), s);
- return -1;
+ return 1;
}
return rc;
@@ -914,7 +911,7 @@
{
if (s->flags & M_DISPLAY)
state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"),
s);
- return -1;
+ return 1;
}
/*
@@ -927,7 +924,7 @@
{
if (s->flags & M_DISPLAY)
state_attach_puts (_("[-- Error: could not create temporary file!
--]\n"), s);
- return -1;
+ return 1;
}
if (s->flags & M_DISPLAY) crypt_current_time (s, "PGP");
@@ -964,10 +961,14 @@
}
else
{
+ /* copy as is */
+ fseek (s->fpin, a->offset, 0);
+ mutt_copy_bytes (s->fpin, s->fpout, a->length);
+
mutt_error _("Could not decrypt PGP message");
/* void the passphrase, even if it's not necessarily the problem */
pgp_void_passphrase ();
- rc = -1;
+ rc = 1;
}
fclose (fpout);
diff -r 4c45a538cc33 smime.c
--- a/smime.c Tue Oct 11 07:04:24 2005
+++ b/smime.c Wed Oct 12 23:46:37 2005
@@ -1931,7 +1931,7 @@
int smime_application_smime_handler (BODY *m, STATE *s)
{
- return smime_handle_entity (m, s, NULL) ? 0 : -1;
+ return smime_handle_entity (m, s, NULL) ? 0 : 1;
}
int smime_send_menu (HEADER *msg, int *redraw)