[PATCH] test/crypto: remove headers more robustly

Tomi Ollila tomi.ollila at iki.fi
Sat Sep 2 12:48:56 PDT 2017


On Fri, Sep 01 2017, David Bremner wrote:

> In [1], Vladimir Panteleev observed that the In-Reply-To and
> References headers could be wrapped in the 'default' output format of
> notmuch-reply, depending on the version of Emacs creating the
> message. In my own experiments notmuch-reply sometimes wraps headers
> with only one message-id if that message-id is long enough. However it
> happens, this causes the previous approach using grep to fail.

we could (also) make emacs think it has wider than 80 characters to fit on
one line...

> Since I found the proposed unwrapping shell fragment in [1] a bit hard
> to follow, I decided to write a little python script instead.

There was nothing hard in that shell construct ;), but I also thought some
alternative solutions (one in awk and one in perl)

How 'bout

drop_email_headers ()
{
    $NOTMUCH_PYTHON -c 'import email, sys
msg = email.message_from_file(sys.stdin)
for hdr in sys.argv: msg.pop(hdr, None)
print(msg.as_string(False))'
}

and then ... | drop_email_headers In-Reply-To References




>
> [1] id:20170817175145.3204-7-notmuch at thecybershadow.net
> ---
>  test/T350-crypto.sh |  2 +-
>  test/test-lib.sh    | 11 +++++++++++
>  2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/test/T350-crypto.sh b/test/T350-crypto.sh
> index 7dab39a2..fd950952 100755
> --- a/test/T350-crypto.sh
> +++ b/test/T350-crypto.sh
> @@ -394,7 +394,7 @@ test_expect_equal_json \
>  
>  test_begin_subtest "reply to encrypted message"
>  output=$(notmuch reply --decrypt subject:"test encrypted message 002" \
> -    | grep -v -e '^In-Reply-To:' -e '^References:')
> +    | notmuch_reply_sanitize_refs)
>  expected='From: Notmuch Test Suite <test_suite at notmuchmail.org>
>  Subject: Re: test encrypted message 002
>  
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index d2b2a47f..4716f649 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -507,6 +507,17 @@ NOTMUCH_DUMP_TAGS ()
>      notmuch dump --include=tags "${@}" | sed '/^#/d' | sort
>  }
>  
> +notmuch_reply_sanitize_refs ()
> +{
> +    $NOTMUCH_PYTHON -c "
> +import email,sys
> +msg=email.message_from_file(sys.stdin)
> +del msg['in-reply-to']
> +del msg['references']
> +print(msg.as_string(False))
> +"
> +}
> +
>  notmuch_search_sanitize ()
>  {
>      perl -pe 's/("?thread"?: ?)("?)................("?)/\1\2XXX\3/'
> -- 
> 2.14.1
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list