The notmuch address output is much more useful for scripts with just
the addresses printed. Support this using the --output=address option.
---
 completion/notmuch-completion.bash |  2 +-
 doc/man1/notmuch-address.rst       |  7 ++++++-
 notmuch-search.c                   |  7 ++++++-
 test/T095-address.sh               | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/completion/notmuch-completion.bash 
b/completion/notmuch-completion.bash
index 7aae4297ae0e..4e94275e3193 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -468,7 +468,7 @@ _notmuch_address()
            return
            ;;
        --output)
-           COMPREPLY=( $( compgen -W "sender recipients count" -- "${cur}" ) )
+           COMPREPLY=( $( compgen -W "sender recipients count address" -- 
"${cur}" ) )
            return
            ;;
        --sort)
diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst
index dbac20f7b012..68415d13c5b6 100644
--- a/doc/man1/notmuch-address.rst
+++ b/doc/man1/notmuch-address.rst
@@ -29,7 +29,7 @@ Supported options for **address** include
         intended for programs that invoke **notmuch(1)** internally. If
         omitted, the latest supported version will be used.
 
-    ``--output=(sender|recipients|count)``
+    ``--output=(sender|recipients|count|address)``
 
         Controls which information appears in the output. This option
         can be given multiple times to combine different outputs.
@@ -55,6 +55,11 @@ Supported options for **address** include
             Note: With this option, addresses are printed only after
             the whole search is finished. This may take long time.
 
+        **address**
+            Output only the email addresses instead of the full
+            mailboxes with names and email addresses. This option has
+            no effect on the JSON or S-Expression output formats.
+
     ``--deduplicate=(no|mailbox|address)``
 
         Control the deduplication of results.
diff --git a/notmuch-search.c b/notmuch-search.c
index 0abac08eb7ab..8f467db43cf0 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -34,6 +34,7 @@ typedef enum {
     OUTPUT_SENDER      = 1 << 5,
     OUTPUT_RECIPIENTS  = 1 << 6,
     OUTPUT_COUNT       = 1 << 7,
+    OUTPUT_ADDRESS     = 1 << 8,
 } output_t;
 
 typedef enum {
@@ -370,7 +371,10 @@ print_mailbox (const search_context_t *ctx, const 
mailbox_t *mailbox)
            format->integer (format, count);
            format->string (format, "\t");
        }
-       format->string (format, name_addr);
+       if (ctx->output & OUTPUT_ADDRESS)
+           format->string (format, addr);
+       else
+           format->string (format, name_addr);
        format->separator (format);
     } else {
        format->begin_map (format);
@@ -877,6 +881,7 @@ notmuch_address_command (notmuch_config_t *config, int 
argc, char *argv[])
          (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER },
                                  { "recipients", OUTPUT_RECIPIENTS },
                                  { "count", OUTPUT_COUNT },
+                                 { "address", OUTPUT_ADDRESS },
                                  { 0, 0 } } },
        { .opt_keyword = &ctx->exclude, .name = "exclude", .keywords =
          (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
diff --git a/test/T095-address.sh b/test/T095-address.sh
index f0291d29ec43..817be5380a45 100755
--- a/test/T095-address.sh
+++ b/test/T095-address.sh
@@ -119,6 +119,42 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "--output=recipients --output=address"
+notmuch address --output=recipients --output=address '*' >OUTPUT
+cat <<EOF >EXPECTED
+al...@archlinux.org
+aur-gene...@archlinux.org
+olivier.ber...@it-sudparis.eu
+notmuch@notmuchmail.org
+notmuch@notmuchmail.org
+kei...@keithp.com
+dotted...@dottedmag.net
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "--output=sender --output=address --output=count"
+notmuch address --output=sender --output=address --output=count '*' | sort -n 
>OUTPUT
+cat <<EOF >EXPECTED
+1      agrif...@n01se.net
+1      ape...@igalia.com
+1      boulogn...@gmail.com
+1      ch...@chris-wilson.co.uk
+1      ing...@exherbo.org
+1      i...@herraiz.org
+1      olivier.ber...@it-sudparis.eu
+1      rollandsantim...@yahoo.com
+2      alex.boterolo...@gmail.com
+2      gzjj...@gmail.com
+3      stew...@flamingspork.com
+4      alex.boterolo...@gmail.com
+4      j...@ryngle.com
+5      dotted...@dottedmag.net
+5      l...@seas.harvard.edu
+7      kei...@keithp.com
+12     cwo...@cworth.org
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_begin_subtest "--output=count --format=json"
 # Since the iteration order of GHashTable is not specified, we
 # preprocess and sort the results to keep the order stable here.
-- 
2.11.0

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to