]> granicus.if.org Git - mutt/commitdiff
Add a function check-traditional-pgp which can be used to handle
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 13 Feb 2001 15:01:57 +0000 (15:01 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 13 Feb 2001 15:01:57 +0000 (15:01 +0000)
old-style PGP messages and/or parts more easily.

OPS.PGP
commands.c
curs_main.c
functions.h
pgp.c
pgp.h
protos.h
recvattach.c

diff --git a/OPS.PGP b/OPS.PGP
index 55add47464b8ae71edfb9866b715f144ec58782c..0eb8ac20ba723eb5f18e037e36dcf07a646e8bb2 100644 (file)
--- 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"
index f2ee3e4524a64285c1f3cc09036e624ec2b4c843..f6cbcc7dc17848f6510d62a3c070ea2d58a585e0 100644 (file)
@@ -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
index 2bb165a9d1cee98c7720f0940f58f5d379ea1560..b28d9c50285894d24e14e24b58c93a9e9d081290 100644 (file)
@@ -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 */
 
index 77c036b4ff96d66f1b854d1bc4cc679e74ca7eef..f1f813b6a2cffac4a993f403bb192c76d7cd79bd 100644 (file)
@@ -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 0ec12ed9d3ce4ee269ea6d7a75f34b1edfaa438b..91c5e61fd852587dbc30fc1e98d8d1814d04c80d 100644 (file)
--- 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 05c1a9a864df3501d8153d887e741bf385b7bf2e..dfb4fc57a3c871b36e7c8dbc44df9afaf1099a83 100644 (file)
--- 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);
index c29e8119a176a6cdb34733804ca8d3cd5ecb1529..1e0bbe793186c027ed05946cc85c7c6b065c3ccc 100644 (file)
--- 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);
index a1de0ddad585e7bfcb8a695e44a544563dd7a862..9b7048473cf382b9876e0ab29048f02632393d6b 100644 (file)
@@ -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 */