From: Kevin McCarthy Date: Fri, 25 Jan 2019 02:28:27 +0000 (-0800) Subject: Show top-level decoded smime text/plain parts X-Git-Tag: 2019-10-25~357^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2dc90ea3acc354cc1876e111d144a40e51562eea;p=neomutt Show top-level decoded smime text/plain parts 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 --- diff --git a/recvattach.c b/recvattach.c index c1aa74551..aa6ac3a14 100644 --- a/recvattach.c +++ b/recvattach.c @@ -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);