From f7ca74c673c1d4560f4e850418ff5ad1fe9d2e08 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Fri, 21 Dec 2018 10:13:17 -0800 Subject: [PATCH] Handle improperly encoded pgp/mime octetstream part Some clients (or even mail servers) improperly encode the octetstream part. Thanks to Riccardo Schirone for the original merge request patch. This commit also handles the attachment menu, and makes the decoding conditional so it's not done if it isn't necessary. Co-authored-by: Richard Russon --- handler.c | 7 ++++++- ncrypt/crypt_gpgme.c | 6 +++++- ncrypt/pgp.c | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/handler.c b/handler.c index 7caee9071..bc3c86383 100644 --- a/handler.c +++ b/handler.c @@ -1414,7 +1414,12 @@ static int valid_pgp_encrypted_handler(struct Body *b, struct State *s) mutt_env_free(&b->mime_headers); mutt_env_free(&octetstream->mime_headers); - int rc = crypt_pgp_encrypted_handler(octetstream, s); + int rc; + /* Some clients improperly encode the octetstream part. */ + if (octetstream->encoding != ENC_7BIT) + rc = run_decode_and_handler(octetstream, s, crypt_pgp_encrypted_handler, 0); + else + rc = crypt_pgp_encrypted_handler(octetstream, s); b->goodsig |= octetstream->goodsig; /* Relocate protected headers onto the multipart/encrypted part */ diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index e42abe878..da4ac20df 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -2212,7 +2212,12 @@ int pgp_gpgme_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body first_part->warnsig = false; if (mutt_is_valid_multipart_pgp_encrypted(b)) + { b = b->parts->next; + /* Some clients improperly encode the octetstream part. */ + if (b->encoding != ENC_7BIT) + need_decode = true; + } else if (mutt_is_malformed_multipart_pgp_encrypted(b)) { b = b->parts->next->next; @@ -3153,7 +3158,6 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) /* clear out any mime headers before the handler, so they can't be spoofed. */ mutt_env_free(&a->mime_headers); - a->warnsig = false; FILE *fpout = mutt_file_mkstemp(); if (!fpout) diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 2db68ecf1..f3423ad34 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -1131,7 +1131,12 @@ int pgp_class_decrypt_mime(FILE *fpin, FILE **fpout, struct Body *b, struct Body int rc = 0; if (mutt_is_valid_multipart_pgp_encrypted(b)) + { b = b->parts->next; + /* Some clients improperly encode the octetstream part. */ + if (b->encoding != ENC_7BIT) + need_decode = true; + } else if (mutt_is_malformed_multipart_pgp_encrypted(b)) { b = b->parts->next->next; -- 2.40.0