unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] cli: add support for only printing the addresses in notmuch address
@ 2017-11-02 18:44 Jani Nikula
  2017-12-15 12:01 ` David Bremner
  2017-12-19 21:23 ` Jameson Graef Rollins
  0 siblings, 2 replies; 9+ messages in thread
From: Jani Nikula @ 2017-11-02 18:44 UTC (permalink / raw)
  To: notmuch

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
+allan@archlinux.org
+aur-general@archlinux.org
+olivier.berger@it-sudparis.eu
+notmuch@notmuchmail.org
+notmuch@notmuchmail.org
+keithp@keithp.com
+dottedmag@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	agriffis@n01se.net
+1	aperez@igalia.com
+1	boulogne.f@gmail.com
+1	chris@chris-wilson.co.uk
+1	ingmar@exherbo.org
+1	isra@herraiz.org
+1	olivier.berger@it-sudparis.eu
+1	rollandsantimano@yahoo.com
+2	alex.boterolowry@gmail.com
+2	gzjjgod@gmail.com
+3	stewart@flamingspork.com
+4	alex.boterolowry@gmail.com
+4	jan@ryngle.com
+5	dottedmag@dottedmag.net
+5	lars@seas.harvard.edu
+7	keithp@keithp.com
+12	cworth@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

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-11-02 18:44 [PATCH] cli: add support for only printing the addresses in notmuch address Jani Nikula
@ 2017-12-15 12:01 ` David Bremner
  2017-12-19 21:23 ` Jameson Graef Rollins
  1 sibling, 0 replies; 9+ messages in thread
From: David Bremner @ 2017-12-15 12:01 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

> The notmuch address output is much more useful for scripts with just
> the addresses printed. Support this using the --output=address option.

pushed to master

d

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-11-02 18:44 [PATCH] cli: add support for only printing the addresses in notmuch address Jani Nikula
  2017-12-15 12:01 ` David Bremner
@ 2017-12-19 21:23 ` Jameson Graef Rollins
  2017-12-20  1:12   ` Daniel Kahn Gillmor
  1 sibling, 1 reply; 9+ messages in thread
From: Jameson Graef Rollins @ 2017-12-19 21:23 UTC (permalink / raw)
  To: Jani Nikula, notmuch

[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

On Thu, Nov 02 2017, Jani Nikula <jani@nikula.org> wrote:
> The notmuch address output is much more useful for scripts with just
> the addresses printed. Support this using the --output=address option.

Isn't "address" kind of orthogonal to "sender" and "recipient"?  Isn't
this more like the --output/--format distinction in search?

jamie.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-12-19 21:23 ` Jameson Graef Rollins
@ 2017-12-20  1:12   ` Daniel Kahn Gillmor
  2017-12-20  1:25     ` Jameson Graef Rollins
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Kahn Gillmor @ 2017-12-20  1:12 UTC (permalink / raw)
  To: Jameson Graef Rollins, Jani Nikula, notmuch

On Tue 2017-12-19 13:23:55 -0800, Jameson Graef Rollins wrote:
> On Thu, Nov 02 2017, Jani Nikula <jani@nikula.org> wrote:
>> The notmuch address output is much more useful for scripts with just
>> the addresses printed. Support this using the --output=address option.
>
> Isn't "address" kind of orthogonal to "sender" and "recipient"?  Isn't
> this more like the --output/--format distinction in search?

i think i agree with Jamie here -- it'd be nice to be able to ask for
the addresses of the senders, or the addresses of the recipients.  how
would that be done here?

      --dkg

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-12-20  1:12   ` Daniel Kahn Gillmor
@ 2017-12-20  1:25     ` Jameson Graef Rollins
  2017-12-20  7:02       ` Jani Nikula
  0 siblings, 1 reply; 9+ messages in thread
From: Jameson Graef Rollins @ 2017-12-20  1:25 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Jani Nikula, notmuch

[-- Attachment #1: Type: text/plain, Size: 838 bytes --]

On Tue, Dec 19 2017, Daniel Kahn Gillmor <dkg@fifthhorseman.net> wrote:
> On Tue 2017-12-19 13:23:55 -0800, Jameson Graef Rollins wrote:
>> On Thu, Nov 02 2017, Jani Nikula <jani@nikula.org> wrote:
>>> The notmuch address output is much more useful for scripts with just
>>> the addresses printed. Support this using the --output=address option.
>>
>> Isn't "address" kind of orthogonal to "sender" and "recipient"?  Isn't
>> this more like the --output/--format distinction in search?
>
> i think i agree with Jamie here -- it'd be nice to be able to ask for
> the addresses of the senders, or the addresses of the recipients.  how
> would that be done here?

Sorry, I see now that address already has the --format option with the
expected values.  So I think either address-only or sender/recipient
should be a separate option.

jamie.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-12-20  1:25     ` Jameson Graef Rollins
@ 2017-12-20  7:02       ` Jani Nikula
  2017-12-20  7:16         ` Jameson Graef Rollins
  0 siblings, 1 reply; 9+ messages in thread
From: Jani Nikula @ 2017-12-20  7:02 UTC (permalink / raw)
  To: Jameson Graef Rollins, Daniel Kahn Gillmor, notmuch

On Tue, 19 Dec 2017, Jameson Graef Rollins <jrollins@finestructure.net> wrote:
> On Tue, Dec 19 2017, Daniel Kahn Gillmor <dkg@fifthhorseman.net> wrote:
>> On Tue 2017-12-19 13:23:55 -0800, Jameson Graef Rollins wrote:
>>> On Thu, Nov 02 2017, Jani Nikula <jani@nikula.org> wrote:
>>>> The notmuch address output is much more useful for scripts with just
>>>> the addresses printed. Support this using the --output=address option.
>>>
>>> Isn't "address" kind of orthogonal to "sender" and "recipient"?  Isn't
>>> this more like the --output/--format distinction in search?
>>
>> i think i agree with Jamie here -- it'd be nice to be able to ask for
>> the addresses of the senders, or the addresses of the recipients.  how
>> would that be done here?
>
> Sorry, I see now that address already has the --format option with the
> expected values.  So I think either address-only or sender/recipient
> should be a separate option.

Note that you can give the notmuch address --output option multiple
times to control the output. For example,

~$ notmuch address --output=sender --output=recipients id:878tdy8a2q.fsf@ligo.caltech.edu
Jameson Graef Rollins <jrollins@finestructure.net>
Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Jani Nikula <jani@nikula.org>
notmuch@notmuchmail.org

~$ notmuch address --output=recipients --output=address id:878tdy8a2q.fsf@ligo.caltech.edu
dkg@fifthhorseman.net
jani@nikula.org
notmuch@notmuchmail.org

~$ notmuch address --output=sender --output=recipients --output=address --output=count id:878tdy8a2q.fsf@ligo.caltech.edu
1	notmuch@notmuchmail.org
1	jrollins@finestructure.net
1	dkg@fifthhorseman.net
1	jani@nikula.org

I prefer this to separate options.

notmuch search uses separate --entire-thread, --body, and --include-html
options, and I think those are getting messy.

BR,
Jani.

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-12-20  7:02       ` Jani Nikula
@ 2017-12-20  7:16         ` Jameson Graef Rollins
  2017-12-20 11:15           ` Jani Nikula
  0 siblings, 1 reply; 9+ messages in thread
From: Jameson Graef Rollins @ 2017-12-20  7:16 UTC (permalink / raw)
  To: Jani Nikula, Daniel Kahn Gillmor, notmuch

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

On Wed, Dec 20 2017, Jani Nikula <jani@nikula.org> wrote:
> ~$ notmuch address --output=sender --output=recipients --output=address --output=count id:878tdy8a2q.fsf@ligo.caltech.edu
> 1	notmuch@notmuchmail.org
> 1	jrollins@finestructure.net
> 1	dkg@fifthhorseman.net
> 1	jani@nikula.org
>
> I prefer this to separate options.

Really?  If each is just a switch then why not:

~$ notmuch address --sender --recipients --address --count id:878tdy8a2q.fsf@ligo.caltech.edu

?  It's just shorter, right?

Also, this behavior is quite different than for search, in which only
the last --output applies.

> notmuch search uses separate --entire-thread, --body, and --include-html
> options, and I think those are getting messy.

The seem less messy than a "--output=" prefixed version of the same.

jamie.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-12-20  7:16         ` Jameson Graef Rollins
@ 2017-12-20 11:15           ` Jani Nikula
  2017-12-20 16:41             ` Jameson Graef Rollins
  0 siblings, 1 reply; 9+ messages in thread
From: Jani Nikula @ 2017-12-20 11:15 UTC (permalink / raw)
  To: Jameson Graef Rollins, Daniel Kahn Gillmor, notmuch

On Tue, 19 Dec 2017, Jameson Graef Rollins <jrollins@finestructure.net> wrote:
> On Wed, Dec 20 2017, Jani Nikula <jani@nikula.org> wrote:
>> ~$ notmuch address --output=sender --output=recipients --output=address --output=count id:878tdy8a2q.fsf@ligo.caltech.edu
>> 1	notmuch@notmuchmail.org
>> 1	jrollins@finestructure.net
>> 1	dkg@fifthhorseman.net
>> 1	jani@nikula.org
>>
>> I prefer this to separate options.
>
> Really?  If each is just a switch then why not:
>
> ~$ notmuch address --sender --recipients --address --count id:878tdy8a2q.fsf@ligo.caltech.edu
>
> ?  It's just shorter, right?
>
> Also, this behavior is quite different than for search, in which only
> the last --output applies.
>
>> notmuch search uses separate --entire-thread, --body, and --include-html
>> options, and I think those are getting messy.

That was supposed to be notmuch show, not search.

> The seem less messy than a "--output=" prefixed version of the same.

Matter of taste. I like the self-documenting aspect of *what* these
options control. --output=body is obvious, --body is less
so. --include-html includes html somewhere, I think --output=html would
be better.

In the spirit of worse is better, I'll note that using --output= stores
all the possible values in a single bit mask, and it's easy to define
the defaults for *all* possible outputs in one variable, and it's easy
to check *all* possible combinations with bit masks. Not so with
independent parameters. Again, matter of taste how much you appreciate
implementation simplicity. With notmuch show, I think that guideline
would have made the interface better too. YMMV.

As to notmuch address --output=address, it fulfills all the feature
needs that popped up in this thread. If there's a strong desired to
change the interface, we'll need patches as this one's already merged.

BR,
Jani.

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

* Re: [PATCH] cli: add support for only printing the addresses in notmuch address
  2017-12-20 11:15           ` Jani Nikula
@ 2017-12-20 16:41             ` Jameson Graef Rollins
  0 siblings, 0 replies; 9+ messages in thread
From: Jameson Graef Rollins @ 2017-12-20 16:41 UTC (permalink / raw)
  To: Jani Nikula, Daniel Kahn Gillmor, notmuch

[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]

On Wed, Dec 20 2017, Jani Nikula <jani@nikula.org> wrote:
> Matter of taste. I like the self-documenting aspect of *what* these
> options control. --output=body is obvious, --body is less
> so. --include-html includes html somewhere, I think --output=html would
> be better.
>
> In the spirit of worse is better, I'll note that using --output= stores
> all the possible values in a single bit mask, and it's easy to define
> the defaults for *all* possible outputs in one variable, and it's easy
> to check *all* possible combinations with bit masks. Not so with
> independent parameters. Again, matter of taste how much you appreciate
> implementation simplicity. With notmuch show, I think that guideline
> would have made the interface better too. YMMV.
>
> As to notmuch address --output=address, it fulfills all the feature
> needs that popped up in this thread. If there's a strong desired to
> change the interface, we'll need patches as this one's already merged.

I'm less interested in specific argument formatting than I am in
consistency across the interface.  I just don't like how --output= now
has quite different semantics between the different sub commands.  That
seems like the wrong direction to me.

jamie.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

end of thread, other threads:[~2017-12-20 16:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-02 18:44 [PATCH] cli: add support for only printing the addresses in notmuch address Jani Nikula
2017-12-15 12:01 ` David Bremner
2017-12-19 21:23 ` Jameson Graef Rollins
2017-12-20  1:12   ` Daniel Kahn Gillmor
2017-12-20  1:25     ` Jameson Graef Rollins
2017-12-20  7:02       ` Jani Nikula
2017-12-20  7:16         ` Jameson Graef Rollins
2017-12-20 11:15           ` Jani Nikula
2017-12-20 16:41             ` Jameson Graef Rollins

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).