Re: [PATCH 4/4] CLI/insert: escape envelope from

Subject: Re: [PATCH 4/4] CLI/insert: escape envelope from

Date: Sat, 19 Feb 2022 23:47:21 +0200

To: David Bremner, notmuch@notmuchmail.org

Cc:

From: Tomi Ollila


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
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: