Some MTAs mangle e-mail messages in transit in ways that are

Microsoft Exchange (in particular, the version running today on
Office365's mailservers) appears to mangle multipart/encrypted
messages in a way that makes them undecryptable by the recipient.

I've documented this in section 4.1 "Mixed-up encryption" of draft -00

Fortunately, it's possible to repair such a message, and notmuch can
do that so that a user who receives an encrypted message from a user
of can still decrypt the message.

Enigmail already knows about this particular kind of mangling.  It
describes it as "broken PGP email format probably caused by an old
Exchange server", and it tries to repair by directly changing the
message held by the user.  if this kind of repair goes wrong, the
repair process can cause data loss
(, yikes).

The tests introduced here are currently broken.  In subsequent
patches, i'll introduce a non-destructive form of repair for notmuch
so that notmuch users can read mail that has been mangled in this way,
and the tests will succeed.

Signed-off-by: Daniel Kahn Gillmor <>
 test/      | 36 ++++++++++++++++++++++++++++++
 test/corpora/mangling/mixed-up.eml | 33 +++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100755 test/
 create mode 100644 test/corpora/mangling/mixed-up.eml

diff --git a/test/ b/test/
new file mode 100755
index 00000000..f65b8a24
--- /dev/null
+++ b/test/
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+test_description='PGP/MIME message mangling'
+. $(dirname "$0")/ || exit 1
+add_email_corpus mangling
+bodytext='["body"][0]["content"][1]["content"]="The password is \"abcd1234!\", 
please do not tell anyone.\n"'
+test_begin_subtest "show 'Mixed-Up' mangled PGP/MIME message correctly"
+output=$(notmuch show --format=json --decrypt=true
+test_json_nodes <<<"$output" \
+                'body:[0][0][0]'"$bodytext"
+test_begin_subtest "reply to 'Mixed-Up' mangled PGP/MIME message correctly"
+output=$(notmuch reply --format=json --decrypt=true
+test_json_nodes <<<"$output" \
+                'body:["original"]'"$bodytext"
+test_begin_subtest "repaired 'Mixed-up' messages can be found with 
+output=$(notmuch search --output=messages property:index.repaired=mixedup)
+test_expect_equal "$output"
+test_begin_subtest "index cleartext of 'Mixed-Up' mangled PGP/MIME message"
+test_expect_success 'notmuch reindex --decrypt=true'
+test_begin_subtest "search cleartext of 'Mixed-Up' mangled PGP/MIME message"
+output=$(notmuch search --output=messages body:password)
+test_expect_equal "$output"
diff --git a/test/corpora/mangling/mixed-up.eml 
new file mode 100644
index 00000000..a09f6191
--- /dev/null
+++ b/test/corpora/mangling/mixed-up.eml
@@ -0,0 +1,33 @@
+Subject: Here is the password
+Date: Sat, 01 Jan 2000 12:00:00 +0000
+Message-ID: <>
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="=-=-="
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: quoted-printable
+Content-Type: application/pgp-encrypted
+Content-Transfer-Encoding: base64
+Content-Type: application/octet-stream
+Content-Transfer-Encoding: base64

notmuch mailing list

Reply via email to