]> granicus.if.org Git - neomutt/commitdiff
Improve attachment menu for s/mime parts
authorKevin McCarthy <kevin@8t8.us>
Thu, 24 Jan 2019 22:15:33 +0000 (14:15 -0800)
committerRichard Russon <rich@flatcap.org>
Wed, 20 Feb 2019 00:55:01 +0000 (00:55 +0000)
Don't prompt for passphrase or getkeys, or set the ENCRYPT flag, for
OPAQUE types.

Don't recurse on "text" output from decrypt_mime().  There is no
reason to recurse on a text type.  Additionally, the
mutt_read_mime_header() will return an empty text type even if the
decode doesn't generate mime output.  In those cases, we want to show
the original attachment.

Co-authored-by: Richard Russon <rich@flatcap.org>
recvattach.c

index e8c3992a6cf09faaf4638b1e9e3de1876e46e588..7da73351849fd060443ffbf8ff9fda891c48cf54 100644 (file)
@@ -1134,24 +1134,38 @@ static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email *
   struct AttachPtr *new = NULL;
   struct Body *new_body = NULL;
   FILE *new_fp = NULL;
-  int need_secured, secured;
+  int type, need_secured, secured;
 
   for (; m; m = m->next)
   {
     need_secured = 0;
     secured = 0;
 
-    if (((WithCrypto & APPLICATION_SMIME) != 0) && mutt_is_application_smime(m))
+    if (((WithCrypto & APPLICATION_SMIME) != 0) && (type = mutt_is_application_smime(m)))
     {
       need_secured = 1;
 
-      if (!crypt_valid_passphrase(APPLICATION_SMIME))
-        goto decrypt_failed;
+      if (type & ENCRYPT)
+      {
+        if (!crypt_valid_passphrase(APPLICATION_SMIME))
+          goto decrypt_failed;
 
-      if (e->env)
-        crypt_smime_getkeys(e->env);
+        if (e->env)
+          crypt_smime_getkeys(e->env);
+      }
 
       secured = !crypt_smime_decrypt_mime(fp, &new_fp, m, &new_body);
+      /* If the decrypt/verify-opaque doesn't generate mime output, an
+       * empty "TEXT" type will still be returned by
+       * mutt_read_mime_header().  Since recursing over that type
+       * isn't interesting and loses information about the original
+       * attachment, just abort and view normally. */
+      if (secured && new_body->type == TYPE_TEXT)
+      {
+        mutt_body_free(&new_body);
+        mutt_file_fclose(&new_fp);
+        goto decrypt_failed;
+      }
 
       /* S/MIME nesting */
       if ((mutt_is_application_smime(new_body) & SMIME_OPAQUE) == SMIME_OPAQUE)
@@ -1168,7 +1182,7 @@ static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email *
         mutt_file_fclose(&outer_fp);
       }
 
-      if (secured)
+      if (secured && (type & ENCRYPT))
         e->security |= SMIME_ENCRYPT;
     }