summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2001-02-13 15:01:57 +0000
committerThomas Roessler <roessler@does-not-exist.org>2001-02-13 15:01:57 +0000
commit98c469edcf550b35640b6a97940343f52db976bb (patch)
tree9ebde66e6564185acf2ce401d6ac9781c1c30717
parentdf41a1bb1b7e0a519dfc5ee8c05778cc45aebf94 (diff)
Add a function check-traditional-pgp which can be used to handle
old-style PGP messages and/or parts more easily.
-rw-r--r--OPS.PGP1
-rw-r--r--commands.c40
-rw-r--r--curs_main.c11
-rw-r--r--functions.h6
-rw-r--r--pgp.c70
-rw-r--r--pgp.h1
-rw-r--r--protos.h1
-rw-r--r--recvattach.c30
8 files changed, 152 insertions, 8 deletions
diff --git a/OPS.PGP b/OPS.PGP
index 55add474..0eb8ac20 100644
--- a/OPS.PGP
+++ b/OPS.PGP
@@ -7,3 +7,4 @@ OP_VERIFY_KEY "verify a PGP public key"
OP_VIEW_ID "view the key's user id"
OP_DECRYPT_SAVE "make decrypted copy and delete"
OP_DECRYPT_COPY "make decrypted copy"
+OP_CHECK_TRADITIONAL "check for classic pgp"
diff --git a/commands.c b/commands.c
index f2ee3e45..f6cbcc7d 100644
--- a/commands.c
+++ b/commands.c
@@ -847,3 +847,43 @@ void mutt_edit_content_type (HEADER *h, BODY *b, FILE *fp)
#endif /* HAVE_PGP */
}
+
+
+#ifdef HAVE_PGP
+
+static int _mutt_check_traditional_pgp (HEADER *h, int *redraw)
+{
+ MESSAGE *msg;
+ int rv = 0;
+
+ mutt_parse_mime_message (Context, h);
+ if ((msg = mx_open_message (Context, h->msgno)) == NULL)
+ return 0;
+ if (pgp_check_traditional (msg->fp, h->content, 0))
+ {
+ h->pgp = pgp_query (h->content);
+ *redraw |= REDRAW_FULL;
+ rv = 1;
+ }
+
+ mx_close_message (&msg);
+ return rv;
+}
+
+int mutt_check_traditional_pgp (HEADER *h, int *redraw)
+{
+ int i;
+ int rv = 0;
+ if (h)
+ rv = _mutt_check_traditional_pgp (h, redraw);
+ else
+ {
+ for (i = 0; i < Context->vcount; i++)
+ if (Context->hdrs[Context->v2r[i]]->tagged)
+ rv = _mutt_check_traditional_pgp (Context->hdrs[Context->v2r[i]], redraw)
+ || rv;
+ }
+ return rv;
+}
+
+#endif
diff --git a/curs_main.c b/curs_main.c
index 2bb165a9..b28d9c50 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -1697,6 +1697,17 @@ int mutt_index_menu (void)
pgp_extract_keys_from_messages(tag ? NULL : CURHDR);
menu->redraw = REDRAW_FULL;
break;
+
+ case OP_CHECK_TRADITIONAL:
+
+ CHECK_MSGCOUNT;
+ mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
+ if (menu->menu == MENU_PAGER)
+ {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ break;
#endif /* HAVE_PGP */
diff --git a/functions.h b/functions.h
index 77c036b4..f1f813b6 100644
--- a/functions.h
+++ b/functions.h
@@ -136,6 +136,7 @@ struct binding_t OpMain[] = {
#ifdef HAVE_PGP
+ { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" },
{ "extract-keys", OP_EXTRACT_KEYS, "\013" },
{ "forget-passphrase", OP_FORGET_PASSPHRASE, "\006" },
{ "mail-key", OP_MAIL_KEY, "\033k" },
@@ -227,6 +228,7 @@ struct binding_t OpPager[] = {
#ifdef HAVE_PGP
+ { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" },
{ "extract-keys", OP_EXTRACT_KEYS, "\013" },
{ "forget-passphrase",OP_FORGET_PASSPHRASE, "\006" },
{ "mail-key", OP_MAIL_KEY, "\033k" },
@@ -261,7 +263,9 @@ struct binding_t OpAttach[] = {
#ifdef HAVE_PGP
- { "extract-keys", OP_EXTRACT_KEYS, "\013" },
+ { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" },
+ { "extract-keys", OP_EXTRACT_KEYS, "\013" },
+ { "forget-passphrase", OP_FORGET_PASSPHRASE, "\006" },
#endif
diff --git a/pgp.c b/pgp.c
index 0ec12ed9..91c5e61f 100644
--- a/pgp.c
+++ b/pgp.c
@@ -405,6 +405,76 @@ void pgp_application_pgp_handler (BODY *m, STATE *s)
}
+static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
+{
+ char tempfile[_POSIX_PATH_MAX];
+ char buf[HUGE_STRING];
+ FILE *tfp;
+
+ short sgn = 0;
+ short enc = 0;
+
+ if (b->type != TYPETEXT)
+ return 0;
+
+ if (tagged_only && !b->tagged)
+ return 0;
+
+ mutt_mktemp (tempfile);
+ if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0)
+ {
+ unlink (tempfile);
+ return 0;
+ }
+
+ if ((tfp = fopen (tempfile, "r")) == NULL)
+ {
+ unlink (tempfile);
+ return 0;
+ }
+
+ while (fgets (buf, sizeof (buf), tfp))
+ {
+ if (mutt_strncmp ("-----BEGIN PGP ", buf, 15) == 0)
+ {
+ if (mutt_strcmp ("MESSAGE-----\n", buf + 15) == 0)
+ enc = 1;
+ else if (mutt_strcmp ("SIGNED MESSAGE-----\n", buf + 15) == 0)
+ sgn = 1;
+ }
+ }
+
+ safe_fclose (&tfp);
+ unlink (tempfile);
+
+ if (!enc && !sgn)
+ return 0;
+
+ /* fix the content type */
+
+ b->type = TYPEAPPLICATION;
+ mutt_str_replace (&b->subtype, "pgp");
+
+ mutt_set_parameter ("format", "text", &b->parameter);
+ mutt_set_parameter ("x-action", enc ? "encrypt" : "sign", &b->parameter);
+
+ return 1;
+}
+
+int pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
+{
+ int rv = 0;
+ for (; b; b = b->next)
+ {
+ if (is_multipart (b))
+ rv = pgp_check_traditional (fp, b->parts, tagged_only) || rv;
+ else if (b->type == TYPETEXT)
+ rv = pgp_check_traditional_one_body (fp, b, tagged_only) || rv;
+ }
+
+ return rv;
+}
+
int mutt_is_multipart_signed (BODY *b)
{
char *p;
diff --git a/pgp.h b/pgp.h
index 05c1a9a8..dfb4fc57 100644
--- a/pgp.h
+++ b/pgp.h
@@ -46,6 +46,7 @@ WHERE char *PgpGetkeysCommand;
/* prototypes */
+int pgp_check_traditional (FILE *, BODY *, int);
BODY *pgp_decrypt_part (BODY *, STATE *, FILE *);
BODY *pgp_make_key_attachment (char *);
const char *pgp_micalg (const char *fname);
diff --git a/protos.h b/protos.h
index c29e8119..1e0bbe79 100644
--- a/protos.h
+++ b/protos.h
@@ -241,6 +241,7 @@ int mutt_check_menu (const char *);
int mutt_check_mime_type (const char *);
int mutt_check_month (const char *);
int mutt_check_overwrite (const char *, const char *, char *, size_t, int *);
+int mutt_check_traditional_pgp (HEADER *, int *);
int mutt_command_complete (char *, size_t, int, int);
int mutt_var_value_complete (char *, size_t, int);
int mutt_complete (char *, size_t);
diff --git a/recvattach.c b/recvattach.c
index a1de0dda..9b704847 100644
--- a/recvattach.c
+++ b/recvattach.c
@@ -766,7 +766,9 @@ mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr,
}
op = OP_VIEW_ATTACH;
break;
+ /* functions which are passed through from the pager */
case OP_ATTACH_COLLAPSE:
+ case OP_CHECK_TRADITIONAL:
if (recv)
return op;
default:
@@ -842,7 +844,7 @@ void mutt_view_attachments (HEADER *hdr)
short idxlen = 0;
short idxmax = 0;
int flags = 0;
- int op;
+ int op = OP_NULL;
/* make sure we have parsed this message */
mutt_parse_mime_message (Context, hdr);
@@ -890,7 +892,9 @@ void mutt_view_attachments (HEADER *hdr)
FOREVER
{
- switch (op = mutt_menuLoop (menu))
+ if (op == OP_NULL)
+ op = mutt_menuLoop (menu);
+ switch (op)
{
case OP_ATTACH_VIEW_MAILCAP:
mutt_view_attachment (fp, idx[menu->current]->content, M_MAILCAP,
@@ -908,11 +912,8 @@ void mutt_view_attachments (HEADER *hdr)
case OP_VIEW_ATTACH:
op = mutt_attach_display_loop (menu, op, fp, hdr, cur, &idx, &idxlen, &idxmax, 1);
menu->redraw = REDRAW_FULL;
- if (op != OP_ATTACH_COLLAPSE)
- break;
- if (!idx[menu->current]->content->collapsed)
- break;
- /* else fall through - hack! */
+ continue;
+
case OP_ATTACH_COLLAPSE:
if (!idx[menu->current]->content->parts)
{
@@ -928,11 +929,24 @@ void mutt_view_attachments (HEADER *hdr)
#ifdef HAVE_PGP
+ case OP_FORGET_PASSPHRASE:
+ mutt_forget_passphrase ();
+ break;
+
case OP_EXTRACT_KEYS:
pgp_extract_keys_from_attachment_list (fp, menu->tagprefix,
menu->tagprefix ? cur : idx[menu->current]->content);
menu->redraw = REDRAW_FULL;
break;
+
+ case OP_CHECK_TRADITIONAL:
+ if (pgp_check_traditional (fp, menu->tagprefix ? cur : idx[menu->current]->content,
+ menu->tagprefix))
+ {
+ hdr->pgp = pgp_query (cur);
+ menu->redraw = REDRAW_FULL;
+ }
+ break;
#endif
@@ -1119,6 +1133,8 @@ void mutt_view_attachments (HEADER *hdr)
mutt_menuDestroy (&menu);
return;
}
+
+ op = OP_NULL;
}
/* not reached */