]> granicus.if.org Git - mutt/commitdiff
[patch-0.94.5i.tlr.pgp_fixes.1] This patch fixes various
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 7 Sep 1998 20:40:51 +0000 (20:40 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 7 Sep 1998 20:40:51 +0000 (20:40 +0000)
pgp-related issues.  In particular, mutt won't segfault
when trying to decrypt-save messages from the index, and
the presence of a PGP-encrypted body part on the
attachment menu will no longer confuse the MIME parser.

commands.c
handler.c
lib.c
pgp.c
pgp.h
recvattach.c
sendlib.c

index cef869cfc64e23978779613a5bc84e2dd28c0e24..3718a2b0bf0335345013c9940a1e3cb9452ab42e 100644 (file)
@@ -512,28 +512,27 @@ void mutt_display_address (ADDRESS *adr)
 static void set_copy_flags(HEADER *hdr, int decode, int decrypt, int *cmflags, int *chflags)
 {
   *cmflags = 0;
-  *chflags = decode ? CH_XMIT | CH_MIME : CH_UPDATE_LEN;
+  *chflags = CH_UPDATE_LEN;
   
 #ifdef _PGPPATH
   if(!decode && decrypt && (hdr->pgp & PGPENCRYPT))
   {
-    if(hdr->content->type == TYPEMULTIPART)
+    if(mutt_is_multipart_encrypted(hdr->content))
     {
-      *chflags |= CH_NONEWLINE;
+      *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME;
       *cmflags = M_CM_DECODE_PGP;
     }
-    else if((hdr->content->type == TYPEAPPLICATION) && mutt_is_pgp_subtype(hdr->content->subtype))
+    else if(mutt_is_application_pgp(hdr->content) & PGPENCRYPT)
       decode = 1;
   }
 #endif
 
   if(decode)
   {
-    *chflags |= CH_TXTPLAIN;
-    *cmflags |= M_CM_DECODE;
+    *chflags = CH_MIME | CH_TXTPLAIN;
+    *cmflags = M_CM_DECODE;
   }
 
-  
 }
 
 static void _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int decrypt)
@@ -541,9 +540,10 @@ static void _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode,
   int cmflags, chflags;
   
   set_copy_flags(h, decode, decrypt, &cmflags, &chflags);
-  if (decode)
+
+  if (decode  || decrypt)
     mutt_parse_mime_message (Context, h);
-  
+
   if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0 && delete)
   {
     mutt_set_flag (Context, h, M_DELETE, 1);
@@ -597,10 +597,6 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redr
     }
   }
 
-  if((decrypt || decode) && need_passphrase && 
-     !pgp_valid_passphrase())
-    return -1;
-
   mutt_pretty_mailbox (buf);
   if (mutt_enter_fname (prompt, buf, sizeof (buf), redraw, 0) == -1)
     return (-1);
@@ -615,7 +611,7 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redr
 
   if (!buf[0])
     return (-1);
-  
   /* This is an undocumented feature of ELM pointed out to me by Felix von
    * Leitner <leitner@prz.fu-berlin.de>
    */
@@ -633,6 +629,9 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redr
     return (-1);
   }
 
+  if(need_passphrase && (decode || decrypt) && !pgp_valid_passphrase())
+    return -1;
+  
   mutt_message ("Copying to %s...", buf);
   
   if (mx_open_mailbox (buf, M_APPEND, &ctx) != NULL)
index 6575a573d00256c22af20419ae477c417e79ebdd..eeebed74adaf78efdc838d49b7c6f52a4a75eb82 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -934,9 +934,7 @@ int mutt_can_decode (BODY *a)
 #ifdef _PGPPATH
   else if (a->type == TYPEAPPLICATION)
   {
-    if (mutt_is_pgp_subtype(a->subtype) || 
-       strcasecmp (a->subtype, "pgp-signed") == 0 ||
-       strcasecmp (a->subtype, "pgp-keys") == 0)
+    if (mutt_is_application_pgp(a))
       return (1);
   }
 #endif
@@ -1241,10 +1239,7 @@ void mutt_body_handler (BODY *b, STATE *s)
 #ifdef _PGPPATH
   else if (b->type == TYPEAPPLICATION)
   {
-    if (mutt_is_pgp_subtype(b->subtype) || 
-       strcasecmp ("pgp-signed", b->subtype) == 0 ||
-       strcasecmp ("pgp-keys", b->subtype) == 0)
-      
+    if (mutt_is_application_pgp(b))
       handler = application_pgp_handler;
   }
 #endif /* _PGPPATH */
diff --git a/lib.c b/lib.c
index 13d2faaf8637e33e48f040d38996b30db2f7f19a..79d901fa7d1e02ce439c53b91ab96e13d3a9964d 100644 (file)
--- a/lib.c
+++ b/lib.c
 #include "mailbox.h"
 #include "mx.h"
 
+#ifdef _PGPPATH
+#include "pgp.h"
+#endif
+
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
@@ -396,16 +400,12 @@ int mutt_needs_mailcap (BODY *m)
 
 #ifdef _PGPPATH
     case TYPEAPPLICATION:
-
-      if (!strcasecmp ("pgp", m->subtype) ||
-         !strcasecmp ("pgp-signed", m->subtype) ||
-         !strcasecmp ("x-pgp-message", m->subtype))
+      if(mutt_is_application_pgp(m))
        return 0;
       break;
 #endif /* _PGPPATH */
 
 
-
     case TYPEMULTIPART:
     case TYPEMESSAGE:
 
diff --git a/pgp.c b/pgp.c
index 0b0fcf5f06df16c9144f23670387b16d4fc47580..58d7348b9041eedc1ed14d1e75ad7d503e18f867 100644 (file)
--- a/pgp.c
+++ b/pgp.c
@@ -479,24 +479,38 @@ void application_pgp_handler (BODY *m, STATE *s)
 
 }
 
-int mutt_is_pgp_subtype(const char *st)
+int mutt_is_multipart_signed(BODY *b)
 {
-  if(st)
-  {
-    if(!strcasecmp(st, "pgp"))               return 1;
-    if(!strcasecmp(st, "x-pgp-message"))      return 1;
-  }
+  char *p;
   
-  return 0;
+  if(!b || b->type != TYPEMULTIPART ||
+     !b->subtype || strcasecmp(b->subtype, "signed") ||
+     !(p = mutt_get_parameter("protocol", b->parameter)) ||
+     strcasecmp(p, "application/pgp-signature"))
+    return 0;
+
+  return PGPSIGN;
 }
+   
+     
+int mutt_is_multipart_encrypted(BODY *b)
+{
+  char *p;
   
+  if(!b || b->type != TYPEMULTIPART ||
+     !b->subtype || strcasecmp(b->subtype, "encrypted") ||
+     !(p = mutt_get_parameter("protocol", b->parameter)) ||
+     strcasecmp(p, "application/pgp-encrypted")) 
+    return 0;
+  
+  return PGPENCRYPT;
+}
 
-int pgp_query (BODY *m)
+int mutt_is_application_pgp(BODY *m)
 {
-  char *p;
   int t = 0;
-
-  /* Check for old-style APPLICATION/PGP messages */
+  char *p;
+  
   if (m->type == TYPEAPPLICATION)
   {
     if (!strcasecmp (m->subtype, "pgp") || !strcasecmp (m->subtype, "x-pgp-message"))
@@ -521,17 +535,21 @@ int pgp_query (BODY *m)
     if (!strcasecmp (m->subtype, "pgp-keys"))
       t |= PGPKEY;
   }
+  return t;
+}
 
+int pgp_query (BODY *m)
+{
+  int t = 0;
+
+  t |= mutt_is_application_pgp(m);
+  
   /* Check for PGP/MIME messages. */
   if (m->type == TYPEMULTIPART)
   {
-    if (strcasecmp (m->subtype, "signed") == 0 &&
-       (p = mutt_get_parameter("protocol", m->parameter)) &&
-       strcasecmp (p, "application/pgp-signature") == 0)
+    if(mutt_is_multipart_signed(m))
       t |= PGPSIGN;
-    else if ((strcasecmp (m->subtype, "encrypted") == 0) && 
-            (p = mutt_get_parameter ("protocol", m->parameter)) &&
-            strcasecmp (p, "application/pgp-encrypted") == 0)
+    else if (mutt_is_multipart_encrypted(m))
       t |= PGPENCRYPT;
   }
 
@@ -908,7 +926,10 @@ int pgp_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur)
 {
   char tempfile[_POSIX_PATH_MAX];
   STATE s;
-
+  
+  if(!mutt_is_multipart_encrypted(b))
+    return -1;
+  
   memset (&s, 0, sizeof (s));
   s.fpin = fpin;
   mutt_mktemp (tempfile);
diff --git a/pgp.h b/pgp.h
index 5a69f32a2443e6fce0da005f4b8fb0a2d9bed44c..7438484591f1906704048ade7447f3a07d8b733f 100644 (file)
--- a/pgp.h
+++ b/pgp.h
@@ -166,7 +166,9 @@ struct pgp_vinfo *pgp_get_vinfo(enum pgp_ops);
 int mutt_check_pgp (HEADER *h);
 int mutt_parse_pgp_hdr (char *, int);
 
-int mutt_is_pgp_subtype(const char *);
+int mutt_is_multipart_encrypted(BODY *);
+int mutt_is_multipart_signed(BODY *);
+int mutt_is_application_pgp(BODY *);
 
 int pgp_decrypt_mime (FILE *, FILE **, BODY *, BODY **);
 int pgp_get_keys (HEADER *, char **);
index 00a766d70e120bb590918cf2003acb12fdd0da46..6969a7a7670b4228ac4c6733720d9ec135fb5657 100644 (file)
@@ -811,7 +811,7 @@ void mutt_view_attachments (HEADER *hdr)
     return;
   }
   
-  if ((hdr->pgp & PGPENCRYPT) && hdr->content->type == TYPEMULTIPART)
+  if ((hdr->pgp & PGPENCRYPT) && mutt_is_multipart_encrypted(hdr->content))
   {
     if (pgp_decrypt_mime (msg->fp, &fp, hdr->content->parts->next, &cur))
     {
index 883eb918425fff805a66f26772d854c890771962..6ff67552fa073512f75de54986dd7f671fea14b3 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -954,14 +954,13 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg)
     if(option(OPTFORWDECRYPT)
        && (hdr->pgp & PGPENCRYPT))
   {
-    if(hdr->content->type == TYPEMULTIPART)
+    if(mutt_is_multipart_encrypted(hdr->content))
     {
       chflags |= CH_MIME | CH_NONEWLINE;
       cmflags = M_CM_DECODE_PGP;
       pgp &= ~PGPENCRYPT;
     }
-    else if((hdr->content->type == TYPEAPPLICATION) &&
-           mutt_is_pgp_subtype(hdr->content->subtype))
+    else if(mutt_is_application_pgp(hdr->content) & PGPENCRYPT)
     {
       chflags |= CH_MIME | CH_TXTPLAIN;
       cmflags = M_CM_DECODE;