From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uFuBC6kjCWK/0wAAgWs5BA (envelope-from ) for ; Sun, 13 Feb 2022 16:28:41 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id c79UBKkjCWL2HgEAG6o9tA (envelope-from ) for ; Sun, 13 Feb 2022 16:28:41 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A2F1B128F3 for ; Sun, 13 Feb 2022 16:28:40 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 9F9565F6CF; Sun, 13 Feb 2022 15:28:39 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id CF8625F401 for ; Sun, 13 Feb 2022 15:28:37 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 60E3A5FBD2; Sun, 13 Feb 2022 10:28:37 -0500 (EST) Received: (nullmailer pid 3015411 invoked by uid 1000); Sun, 13 Feb 2022 15:27:56 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 4/4] CLI/insert: escape envelope from Date: Sun, 13 Feb 2022 11:27:51 -0400 Message-Id: <20220213152751.3015318-5-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220213152751.3015318-1-david@tethera.net> References: <20220213152751.3015318-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: N6VD5G4KOPF3HDCUIQIXIKXTH6QWNLZF X-Message-ID-Hash: N6VD5G4KOPF3HDCUIQIXIKXTH6QWNLZF X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644766120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=ZL2PgQAo9lhjIO3lzeOYl9PivFGMUn3cBHwMbBLR6II=; b=qXyrKhOeH/ELvc3VjTa+gVuLjc1lSAYOEw8SfECpTysJOh3gc/pzEzM7jrTgzwcH5OVFD4 /YGYdo/U0jnxidSNgDgITjO42oCD6AF9MRWij6uDBIsL2PQjPbwMfSxQz++xJ4ePKcIbdL BA5eA7GY1ARHNmawspCbi3JJ8/wTIgeMSm0fAlintYJSOab69KstlJIfWIIzOlfsY5hk1P l3UieF4L6wm6XsaQw/XJHFx9RIKMBfcSbjmDV8a75yllzHBVrKM7DhIwYS6X1sNePfGvjI yWo2UmllyEvAp/wkG9PpkPYyhf7/B48zj4e9L/o2NP9sxy0MPlaH2vBFh6lydQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644766120; a=rsa-sha256; cv=none; b=KC9yRVz0kBK8kOcmkT0pdDv3Jya7k9jgey1/yivjfqIZxaEjvCUba35j89kzZ9VL5kWn6O OvVMILVCz/ODUwhhPYxlA5Nk8krAwk/zsm9pguODJoTHCrf2a9LAaBovnFfhLoYl7IoFrK eBVFO0rRxC82revQluAOqMRKVEvJ+A/znpFcM/rs2NpOpZ2deWDGlEzrmaYsZnsE0y3A18 LGNGOI37vphmwgGNUZcMfyFrxWboBSkOUDO34ZC5zj35p4YaPrzNYFL+JVAf1PTZS0XX07 huXLB2DvV+pjfARxvT4UIn3Gdn6dlS+V1kPCWGEMOPq5g+0QKavHjrWPRGm0hA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.34 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A2F1B128F3 X-Spam-Score: -1.34 X-Migadu-Scanner: scn1.migadu.com X-TUID: qBLmbxEZNuDB The idea is to do as little parsing and modification of the delivered message as possible. Luckily the position of the "envelope header" lets us escape it by replacing the first 5 characters of the stream with a regular header name (with ':'). --- notmuch-insert.c | 15 ++++++++++++++- test/T070-insert.sh | 1 - 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index bec25a2a..d1244384 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -267,10 +267,13 @@ static bool copy_fd (int fdout, int fdin) { bool empty = true; + bool first = true; + const char *header="X-Envelope-From: "; while (! interrupted) { ssize_t remain; char buf[4096]; + const char *p = buf; remain = read (fdin, buf, sizeof (buf)); if (remain == 0) @@ -282,7 +285,17 @@ copy_fd (int fdout, int fdin) strerror (errno)); return false; } - if (! write_buf (buf, fdout, remain)) + + if (first && remain >= 5 && 0 == strncmp (buf, "From ", 5)) { + if (! write_buf (header, fdout, strlen (header))) + return false; + p += 5; + remain -= 5; + } + + first = false; + + if (! write_buf (p, fdout, remain)) return false; empty = false; } diff --git a/test/T070-insert.sh b/test/T070-insert.sh index a297fa73..e1e3b151 100755 --- a/test/T070-insert.sh +++ b/test/T070-insert.sh @@ -293,7 +293,6 @@ for code in OUT_OF_MEMORY XAPIAN_EXCEPTION ; do done test_begin_subtest "insert converts mboxes on delivery" -test_subtest_known_broken notmuch insert +unmboxed < "${TEST_DIRECTORY}"/corpora/indexing/mbox-attachment.eml output=$(notmuch count tag:unmboxed) test_expect_equal "${output}" 1 -- 2.34.1