]> granicus.if.org Git - neomutt/commitdiff
Show top-level decoded smime text/plain parts
authorKevin McCarthy <kevin@8t8.us>
Fri, 25 Jan 2019 02:28:27 +0000 (18:28 -0800)
committerRichard Russon <rich@flatcap.org>
Wed, 20 Feb 2019 00:55:01 +0000 (00:55 +0000)
Commit 331d9d5a attempted to fix a problem with an attachment having
extension .p7m.  The attachment menu tried to decode and failed, and
the part ended up being replaced by a bogus text/plain part.

The problem is that crypt_smime_decrypt_mime() returns a text/plain
part if the decode fails, meaning we can't distinguish failure from
success in this case.

As a compromise, only use a text/plain resulting from a single
top-level application_smime part.  This will allow for the case of an
text/plain encoded email, but won't end up hiding attachments that
were not decoded.

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

index c1aa745510bd4ec34279deb482782e3f23184f90..aa6ac3a14bf78d80bdccd550f5ba9b1cedc4795b 100644 (file)
@@ -1120,23 +1120,24 @@ int mutt_attach_display_loop(struct Menu *menu, int op, struct Email *e,
 /**
  * mutt_generate_recvattach_list - Create a list of attachments
  * @param actx        Attachment context
- * @param e         Email
- * @param m           Body of email
+ * @param e           Email
+ * @param parts       Body of email
  * @param fp          File to read from
  * @param parent_type Type, e.g. #TYPE_MULTIPART
  * @param level       Attachment depth
  * @param decrypted   True if attachment has been decrypted
  */
 static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email *e,
-                                          struct Body *m, FILE *fp, int parent_type,
-                                          int level, bool decrypted)
+                                          struct Body *parts, FILE *fp,
+                                          int parent_type, int level, bool decrypted)
 {
   struct AttachPtr *new = NULL;
+  struct Body *m = NULL;
   struct Body *new_body = NULL;
   FILE *new_fp = NULL;
   int type, need_secured, secured;
 
-  for (; m; m = m->next)
+  for (m = parts; m; m = m->next)
   {
     need_secured = 0;
     secured = 0;
@@ -1155,12 +1156,13 @@ static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email *
       }
 
       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)
+      /* If the decrypt/verify-opaque doesn't generate mime output, an empty
+       * text/plain type will still be returned by mutt_read_mime_header().
+       * We can't distinguish an actual part from a failure, so only use a
+       * text/plain that results from a single top-level part. */
+      if (secured && (new_body->type == TYPE_TEXT) &&
+          (mutt_str_strcasecmp("plain", new_body->subtype) == 0) &&
+          ((parts != m) || m->next))
       {
         mutt_body_free(&new_body);
         mutt_file_fclose(&new_fp);