Fix pgp and smime decryption in mutt_prepare_template().

Change the "combined" multipart decryption block to only work for pgp,
since mutt_is_multipart_encrypted() currently only checks for pgp
headers and it therefore only worked for pgp in the first place.

Fix the newhdr->security to be based on what that function returns,
instead of the "context" hdr passed in.

Add a smime decryption block below when iterating through the content.

Fix the application/pgp decryption block to assign to hdr->security
using the type of the app/pgp part instead of hdr->content.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
http://www.8t8.us/configs/gpg-key-transition-statement.txt
# HG changeset patch
# User Kevin McCarthy <[email protected]>
# Date 1454630603 28800
#      Thu Feb 04 16:03:23 2016 -0800
# Node ID 4c03169face1343840d0babb0805137822f18b4a
# Parent  d566ab7098957fadab9838634eb3416a23fe178c
Fix pgp and smime decryption in mutt_prepare_template().

Change the "combined" multipart decryption block to only work for pgp,
since mutt_is_multipart_encrypted() currently only checks for pgp
headers and it therefore only worked for pgp in the first place.

Fix the newhdr->security to be based on what that function returns,
instead of the "context" hdr passed in.

Add a smime decryption block below when iterating through the content.

Fix the application/pgp decryption block to assign to hdr->security
using the type of the app/pgp part instead of hdr->content.

diff --git a/postpone.c b/postpone.c
--- a/postpone.c
+++ b/postpone.c
@@ -536,19 +536,19 @@
 
 int mutt_prepare_template (FILE *fp, CONTEXT *ctx, HEADER *newhdr, HEADER *hdr,
                               short weed)
 {
   MESSAGE *msg = NULL;
   char file[_POSIX_PATH_MAX];
   BODY *b;
   FILE *bfp;
-
   int rv = -1;
   STATE s;
+  int sec_type;
 
   memset (&s, 0, sizeof (s));
 
   if (!fp && (msg = mx_open_message (ctx, hdr->msgno)) == NULL)
     return (-1);
 
   if (!fp) fp = msg->fp;
 
@@ -569,27 +569,25 @@
   if (newhdr->env->message_id != NULL)
   {
     FREE (&newhdr->env->message_id);
     FREE (&newhdr->env->mail_followup_to);
   }
 
   /* decrypt pgp/mime encoded messages */
 
-  if ((WithCrypto & (APPLICATION_PGP|APPLICATION_SMIME) & hdr->security)
-      && mutt_is_multipart_encrypted (newhdr->content))
+  if ((WithCrypto & APPLICATION_PGP) &&
+      (sec_type = mutt_is_multipart_encrypted (newhdr->content)))
   {
-    int ccap = WithCrypto & (APPLICATION_PGP|APPLICATION_SMIME) & 
hdr->security;
-    newhdr->security |= ENCRYPT | ccap;
-    if (!crypt_valid_passphrase (ccap))
+    newhdr->security |= sec_type;
+    if (!crypt_valid_passphrase (sec_type))
       goto err;
 
     mutt_message _("Decrypting message...");
-    if (((ccap & APPLICATION_PGP) && crypt_pgp_decrypt_mime (fp, &bfp, 
newhdr->content, &b) == -1)
-       || ((ccap & APPLICATION_SMIME) && crypt_smime_decrypt_mime (fp, &bfp, 
newhdr->content, &b) == -1)
+    if ((crypt_pgp_decrypt_mime (fp, &bfp, newhdr->content, &b) == -1)
        || b == NULL)
     {
  err:
       mx_close_message (&msg);
       mutt_free_envelope (&newhdr->env);
       mutt_free_body (&newhdr->content);
       mutt_error _("Decryption failed.");
       return -1;
@@ -673,28 +671,36 @@
       mutt_delete_parameter ("x-mutt-noconv", &b->parameter);
     }
 
     mutt_adv_mktemp (file, sizeof(file));
     if ((s.fpout = safe_fopen (file, "w")) == NULL)
       goto bail;
 
 
-    if ((WithCrypto & APPLICATION_PGP)
-       && (mutt_is_application_pgp (b) & (ENCRYPT|SIGN)))
+    if ((WithCrypto & APPLICATION_PGP) &&
+       ((sec_type = mutt_is_application_pgp (b)) & (ENCRYPT|SIGN)))
     {
-
       mutt_body_handler (b, &s);
 
-      newhdr->security |= mutt_is_application_pgp (newhdr->content);
+      newhdr->security |= sec_type;
 
       b->type = TYPETEXT;
       mutt_str_replace (&b->subtype, "plain");
       mutt_delete_parameter ("x-action", &b->parameter);
     }
+    else if ((WithCrypto & APPLICATION_SMIME) &&
+             ((sec_type = mutt_is_application_smime (b)) & (ENCRYPT|SIGN)))
+    {
+      mutt_body_handler (b, &s);
+
+      newhdr->security |= sec_type;
+      b->type = TYPETEXT;
+      mutt_str_replace (&b->subtype, "plain");
+    }
     else
       mutt_decode_attachment (b, &s);
 
     if (safe_fclose (&s.fpout) != 0)
       goto bail;
 
     mutt_str_replace (&b->filename, file);
     b->unlink = 1;

Attachment: signature.asc
Description: PGP signature

Reply via email to