From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 6B4DA6DE025C for ; Sun, 8 Sep 2019 20:27:36 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -1.528 X-Spam-Level: X-Spam-Status: No, score=-1.528 tagged_above=-999 required=5 tests=[AWL=0.973, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kCADMOmTGBie for ; Sun, 8 Sep 2019 20:27:35 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTPS id B6C766DE0944 for ; Sun, 8 Sep 2019 20:27:34 -0700 (PDT) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019; t=1567999653; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=deLpC6HnDxiZoJ4KvBv+uqkoqv3B31+uZFEWBYIFilQ=; b=HJuVE1OaLkpRvVP5H3q5laTs9p7mTMjH9DOkN60lCnda0HAF5/QftIBU JgsU1uEUk7odxhBi1/goDsWfz/lXBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fifthhorseman.net; i=@fifthhorseman.net; q=dns/txt; s=2019rsa; t=1567999653; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : from; bh=deLpC6HnDxiZoJ4KvBv+uqkoqv3B31+uZFEWBYIFilQ=; b=hnDUMdesbwzNqakWxm2jjUIgK/mxw5LDFHPwuGjI/ylQRw5xB0aDM3kR zg8cgafZX7zp0g2frlLT5Y2kPH6CKDfIPRbWD6voT+il8+t4YuIwrpVDKp sWNPdmwe+ckLOxpaEvzMPOqBaEOK1Eg4QC1AdRMNRpiF8sY3P3gSYOJm48 k8ZJ/lndKg7HvE36UaqDVR5qqHIMTzlPsDJj9fzB17tF3pGlwJvB/WNiYI xbguDhMJ1vhEqj/CYPxMgZqpTJgKX/hlN+55hZuJC2zGzqcdy/6fKmhPSh sGP8UdZbzSCi5GLZNsUSqqeEyGOlCCbxklOE4Lt63MM3xKojY2zZpA== Received: from fifthhorseman.net (unknown [IPv6:2001:470:1f07:60d:c41:39ff:fef3:974f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by che.mayfirst.org (Postfix) with ESMTPSA id 9F1FBF9A9 for ; Sun, 8 Sep 2019 23:27:33 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id 14B4F2058D; Sun, 8 Sep 2019 23:27:29 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH v4 4/4] cli/{show, reply}: use repaired form of "Mixed Up" mangled messages Date: Sun, 8 Sep 2019 23:27:26 -0400 Message-Id: <20190909032726.8931-5-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190909032726.8931-1-dkg@fifthhorseman.net> References: <20190909032726.8931-1-dkg@fifthhorseman.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Sep 2019 03:27:36 -0000 When showing or replying to a message that has been mangled in transit by an MTA in the "Mixed up" way, notmuch should instead use the repaired form of the message. Tracking the repaired GMimeObject for the lifetime of the mime_node so that it is cleaned up properly is probably the trickiest part of this patch, but the choices here are based on the idea that the mime_node_context is the memory manager for the whole mime_node tree in the first place, so new GMimeObject tree created on-the-fly during message parsing should be disposed of in the same place. Signed-off-by: Daniel Kahn Gillmor --- mime-node.c | 22 ++++++++++++++++++++++ test/T351-pgpmime-mangling.sh | 2 -- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mime-node.c b/mime-node.c index 599d3b65..d4996a33 100644 --- a/mime-node.c +++ b/mime-node.c @@ -36,6 +36,9 @@ typedef struct mime_node_context { GMimeMessage *mime_message; _notmuch_message_crypto_t *msg_crypto; + /* repaired/unmangled parts that will need to be cleaned up */ + GSList *repaired_parts; + /* Context provided by the caller. */ _notmuch_crypto_t *crypto; } mime_node_context_t; @@ -52,9 +55,21 @@ _mime_node_context_free (mime_node_context_t *res) if (res->stream) g_object_unref (res->stream); + if (res->repaired_parts) + g_slist_free_full (res->repaired_parts, g_object_unref); + return 0; } +/* keep track of objects that need to be destroyed when the mime node + * context goes away. */ +static void +_mime_node_context_track_repaired_part (mime_node_context_t *ctx, GMimeObject *part) +{ + if (part) + ctx->repaired_parts = g_slist_prepend (ctx->repaired_parts, part); +} + const _notmuch_message_crypto_t * mime_node_get_message_crypto_status (mime_node_t *node) { @@ -298,6 +313,13 @@ _mime_node_set_up_part (mime_node_t *node, GMimeObject *part, int numchild) node->part = part; node->nchildren = 0; } else if (GMIME_IS_MULTIPART (part)) { + GMimeObject *repaired_part = _notmuch_repair_mixed_up_mangled (part); + if (repaired_part) { + /* This was likely "Mixed Up" in transit! We replace it + * with the more likely-to-be-correct variant. */ + _mime_node_context_track_repaired_part (node->ctx, repaired_part); + part = repaired_part; + } node->part = part; node->nchildren = g_mime_multipart_get_count (GMIME_MULTIPART (part)); } else if (GMIME_IS_MESSAGE_PART (part)) { diff --git a/test/T351-pgpmime-mangling.sh b/test/T351-pgpmime-mangling.sh index 4555f937..71a68c05 100755 --- a/test/T351-pgpmime-mangling.sh +++ b/test/T351-pgpmime-mangling.sh @@ -9,13 +9,11 @@ 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" -test_subtest_known_broken output=$(notmuch show --format=json --decrypt=true id:mixed-up@mangling.notmuchmail.org) test_json_nodes <<<"$output" \ 'body:[0][0][0]'"$bodytext" test_begin_subtest "reply to 'Mixed-Up' mangled PGP/MIME message correctly" -test_subtest_known_broken output=$(notmuch reply --format=json --decrypt=true id:mixed-up@mangling.notmuchmail.org) test_json_nodes <<<"$output" \ 'body:["original"]'"$bodytext" -- 2.23.0