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 2C8BB6DE01E0 for ; Thu, 25 Oct 2018 11:56:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.039 X-Spam-Level: X-Spam-Status: No, score=0.039 tagged_above=-999 required=5 tests=[AWL=0.039, DKIMWL_WL_MED=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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 3xtXDgGoe8Hg for ; Thu, 25 Oct 2018 11:56:00 -0700 (PDT) Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by arlo.cworth.org (Postfix) with ESMTPS id A70326DE00DD for ; Thu, 25 Oct 2018 11:55:59 -0700 (PDT) Received: by mail-lf1-f67.google.com with SMTP id u18so475908lff.10 for ; Thu, 25 Oct 2018 11:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nikula-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=f3IFjjkjkt1l7peqFRKDCjHjRDV+o0TIHDIndz6adzk=; b=HQ0JKjbhT1PIgXLiZmTQBvRzKfmKHKsHcqRYDWd4m4iHTvAqgu/AKgcqQedtX0aaKv okqWSSH27GSScXILSqVhGJey/o4c1IzxE2rkAolUxTytPAh6F9+y98JSCTYBfBTIs8z7 OZk0iIdMk2iy/lqK6kbPjF4MwxLj5BoiK8dN82oBpkHFcxNMd5xUprEUFhJyAewj6rrM m1D5ObwX32wafrQUGAZ9IiJ42LO8z7xJ1dvtVLGDICF2MffsbCTNuSOjxnB1jENSZsuL EF3q87dC2/LyUtPx3jCqFqsW5UKKtJPKyx/qlij3LvbagjPx3TM9C+4s4Mhy1CZsZS67 q8Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=f3IFjjkjkt1l7peqFRKDCjHjRDV+o0TIHDIndz6adzk=; b=oEjVtlgiHSxX+NwgpG5uA6TmtW95WfKIzGvH9tACna7h0RNL3iQJmC6PPDU1q2pjS1 8hBRN5Yb4N+xeLTm/pfuo2fyWT6no/DWVT3gxqS+Ilwn5jihzvpVlCEdZludhGQli/+d qyRmi6QvnaFZszLUAc5RfiEM0dpzElZYEQCFQjo2IWJ4G8iJpFm5LvacQcwI9KObdH83 SsvOJw6wHMokR1+Sr2MhaIu4o2a8xIzluZJ4xtgknFIv265HoqpmtFOMbnB5CpOj1baA 9Wvici6XUiLr3Di1KF95Q2YOcLtsfo5iyYFb6SJYbC8Ypom6/j9CJjZrCcJg3FyxqRjf ofcQ== X-Gm-Message-State: AGRZ1gJH3cMfI9hHoTpbJj8/7NulkyXaX0GsxD9KZBwE3uwZOX8xGL7t XMZ4hOUBt1k1daoLhMZnAGUiqA== X-Google-Smtp-Source: AJdET5dmyxGLP4yoZsjfWvOb7d/JQ7QBS6X8ij4AAc2O4o03PvAlrZZVlXvx0eBDg47QFZIBI5NVzQ== X-Received: by 2002:a19:10da:: with SMTP id 87mr274993lfq.60.1540493755912; Thu, 25 Oct 2018 11:55:55 -0700 (PDT) Received: from localhost (213-216-252-32.bb.dnainternet.fi. [213.216.252.32]) by smtp.gmail.com with ESMTPSA id e24-v6sm1150757lfj.30.2018.10.25.11.55.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Oct 2018 11:55:54 -0700 (PDT) From: Jani Nikula To: mawww@kakoune.org, notmuch@notmuchmail.org Subject: Re: [PATCH] cli: Support --include-html and --body=false for --format=text In-Reply-To: <31d73dc7587ea4ee45c176e345f7cb3d@kakoune.org> References: <31d73dc7587ea4ee45c176e345f7cb3d@kakoune.org> Date: Thu, 25 Oct 2018 21:55:51 +0300 Message-ID: <87r2gd7t54.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain 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: Thu, 25 Oct 2018 18:56:01 -0000 On Thu, 25 Oct 2018, mawww@kakoune.org wrote: > text format is convenient for shell based parsing of notmuch output, > adding support for --include-html and --body=false improves its > usefulness to write complex shell based scripts. It's debatable whether parsing the --format=text output correctly is convenient or not. Particularly for notmuch show I think the text format output is basically legacy, and I don't think we're all that fond of adding new features to it. In any case, this patch has two independent changes in one, and should be split. BR, Jani. > --- > NEWS | 9 +++++++++ > doc/man1/notmuch-show.rst | 15 ++++++++------- > notmuch-show.c | 20 +++++++++++++++----- > test/T190-multipart.sh | 24 ++++++++++++++++++++++++ > 4 files changed, 56 insertions(+), 12 deletions(-) > > diff --git a/NEWS b/NEWS > index ca3ba99e..6d7e7162 100644 > --- a/NEWS > +++ b/NEWS > @@ -1,3 +1,12 @@ > +Notmuch 0.29 (UNRELEASED) > +========================= > + > +Command Line Interface > +---------------------- > + > +`notmuch show` now supports --include-html and --body=false with > +--format=text > + > Notmuch 0.28 (2018-10-12) > ========================= > > diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst > index 8bfa87c6..a2708a04 100644 > --- a/doc/man1/notmuch-show.rst > +++ b/doc/man1/notmuch-show.rst > @@ -176,18 +176,19 @@ Supported options for **show** include > ``--body=(true|false)`` > If true (the default) **notmuch show** includes the bodies of the > messages in the output; if false, bodies are omitted. > - ``--body=false`` is only implemented for the json and sexp formats > - and it is incompatible with ``--part > 0.`` > + ``--body=false`` is only implemented for the text, json and sexp > + formats and it is incompatible with ``--part > 0.`` > > This is useful if the caller only needs the headers as body-less > output is much faster and substantially smaller. > > ``--include-html`` > - Include "text/html" parts as part of the output (currently only > - supported with ``--format=json`` and ``--format=sexp``). By > default, > - unless ``--part=N`` is used to select a specific part or > - ``--include-html`` is used to include all "text/html" parts, no > - part with content type "text/html" is included in the output. > + Include "text/html" parts as part of the output (currently > + only supported with ``--format=text``, ``--format=json`` and > + ``--format=sexp``). By default, unless ``--part=N`` is used to > + select a specific part or ``--include-html`` is used to include all > + "text/html" parts, no part with content type "text/html" is > included > + in the output. > > A common use of **notmuch show** is to display a single thread of email > messages. For this, use a search term of "thread:" as can be > diff --git a/notmuch-show.c b/notmuch-show.c > index c3a3783a..07e9a5db 100644 > --- a/notmuch-show.c > +++ b/notmuch-show.c > @@ -574,12 +574,18 @@ format_part_text (const void *ctx, sprinter_t *sp, > mime_node_t *node, > g_mime_stream_printf (stream, "Date: %s\n", date_string); > g_mime_stream_printf (stream, "\fheader}\n"); > > + if (!params->output_body) > + { > + g_mime_stream_printf (stream, "\f%s}\n", part_type); > + return NOTMUCH_STATUS_SUCCESS; > + } > g_mime_stream_printf (stream, "\fbody{\n"); > } > > if (leaf) { > if (g_mime_content_type_is_type (content_type, "text", "*") && > - !g_mime_content_type_is_type (content_type, "text", "html")) > + (params->include_html || > + ! g_mime_content_type_is_type (content_type, "text", "html"))) > { > show_text_part_content (node->part, stream, 0); > } else { > @@ -1204,15 +1210,19 @@ notmuch_show_command (notmuch_config_t *config, > int argc, char *argv[]) > fprintf (stderr, "Warning: --body=false is incompatible with > --part > 0. Disabling.\n"); > params.output_body = true; > } else { > - if (format != NOTMUCH_FORMAT_JSON && format != > NOTMUCH_FORMAT_SEXP) > + if (format != NOTMUCH_FORMAT_TEXT && > + format != NOTMUCH_FORMAT_JSON && > + format != NOTMUCH_FORMAT_SEXP) > fprintf (stderr, > - "Warning: --body=false only implemented for format=json and > format=sexp\n"); > + "Warning: --body=false only implemented for format=text, > format=json and format=sexp\n"); > } > } > > if (params.include_html && > - (format != NOTMUCH_FORMAT_JSON && format != > NOTMUCH_FORMAT_SEXP)) { > - fprintf (stderr, "Warning: --include-html only implemented for > format=json and format=sexp\n"); > + (format != NOTMUCH_FORMAT_TEXT && > + format != NOTMUCH_FORMAT_JSON && > + format != NOTMUCH_FORMAT_SEXP)) { > + fprintf (stderr, "Warning: --include-html only implemented for > format=text, format=json and format=sexp\n"); > } > > query_string = query_string_from_args (config, argc-opt_index, > argv+opt_index); > diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh > index 3eeac1db..9ad141cb 100755 > --- a/test/T190-multipart.sh > +++ b/test/T190-multipart.sh > @@ -190,6 +190,21 @@ Non-text part: application/pgp-signature > EOF > test_expect_equal_file EXPECTED OUTPUT > > +test_begin_subtest "--format=text --part=0 --body=false, message > header" > +notmuch show --format=text --part=0 --body=false > 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT > +cat <EXPECTED > + message{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 > excluded:0 filename:${MAIL_DIR}/multipart > + header{ > +Carl Worth (2001-01-05) (attachment inbox signed > unread) > +Subject: Multipart message > +From: Carl Worth > +To: cworth@cworth.org > +Date: Fri, 05 Jan 2001 15:43:57 +0000 > + header} > + message} > +EOF > +test_expect_equal_file EXPECTED OUTPUT > + > test_begin_subtest "--format=text --part=1, message body" > notmuch show --format=text --part=1 > 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT > cat <EXPECTED > @@ -310,6 +325,15 @@ Non-text part: text/html > EOF > test_expect_equal_file EXPECTED OUTPUT > > +test_begin_subtest "--format=text --include-html --part=5, rfc822's > html part" > +notmuch show --format=text --include-html --part=5 > 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT > +cat <EXPECTED > + part{ ID: 5, Content-type: text/html > +

This is an embedded message, with a multipart/alternative part.

> + part} > +EOF > +test_expect_equal_file EXPECTED OUTPUT > + > test_begin_subtest "--format=text --part=6, rfc822's text part" > notmuch show --format=text --part=6 > 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT > cat <EXPECTED > -- > 2.14.5 > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch