<<< Date Index >>>     <<< Thread Index >>>

[PATCH] Make mutt_parse_crypt_hdr() more SMIME-aware



Hi,

the attached patch fixes the following bug in Mutt HEAD:

when I postpone a message for which I have enabled SMIME signing with a
specific key, the correct SMIME-related headers are added to the
postponed message - BUT: they are parsed wrong.  What happens during
parsing is that PgpSignAs is filled with the ID of the SMIME key, not
SmimeDefaultKey.

What the patch basically does is: make mutt_parse_crypt_hdr accept a new
argument (crypt_app), which is to be set by the caller to either
APPLICATION_PGP for parsing of a PGP header or to APPLICATION_SMIME for
parsing of an SMIME header.  With that information,
mutt_parse_crypt_hdr() can fill the correct variable instead of hoping
that it was a PGP header so that PgpSignAs is the correct variable.

Besides this, the patch generalizes mutt_parse_crypt_hdr a bit (by
renaming some local variables, etc.).

Greetings,
Moritz

--- PATCHES~    Tue Nov  6 19:59:33 2001
+++ PATCHES     Tue Nov  6 19:59:42 2001
@@ -1,0 +1 @@
+smime-default-key.diff
Index: ChangeLog
===================================================================
RCS file: /home/roessler/cvs/mutt/ChangeLog,v
retrieving revision 3.687
diff -u -p -r3.687 ChangeLog
--- ChangeLog   12 Jan 2006 19:10:03 -0000      3.687
+++ ChangeLog   12 Jan 2006 21:33:47 -0000
@@ -1,3 +1,19 @@
+2006-01-12  Moritz Schulte  <moritz@xxxxxxxxxxx>
+
+       * postpone.c (mutt_get_postponed): Pass APPLICATION_PGP or
+       APPLICATION_SMIME to mutt_parse_crypt_hdr.
+
+       * headers.c (mutt_edit_headers): Likewise.
+
+       * mutt_crypt.h: Updated declaration of function
+       mutt_parse_crypt_hdr.
+
+       * postpone.c (mutt_parse_crypt_hdr): New argument: crypt_app;
+       set PgpSignAs or SmimeDefaultKey, depending on crypt_app.
+       renamed local variable 'pgp' to 'flags';
+       renamed local variable 'pgp_sign_as' to 'sign_as';
+       made error message less pgp/smime-specific.
+
 2006-01-12 19:09:28  Phil Pennock  <mutt-dev@xxxxxxxxxxxxxxxxx>  (brendan)
 
        * init.c: Update MyVars to the next entry when deleting the head
Index: headers.c
===================================================================
RCS file: /home/roessler/cvs/mutt/headers.c,v
retrieving revision 3.8
diff -u -p -r3.8 headers.c
--- headers.c   17 Sep 2005 20:46:10 -0000      3.8
+++ headers.c   12 Jan 2006 21:28:45 -0000
@@ -184,7 +184,7 @@ void mutt_edit_headers (const char *edit
     else if ((WithCrypto & APPLICATION_PGP)
              &&ascii_strncasecmp ("pgp:", cur->data, 4) == 0)
     {
-      msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0);
+      msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0, APPLICATION_PGP);
       if (msg->security)
        msg->security |= APPLICATION_PGP;
       keep = 0;
Index: mutt_crypt.h
===================================================================
RCS file: /home/roessler/cvs/mutt/mutt_crypt.h,v
retrieving revision 3.11
diff -u -p -r3.11 mutt_crypt.h
--- mutt_crypt.h        17 Sep 2005 20:46:10 -0000      3.11
+++ mutt_crypt.h        12 Jan 2006 21:28:46 -0000
@@ -119,7 +119,7 @@ int mutt_is_application_smime (BODY *);
 
 int mutt_signed_handler (BODY *, STATE *);
 
-int mutt_parse_crypt_hdr (char *, int);
+int mutt_parse_crypt_hdr (char *, int, int);
 
 
 void convert_to_7bit (BODY *);
Index: postpone.c
===================================================================
RCS file: /home/roessler/cvs/mutt/postpone.c,v
retrieving revision 3.17
diff -u -p -r3.17 postpone.c
--- postpone.c  3 Jan 2006 17:28:51 -0000       3.17
+++ postpone.c  12 Jan 2006 21:28:47 -0000
@@ -340,7 +340,8 @@ int mutt_get_postponed (CONTEXT *ctx, HE
                                                       */
                  || mutt_strncmp ("X-Mutt-PGP:", tmp->data, 11) == 0))
     {
-      hdr->security = mutt_parse_crypt_hdr (strchr (tmp->data, ':') + 1, 1);
+      hdr->security = mutt_parse_crypt_hdr (strchr (tmp->data, ':') + 1, 1,
+                                           APPLICATION_PGP);
       hdr->security |= APPLICATION_PGP;
        
       /* remove the pgp field */
@@ -356,7 +357,8 @@ int mutt_get_postponed (CONTEXT *ctx, HE
     else if ((WithCrypto & APPLICATION_SMIME)
              && mutt_strncmp ("X-Mutt-SMIME:", tmp->data, 13) == 0)
     {
-      hdr->security = mutt_parse_crypt_hdr (strchr (tmp->data, ':') + 1, 1);
+      hdr->security = mutt_parse_crypt_hdr (strchr (tmp->data, ':') + 1, 1,
+                                           APPLICATION_SMIME);
       hdr->security |= APPLICATION_SMIME;
        
       /* remove the smime field */
@@ -405,11 +407,11 @@ int mutt_get_postponed (CONTEXT *ctx, HE
 
 
 
-int mutt_parse_crypt_hdr (char *p, int set_signas)
+int mutt_parse_crypt_hdr (char *p, int set_signas, int crypt_app)
 {
-  int pgp = 0;
-  char pgp_sign_as[LONG_STRING] = "\0", *q;
   char smime_cryptalg[LONG_STRING] = "\0";
+  char sign_as[LONG_STRING] = "\0", *q;
+  int flags = 0;
 
   if (!WithCrypto)
     return 0;
@@ -422,24 +424,24 @@ int mutt_parse_crypt_hdr (char *p, int s
     {
       case 'e':
       case 'E':
-        pgp |= ENCRYPT;
+        flags |= ENCRYPT;
         break;
 
       case 's':    
       case 'S':
-        pgp |= SIGN;
-        q = pgp_sign_as;
+        flags |= SIGN;
+        q = sign_as;
       
         if (*(p+1) == '<')
         {
           for (p += 2; 
-              *p && *p != '>' && q < pgp_sign_as + sizeof (pgp_sign_as) - 1;
+              *p && *p != '>' && q < sign_as + sizeof (sign_as) - 1;
                *q++ = *p++)
            ;
 
           if (*p!='>')
           {
-            mutt_error _("Illegal PGP header");
+            mutt_error _("Illegal crypto header");
             return 0;
           }
         }
@@ -460,7 +462,7 @@ int mutt_parse_crypt_hdr (char *p, int s
            ;
          if(*p != '>')
          {
-           mutt_error _("Illegal PGP header");
+           mutt_error _("Illegal crypto header");
            return 0;
          }
        }
@@ -490,24 +492,31 @@ int mutt_parse_crypt_hdr (char *p, int s
 
       case 'i':
       case 'I':
-       pgp |= INLINE;
+       flags |= INLINE;
        break;
 
       default:
-        mutt_error _("Illegal PGP header");
+        mutt_error _("Illegal crypto header");
         return 0;
     }
      
   }
- 
+
   /* the cryptalg field must not be empty */
   if ((WithCrypto & APPLICATION_SMIME) && *smime_cryptalg)
     mutt_str_replace (&SmimeCryptAlg, smime_cryptalg);
 
-  if ((WithCrypto & APPLICATION_PGP) && (set_signas || *pgp_sign_as))
-    mutt_str_replace (&PgpSignAs, pgp_sign_as);
+  /* Set {Smime,Pgp}SignAs, if desired. */
+
+  if ((WithCrypto & APPLICATION_PGP) && (crypt_app == APPLICATION_PGP)
+      && (set_signas || *sign_as))
+    mutt_str_replace (&PgpSignAs, sign_as);
+
+  if ((WithCrypto & APPLICATION_SMIME) && (crypt_app == APPLICATION_SMIME)
+      && (set_signas || *sign_as))
+    mutt_str_replace (&SmimeDefaultKey, sign_as);
 
-  return pgp;
+  return flags;
 }