unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] cli: Support --include-html and --body=false for --format=text
@ 2018-10-25  1:44 mawww
  2018-10-25 18:55 ` Jani Nikula
  0 siblings, 1 reply; 10+ messages in thread
From: mawww @ 2018-10-25  1:44 UTC (permalink / raw)
  To: notmuch

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.
---
  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:<thread-id>" 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 <<EOF >EXPECTED
+\fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 
excluded:0 filename:${MAIL_DIR}/multipart
+\fheader{
+Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed 
unread)
+Subject: Multipart message
+From: Carl Worth <cworth@cworth.org>
+To: cworth@cworth.org
+Date: Fri, 05 Jan 2001 15:43:57 +0000
+\fheader}
+\fmessage}
+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 <<EOF >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 <<EOF >EXPECTED
+\fpart{ ID: 5, Content-type: text/html
+<p>This is an embedded message, with a multipart/alternative part.</p>
+\fpart}
+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 <<EOF >EXPECTED
-- 
2.14.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] cli: Support --include-html and --body=false for --format=text
  2018-10-25  1:44 [PATCH] cli: Support --include-html and --body=false for --format=text mawww
@ 2018-10-25 18:55 ` Jani Nikula
  2018-10-26  2:12   ` mawww
  0 siblings, 1 reply; 10+ messages in thread
From: Jani Nikula @ 2018-10-25 18:55 UTC (permalink / raw)
  To: mawww, notmuch

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:<thread-id>" 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 <<EOF >EXPECTED
> +\fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 
> excluded:0 filename:${MAIL_DIR}/multipart
> +\fheader{
> +Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed 
> unread)
> +Subject: Multipart message
> +From: Carl Worth <cworth@cworth.org>
> +To: cworth@cworth.org
> +Date: Fri, 05 Jan 2001 15:43:57 +0000
> +\fheader}
> +\fmessage}
> +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 <<EOF >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 <<EOF >EXPECTED
> +\fpart{ ID: 5, Content-type: text/html
> +<p>This is an embedded message, with a multipart/alternative part.</p>
> +\fpart}
> +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 <<EOF >EXPECTED
> -- 
> 2.14.5
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] cli: Support --include-html and --body=false for --format=text
  2018-10-25 18:55 ` Jani Nikula
@ 2018-10-26  2:12   ` mawww
  2018-10-28 12:56     ` David Bremner
  0 siblings, 1 reply; 10+ messages in thread
From: mawww @ 2018-10-26  2:12 UTC (permalink / raw)
  To: notmuch

On 2018-10-26 05:55, Jani Nikula wrote:
> 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.

I would argue that it is easier to work with with shell tools than
sexpression or json, but even if it was not, this change is pretty 
trivial
and does not add a brand new feature to the text format, it just makes
it possible to use existing features (include-html and body=false) with 
it.

> In any case, this patch has two independent changes in one, and should
> be split.

Following are the splitted commits.

 From afd74f5a7506704d4459d01a4d347d8b57293cc5 Mon Sep 17 00:00:00 2001
 From: Maxime Coste <mawww@kakoune.org>
Date: Fri, 26 Oct 2018 13:01:24 +1100
Subject: [PATCH 1/2] cli: notmuch show support for --body=false with
  --format=text

---
  NEWS                      |  8 ++++++++
  doc/man1/notmuch-show.rst |  4 ++--
  notmuch-show.c            | 11 +++++++++--
  test/T190-multipart.sh    | 15 +++++++++++++++
  4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index ca3ba99e..64de9999 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+Notmuch 0.29 (UNRELEASED)
+=========================
+
+Command Line Interface
+----------------------
+
+`notmuch show` now supports --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..f3c32fd2 100644
--- a/doc/man1/notmuch-show.rst
+++ b/doc/man1/notmuch-show.rst
@@ -176,8 +176,8 @@ 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.
diff --git a/notmuch-show.c b/notmuch-show.c
index c3a3783a..42fe27cc 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -574,6 +574,11 @@ 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");
      }

@@ -1204,9 +1209,11 @@ 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");
  	}
      }

diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
index 3eeac1db..81c4d772 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 <<EOF >EXPECTED
+\fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 
excluded:0 filename:${MAIL_DIR}/multipart
+\fheader{
+Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed 
unread)
+Subject: Multipart message
+From: Carl Worth <cworth@cworth.org>
+To: cworth@cworth.org
+Date: Fri, 05 Jan 2001 15:43:57 +0000
+\fheader}
+\fmessage}
+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 <<EOF >EXPECTED
-- 
2.14.5


 From af20160c28e26426825a959911c4f0c4d5950048 Mon Sep 17 00:00:00 2001
 From: Maxime Coste <mawww@kakoune.org>
Date: Fri, 26 Oct 2018 13:02:11 +1100
Subject: [PATCH 2/2] cli: notmuch show support for --include-html with
  --format=text

---
  NEWS                      |  3 ++-
  doc/man1/notmuch-show.rst | 11 ++++++-----
  notmuch-show.c            |  9 ++++++---
  test/T190-multipart.sh    |  9 +++++++++
  4 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index 64de9999..434f920a 100644
--- a/NEWS
+++ b/NEWS
@@ -4,7 +4,8 @@ Notmuch 0.29 (UNRELEASED)
  Command Line Interface
  ----------------------

-`notmuch show` now supports --body=false with --format=text
+`notmuch show` now supports --body=false and --include-html with
+--format=text

  Notmuch 0.28 (2018-10-12)
  =========================
diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst
index f3c32fd2..a2708a04 100644
--- a/doc/man1/notmuch-show.rst
+++ b/doc/man1/notmuch-show.rst
@@ -183,11 +183,12 @@ Supported options for **show** include
      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:<thread-id>" as can be
diff --git a/notmuch-show.c b/notmuch-show.c
index 42fe27cc..07e9a5db 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -584,7 +584,8 @@ format_part_text (const void *ctx, sprinter_t *sp, 
mime_node_t *node,

      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 {
@@ -1218,8 +1219,10 @@ notmuch_show_command (notmuch_config_t *config, 
int argc, char *argv[])
      }

      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 81c4d772..9ad141cb 100755
--- a/test/T190-multipart.sh
+++ b/test/T190-multipart.sh
@@ -325,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 <<EOF >EXPECTED
+\fpart{ ID: 5, Content-type: text/html
+<p>This is an embedded message, with a multipart/alternative part.</p>
+\fpart}
+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 <<EOF >EXPECTED
-- 
2.14.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] cli: Support --include-html and --body=false for --format=text
  2018-10-26  2:12   ` mawww
@ 2018-10-28 12:56     ` David Bremner
  2018-10-30 23:54       ` [PATCH 1/2] cli: notmuch show support for --body=false with --format=text mawww
  0 siblings, 1 reply; 10+ messages in thread
From: David Bremner @ 2018-10-28 12:56 UTC (permalink / raw)
  To: mawww, notmuch

mawww@kakoune.org writes:

> On 2018-10-26 05:55, Jani Nikula wrote:
>> 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.
>
> I would argue that it is easier to work with with shell tools than
> sexpression or json, but even if it was not, this change is pretty 
> trivial
> and does not add a brand new feature to the text format, it just makes
> it possible to use existing features (include-html and body=false) with 
> it.
>
>> In any case, this patch has two independent changes in one, and should
>> be split.
>
> Following are the splitted commits.
>

Please re-send using git-send-email when you have a chance.

d

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] cli: notmuch show support for --body=false with --format=text
  2018-10-28 12:56     ` David Bremner
@ 2018-10-30 23:54       ` mawww
  2018-10-30 23:54         ` [PATCH 2/2] cli: notmuch show support for --include-html " mawww
  0 siblings, 1 reply; 10+ messages in thread
From: mawww @ 2018-10-30 23:54 UTC (permalink / raw)
  To: notmuch

From: Maxime Coste <mawww@kakoune.org>

---
 NEWS                      |  8 ++++++++
 doc/man1/notmuch-show.rst |  4 ++--
 notmuch-show.c            | 11 +++++++++--
 test/T190-multipart.sh    | 15 +++++++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index ca3ba99e..64de9999 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+Notmuch 0.29 (UNRELEASED)
+=========================
+
+Command Line Interface
+----------------------
+
+`notmuch show` now supports --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..f3c32fd2 100644
--- a/doc/man1/notmuch-show.rst
+++ b/doc/man1/notmuch-show.rst
@@ -176,8 +176,8 @@ 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.
diff --git a/notmuch-show.c b/notmuch-show.c
index c3a3783a..42fe27cc 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -574,6 +574,11 @@ 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");
     }
 
@@ -1204,9 +1209,11 @@ 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");
 	}
     }
 
diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
index 3eeac1db..81c4d772 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 <<EOF >EXPECTED
+\fmessage{ id:87liy5ap00.fsf@yoom.home.cworth.org depth:0 match:1 excluded:0 filename:${MAIL_DIR}/multipart
+\fheader{
+Carl Worth <cworth@cworth.org> (2001-01-05) (attachment inbox signed unread)
+Subject: Multipart message
+From: Carl Worth <cworth@cworth.org>
+To: cworth@cworth.org
+Date: Fri, 05 Jan 2001 15:43:57 +0000
+\fheader}
+\fmessage}
+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 <<EOF >EXPECTED
-- 
2.14.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] cli: notmuch show support for --include-html with --format=text
  2018-10-30 23:54       ` [PATCH 1/2] cli: notmuch show support for --body=false with --format=text mawww
@ 2018-10-30 23:54         ` mawww
  2018-11-16  3:05           ` mawww
  2018-11-23 19:24           ` Tomi Ollila
  0 siblings, 2 replies; 10+ messages in thread
From: mawww @ 2018-10-30 23:54 UTC (permalink / raw)
  To: notmuch

From: Maxime Coste <mawww@kakoune.org>

---
 NEWS                      |  3 ++-
 doc/man1/notmuch-show.rst | 11 ++++++-----
 notmuch-show.c            |  9 ++++++---
 test/T190-multipart.sh    |  9 +++++++++
 4 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index 64de9999..434f920a 100644
--- a/NEWS
+++ b/NEWS
@@ -4,7 +4,8 @@ Notmuch 0.29 (UNRELEASED)
 Command Line Interface
 ----------------------
 
-`notmuch show` now supports --body=false with --format=text
+`notmuch show` now supports --body=false and --include-html with
+--format=text
 
 Notmuch 0.28 (2018-10-12)
 =========================
diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst
index f3c32fd2..a2708a04 100644
--- a/doc/man1/notmuch-show.rst
+++ b/doc/man1/notmuch-show.rst
@@ -183,11 +183,12 @@ Supported options for **show** include
     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:<thread-id>" as can be
diff --git a/notmuch-show.c b/notmuch-show.c
index 42fe27cc..07e9a5db 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -584,7 +584,8 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 
     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 {
@@ -1218,8 +1219,10 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
     }
 
     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 81c4d772..9ad141cb 100755
--- a/test/T190-multipart.sh
+++ b/test/T190-multipart.sh
@@ -325,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 <<EOF >EXPECTED
+\fpart{ ID: 5, Content-type: text/html
+<p>This is an embedded message, with a multipart/alternative part.</p>
+\fpart}
+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 <<EOF >EXPECTED
-- 
2.14.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] cli: notmuch show support for --include-html with --format=text
  2018-10-30 23:54         ` [PATCH 2/2] cli: notmuch show support for --include-html " mawww
@ 2018-11-16  3:05           ` mawww
  2018-11-19 14:07             ` David Bremner
  2018-11-23 19:24           ` Tomi Ollila
  1 sibling, 1 reply; 10+ messages in thread
From: mawww @ 2018-11-16  3:05 UTC (permalink / raw)
  To: notmuch

Hello

Any progress on merging those patches ?

Is there anything I should do ?

Cheers,

Maxime.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] cli: notmuch show support for --include-html with --format=text
  2018-11-16  3:05           ` mawww
@ 2018-11-19 14:07             ` David Bremner
  0 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2018-11-19 14:07 UTC (permalink / raw)
  To: mawww, notmuch

mawww@kakoune.org writes:

> Hello
>
> Any progress on merging those patches ?
>
> Is there anything I should do ?
>

I think it's waiting for review on our side now. Unfortunately I'm
personally very busy with $DAYJOB atm.

d

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] cli: notmuch show support for --include-html with --format=text
  2018-10-30 23:54         ` [PATCH 2/2] cli: notmuch show support for --include-html " mawww
  2018-11-16  3:05           ` mawww
@ 2018-11-23 19:24           ` Tomi Ollila
  2018-11-24 13:19             ` David Bremner
  1 sibling, 1 reply; 10+ messages in thread
From: Tomi Ollila @ 2018-11-23 19:24 UTC (permalink / raw)
  To: mawww, notmuch

On Wed, Oct 31 2018, mawww@kakoune.org wrote:

> From: Maxime Coste <mawww@kakoune.org>

To me these changes looks simple and trivial enough to be merged
(if these works, but code LGTM)

Tomi


>
> ---
>  NEWS                      |  3 ++-
>  doc/man1/notmuch-show.rst | 11 ++++++-----
>  notmuch-show.c            |  9 ++++++---
>  test/T190-multipart.sh    |  9 +++++++++
>  4 files changed, 23 insertions(+), 9 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index 64de9999..434f920a 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -4,7 +4,8 @@ Notmuch 0.29 (UNRELEASED)
>  Command Line Interface
>  ----------------------
>  
> -`notmuch show` now supports --body=false with --format=text
> +`notmuch show` now supports --body=false and --include-html with
> +--format=text
>  
>  Notmuch 0.28 (2018-10-12)
>  =========================
> diff --git a/doc/man1/notmuch-show.rst b/doc/man1/notmuch-show.rst
> index f3c32fd2..a2708a04 100644
> --- a/doc/man1/notmuch-show.rst
> +++ b/doc/man1/notmuch-show.rst
> @@ -183,11 +183,12 @@ Supported options for **show** include
>      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:<thread-id>" as can be
> diff --git a/notmuch-show.c b/notmuch-show.c
> index 42fe27cc..07e9a5db 100644
> --- a/notmuch-show.c
> +++ b/notmuch-show.c
> @@ -584,7 +584,8 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
>  
>      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 {
> @@ -1218,8 +1219,10 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
>      }
>  
>      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 81c4d772..9ad141cb 100755
> --- a/test/T190-multipart.sh
> +++ b/test/T190-multipart.sh
> @@ -325,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 <<EOF >EXPECTED
> +\fpart{ ID: 5, Content-type: text/html
> +<p>This is an embedded message, with a multipart/alternative part.</p>
> +\fpart}
> +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 <<EOF >EXPECTED
> -- 
> 2.14.5
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] cli: notmuch show support for --include-html with --format=text
  2018-11-23 19:24           ` Tomi Ollila
@ 2018-11-24 13:19             ` David Bremner
  0 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2018-11-24 13:19 UTC (permalink / raw)
  To: Tomi Ollila, mawww, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:

> On Wed, Oct 31 2018, mawww@kakoune.org wrote:
>
>> From: Maxime Coste <mawww@kakoune.org>
>
> To me these changes looks simple and trivial enough to be merged
> (if these works, but code LGTM)
>

pushed to master

d

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-11-24 13:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-25  1:44 [PATCH] cli: Support --include-html and --body=false for --format=text mawww
2018-10-25 18:55 ` Jani Nikula
2018-10-26  2:12   ` mawww
2018-10-28 12:56     ` David Bremner
2018-10-30 23:54       ` [PATCH 1/2] cli: notmuch show support for --body=false with --format=text mawww
2018-10-30 23:54         ` [PATCH 2/2] cli: notmuch show support for --include-html " mawww
2018-11-16  3:05           ` mawww
2018-11-19 14:07             ` David Bremner
2018-11-23 19:24           ` Tomi Ollila
2018-11-24 13:19             ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).