From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MHTHDHJlEWJv5gAAgWs5BA (envelope-from ) for ; Sat, 19 Feb 2022 22:47:30 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id SMiPBXJlEWL0xQAAG6o9tA (envelope-from ) for ; Sat, 19 Feb 2022 22:47:30 +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 D105C85B1 for ; Sat, 19 Feb 2022 22:47:29 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id ADBFA5E025; Sat, 19 Feb 2022 21:47:26 +0000 (UTC) Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37]) by mail.notmuchmail.org (Postfix) with ESMTPS id 22B2B5E017 for ; Sat, 19 Feb 2022 21:47:24 +0000 (UTC) Received: from guru.guru-group.fi (unknown [IPv6:2a02:2380:1:9:5054:ff:feb7:a4bc]) (using TLSv1.2 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: too) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4320C1B001CF; Sat, 19 Feb 2022 23:47:23 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1645307243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n7Tif9qY8yCyVN04BH48QoCYM6DYUTB9yVtNg1PQfqE=; b=BODIxjFHFcWmfz6P/x66G/H3u01mTjzR0DZQbP9c84LTtquKLW50m7eOAZBbCukkae7fpf uroMMHsPH3YDarscy6g3Pa8BvZ9bRpcKNA1e4cCgdsdqlmlwCZfKEv9ka20oTphOtf3FoU kQgtJuYf5dkIUHzJO7G6WGRypTkLfInv8RAV5E8gG6q181Jh3xj3jy21a7UphFxeU54Yyk KZt2rnEpE6AhczYyRUaUEfJXVi3wc6jP6szgZ9TCnTYqAeniTSRNjVAktZPxl3jNyI4J1i UnytoEDrICDCeRbvrcud5pszZ/DTxj/cLCAXDMVrKtPOJxiUZ2bpjhQcsNPuXg== From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH 4/4] CLI/insert: escape envelope from In-Reply-To: <20220213152751.3015318-5-david@tethera.net> References: <20220213152751.3015318-1-david@tethera.net> <20220213152751.3015318-5-david@tethera.net> User-Agent: Notmuch/0.35+4~ge2bb4cd (https://notmuchmail.org) Emacs/27.1 X-Face: HhBM'cA~ MIME-Version: 1.0 ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=too smtp.mailfrom=tomi.ollila@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1645307243; a=rsa-sha256; cv=none; b=k2GHalPwGdAOZKEJ/K/k/ThUKswjjkjZfXBl97/PO8eAuJiABdOGGw/ICG8k4kB/WYsXhO IPJP0t1eGbopJqi5tEHTDVWdB2CA8gk858aXDdfVCST9llQjHltb59gU+6DTvnUCkH1cTU lol+dRXcFYZ//+iSuoysYoeZNnNK3dwsE26Bsbp6WLORZIh3bTzCXfew5su0WQUqtGNqZ9 xpzbJ0YpRO9Y/q+qDVtCyUDQdaFA/NYkyfjndcXfszq6qtHkoKbUDIoBi1YhfA0EdtYaG4 IeG/JV/42qC2QneH2N5/6M6jp6xb+K5wUVpQVR4/kV3wdd+tdsrHWBWDKu3Muw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1645307243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n7Tif9qY8yCyVN04BH48QoCYM6DYUTB9yVtNg1PQfqE=; b=NiVNdJqjDPV66OMAIwPoqaS5vk8awAacNlpTfUrgOwo9BE1f+f6Iim2Zcqx0twZ5dBq/bz AQIUwRhNsU10u5z+i8H3vKqyDiKMJud8mmlxFQ9P8h3AExVCx/MMxPakQhIzanjIVQ/Su+ 966jzlaF7yZqQnP9ZFJ8ssWgu6SiIHED3LXZX7dmSWUPCTvzGZNfsiE6TG2UnVZhqZY/53 F//+67wOGz+CK9Z11oM8bqz6vWY8b5HXrqKez3PymTpNSlSOw12fJSKMVuonY5jpe/LC4H aucD3l/T8Ojqbbs7WSdNWHEJXE+UexGILvnGFz4FdF2tqDdyUqWJEC8tKxzQyw== Message-ID-Hash: OGQH3A3EUISE5IK6FDCDCAWLDXDI7MHB X-Message-ID-Hash: OGQH3A3EUISE5IK6FDCDCAWLDXDI7MHB X-MailFrom: tomi.ollila@iki.fi 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=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1645307249; 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:dkim-signature; bh=Ua5d9bOzmdj63zBxbXRf/OqC0LuCDMuRrjKlHW+Tfkw=; b=in1RK+x6sMMTp2cOo2lIsSIG0/knIg3+wX7Z0vZ0JJqH8rKZCncmvmbTQvIAwope8ng6Cq vQW3dmZ13X6cK/djEyVPTWWHviZETRM46iqLtXtQ1DFELvyF18wCyBK7nE3Ew6NBgJudV4 5j0YwZ0PFYMJx10TmFzwvBif3zlrD2DJSdcKSamXBlBJVhBYuKiU3emvjuModm6vl65dFK r3ysNMac3m0Mj6eck2flv/LuRXlNdbKRsiebyTco9HlCjRhhrv07jKgn6eMFbKsaZvvKcZ SUpOxgMc7fyGv4bSZ9mN6tEWDXTlzZes+qKh10A8gV9hMhbuiwpOAmeEa3gM8A== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1645307249; a=rsa-sha256; cv=fail; b=gO97e++EGy6YfYsdJAlF9vKcx/ennSpvi7hur24TJs04Rdf3BEL54eK85VWMyIJFldLWyx 2/BFFAPDhdLzCUkwqWSIu7KbciYyE0c7r2n4o7dEaqnhzbTP/dX4G0NVMW2mM/bnIAufR1 y8pDkvI87Bb9smbmbRnF0QhiTo97XcDAXLYsQKaljtLN7b65K0iM3rZ/WUHV0JG7WNyl1H Q6ZPj+jRUznoI5LI7yHxIxxsI5jmS8ev9AOMi2kN4+trRFyUGROgi1JS8fqLCBSI3aLSp0 VYh/MxoqAixtdhrN3EXUMGWWbCPVkRsPvQtKDX9jFUUn/9JvcdFrSo3RoRUFZw== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=lahtoruutu header.b=BODIxjFH; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); 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: -0.95 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=lahtoruutu header.b=BODIxjFH; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); 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: D105C85B1 X-Spam-Score: -0.95 X-Migadu-Scanner: scn0.migadu.com X-TUID: BkJj3EWAECNz On Sun, Feb 13 2022, David Bremner wrote: > 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: "; spaces > > 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))) Probably optimizing compiler can replace strlen (header) with constant value -- it does not matter but had to mention :D Code changes look good to me. Tomi > + 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