--- /dev/null
+Return-Path: <sojkam1@fel.cvut.cz>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id A0849431FDD\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 03:57:30 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id ftc+qzG-5rJh for <notmuch@notmuchmail.org>;\r
+ Fri, 24 Oct 2014 03:57:23 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id 11DC9431FBD\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 03:57:23 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.7])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id B8B3B3CFEE6;\r
+ Fri, 24 Oct 2014 12:57:21 +0200 (CEST)\r
+X-Virus-Scanned: IMAP STYX AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+ by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
+ port 10044)\r
+ with ESMTP id 1IznQ5zjB6qN; Fri, 24 Oct 2014 12:57:16 +0200 (CEST)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id CE5325CCF00;\r
+ Fri, 24 Oct 2014 12:57:16 +0200 (CEST)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+ (envelope-from <sojkam1@fel.cvut.cz>)\r
+ id 1XhcYW-0004pj-PB; Fri, 24 Oct 2014 12:57:16 +0200\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 3/4] cli: Extend the search command for\r
+ --output={sender, recipients}\r
+In-Reply-To: <87mw8obcob.fsf@qmul.ac.uk>\r
+References: <87zjd51phx.fsf@steelpick.2x.cz>\r
+ <1413150093-8383-1-git-send-email-sojkam1@fel.cvut.cz>\r
+ <1413150093-8383-4-git-send-email-sojkam1@fel.cvut.cz>\r
+ <87mw8obcob.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.18.1+101~g56b0ff0 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Fri, 24 Oct 2014 12:57:16 +0200\r
+Message-ID: <87fvedag6r.fsf@steelpick.2x.cz>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 24 Oct 2014 10:57:30 -0000\r
+\r
+Hi Mark,\r
+\r
+I mostly agree with your points mentioned in this and other your emails.\r
+I'll prepare v4 based on that.\r
+\r
+On Wed, Oct 22 2014, Mark Walters wrote:\r
+> On Sun, 12 Oct 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
+>> The new outputs allow printing senders, recipients or both of matching\r
+>> messages. The --output option is converted from "keyword" argument to\r
+>> "flags" argument, which means that the user can use --output=3Dsender and\r
+>> --output=3Drecipients simultaneously, to print both. Other combinations\r
+>> produce an error.\r
+>>\r
+>> This code based on a patch from Jani Nikula.\r
+>> ---\r
+>> completion/notmuch-completion.bash | 2 +-\r
+>> completion/notmuch-completion.zsh | 3 +-\r
+>> doc/man1/notmuch-search.rst | 22 +++++++-\r
+>> notmuch-search.c | 110 ++++++++++++++++++++++++++++++=\r
+++++---\r
+>> test/T090-search-output.sh | 64 +++++++++++++++++++++\r
+>> 5 files changed, 189 insertions(+), 12 deletions(-)\r
+>>\r
+>> diff --git a/completion/notmuch-completion.bash b/completion/notmuch-com=\r
+pletion.bash\r
+>> index 0571dc9..cfbd389 100644\r
+>> --- a/completion/notmuch-completion.bash\r
+>> +++ b/completion/notmuch-completion.bash\r
+>> @@ -294,7 +294,7 @@ _notmuch_search()\r
+>> return\r
+>> ;;\r
+>> --output)\r
+>> - COMPREPLY=3D( $( compgen -W "summary threads messages files tags" =\r
+-- "${cur}" ) )\r
+>> + COMPREPLY=3D( $( compgen -W "summary threads messages files tags s=\r
+ender recipients" -- "${cur}" ) )\r
+>> return\r
+>> ;;\r
+>> --sort)\r
+>> diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-comp=\r
+letion.zsh\r
+>> index 67a9aba..3e52a00 100644\r
+>> --- a/completion/notmuch-completion.zsh\r
+>> +++ b/completion/notmuch-completion.zsh\r
+>> @@ -52,7 +52,8 @@ _notmuch_search()\r
+>> _arguments -s : \\r
+>> '--max-threads=3D[display only the first x threads from the search =\r
+results]:number of threads to show: ' \\r
+>> '--first=3D[omit the first x threads from the search results]:numbe=\r
+r of threads to omit: ' \\r
+>> - '--sort=3D[sort results]:sorting:((newest-first\:"reverse chronolog=\r
+ical order" oldest-first\:"chronological order"))'\r
+>> + '--sort=3D[sort results]:sorting:((newest-first\:"reverse chronolog=\r
+ical order" oldest-first\:"chronological order"))' \\r
+>> + '--output=3D[select what to output]:output:((summary threads messag=\r
+es files tags sender recipients))'\r
+>> }\r
+>>\r
+>> _notmuch()\r
+>> diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst\r
+>> index 90160f2..c9d38b1 100644\r
+>> --- a/doc/man1/notmuch-search.rst\r
+>> +++ b/doc/man1/notmuch-search.rst\r
+>> @@ -35,7 +35,7 @@ Supported options for **search** include\r
+>> intended for programs that invoke **notmuch(1)** internally. If\r
+>> omitted, the latest supported version will be used.\r
+>>\r
+>> - ``--output=3D(summary|threads|messages|files|tags)``\r
+>> + ``--output=3D(summary|threads|messages|files|tags|sender|recipients=\r
+)``\r
+>>\r
+>> **summary**\r
+>> Output a summary of each thread with any message matching\r
+>> @@ -78,6 +78,26 @@ Supported options for **search** include\r
+>> by null characters (--format=3Dtext0), as a JSON array\r
+>> (--format=3Djson), or as an S-Expression list (--format=3Ds=\r
+exp).\r
+>>\r
+>> + **sender**\r
+>> + Output all addresses from the *From* header that appear on\r
+>> + any message matching the search terms, either one per line\r
+>> + (--format=3Dtext), separated by null characters\r
+>> + (--format=3Dtext0), as a JSON array (--format=3Djson), or as\r
+>> + an S-Expression list (--format=3Dsexp).\r
+>> +\r
+>> + Note: Searching for **sender** should be much faster than\r
+>> + searching for **recipients**, because sender addresses are\r
+>> + cached directly in the database whereas other addresses\r
+>> + need to be fetched from message files.\r
+>> +\r
+>> + **recipients**\r
+>> + Like **sender** but for addresses from *To*, *Cc* and\r
+>> + *Bcc* headers.\r
+>> +\r
+>> + This option can be given multiple times to combine different\r
+>> + outputs. Curently, this is only supported for **sender** and\r
+>> + **recipients** outputs.\r
+>> +\r
+>> ``--sort=3D``\ (**newest-first**\ \|\ **oldest-first**)\r
+>> This option can be used to present results in either\r
+>> chronological order (**oldest-first**) or reverse chronological\r
+>> diff --git a/notmuch-search.c b/notmuch-search.c\r
+>> index 5ac2a26..74588f8 100644\r
+>> --- a/notmuch-search.c\r
+>> +++ b/notmuch-search.c\r
+>> @@ -23,11 +23,14 @@\r
+>> #include "string-util.h"\r
+>>\r
+>> typedef enum {\r
+>> - OUTPUT_SUMMARY,\r
+>> - OUTPUT_THREADS,\r
+>> - OUTPUT_MESSAGES,\r
+>> - OUTPUT_FILES,\r
+>> - OUTPUT_TAGS\r
+>> + OUTPUT_SUMMARY =3D 1 << 0,\r
+>> + OUTPUT_THREADS =3D 1 << 1,\r
+>> + OUTPUT_MESSAGES =3D 1 << 2,\r
+>> + OUTPUT_FILES =3D 1 << 3,\r
+>> + OUTPUT_TAGS =3D 1 << 4,\r
+>> + OUTPUT_SENDER =3D 1 << 5,\r
+>> + OUTPUT_RECIPIENTS =3D 1 << 6,\r
+>> + OUTPUT_ADDRESSES =3D OUTPUT_SENDER | OUTPUT_RECIPIENTS,\r
+>\r
+> I think I would drop the OUTPUT_ADDRESSES enum as the parser no longer\r
+> uses it (and replace the one use by OUTPUT_SENDER | OUTPUT_RECIPIENTS\r
+> below).\r
+\r
+As mentioned elsewhere, this is required to suppress the following warning.\r
+\r
+notmuch-search.c:634:5: warning: case value =E2=80=9896=E2=80=99 not in enu=\r
+merated type =E2=80=98output_t=E2=80=99 [-Wswitch]\r
+\r
+>\r
+>> } output_t;\r
+>>\r
+>> typedef struct {\r
+>> @@ -220,6 +223,67 @@ do_search_threads (search_options_t *o)\r
+>> return 0;\r
+>> }\r
+>>\r
+>> +static void\r
+>> +print_address_list (const search_options_t *o, InternetAddressList *lis=\r
+t)\r
+>> +{\r
+>> + InternetAddress *address;\r
+>> + int i;\r
+>> +\r
+>> + for (i =3D 0; i < internet_address_list_length (list); i++) {\r
+>> + address =3D internet_address_list_get_address (list, i);\r
+>> + if (INTERNET_ADDRESS_IS_GROUP (address)) {\r
+>> + InternetAddressGroup *group;\r
+>> + InternetAddressList *group_list;\r
+>> +\r
+>> + group =3D INTERNET_ADDRESS_GROUP (address);\r
+>> + group_list =3D internet_address_group_get_members (group);\r
+>> + if (group_list =3D=3D NULL)\r
+>> + continue;\r
+>> +\r
+>> + print_address_list (o, group_list);\r
+>> + } else {\r
+>> + InternetAddressMailbox *mailbox;\r
+>> + const char *name;\r
+>> + const char *addr;\r
+>> + char *full_address;\r
+>> +\r
+>> + mailbox =3D INTERNET_ADDRESS_MAILBOX (address);\r
+>> +\r
+>> + name =3D internet_address_get_name (address);\r
+>> + addr =3D internet_address_mailbox_get_addr (mailbox);\r
+>> +\r
+>> + if (name && *name)\r
+>> + full_address =3D talloc_asprintf (o->format, "%s <%s>", name, addr);\r
+>> + else\r
+>> + full_address =3D talloc_strdup (o->format, addr);\r
+>> +\r
+>> + if (!full_address) {\r
+>> + fprintf (stderr, "Error: out of memory\n");\r
+>> + break;\r
+>> + }\r
+>> + o->format->string (o->format, full_address);\r
+>> + o->format->separator (o->format);\r
+>> +\r
+>> + talloc_free (full_address);\r
+>> + }\r
+>> + }\r
+>> +}\r
+>> +\r
+>> +static void\r
+>> +print_address_string (const search_options_t *o, const char *recipients)\r
+>> +{\r
+>> + InternetAddressList *list;\r
+>> +\r
+>> + if (recipients =3D=3D NULL)\r
+>> + return;\r
+>> +\r
+>> + list =3D internet_address_list_parse_string (recipients);\r
+>> + if (list =3D=3D NULL)\r
+>> + return;\r
+>> +\r
+>> + print_address_list (o, list);\r
+>> +}\r
+>> +\r
+>> static int\r
+>> do_search_messages (search_options_t *o)\r
+>> {\r
+>> @@ -266,11 +330,29 @@ do_search_messages (search_options_t *o)\r
+>>\r
+>> notmuch_filenames_destroy( filenames );\r
+>>\r
+>> - } else { /* output =3D=3D OUTPUT_MESSAGES */\r
+>> + } else if (o->output =3D=3D OUTPUT_MESSAGES) {\r
+>> format->set_prefix (format, "id");\r
+>> format->string (format,\r
+>> notmuch_message_get_message_id (message));\r
+>> format->separator (format);\r
+>> + } else {\r
+>> + if (o->output & OUTPUT_SENDER) {\r
+>> + const char *addrs;\r
+>> +\r
+>> + addrs =3D notmuch_message_get_header (message, "from");\r
+>> + print_address_string (o, addrs);\r
+>> + }\r
+>> +\r
+>> + if (o->output & OUTPUT_RECIPIENTS) {\r
+>> + const char *hdrs[] =3D { "to", "cc", "bcc" };\r
+>> + const char *addrs;\r
+>> + size_t j;\r
+>> +\r
+>> + for (j =3D 0; j < ARRAY_SIZE (hdrs); j++) {\r
+>> + addrs =3D notmuch_message_get_header (message, hdrs[j]);\r
+>> + print_address_string (o, addrs);\r
+>> + }\r
+>> + }\r
+>> }\r
+>>\r
+>> notmuch_message_destroy (message);\r
+>> @@ -337,7 +419,7 @@ notmuch_search_command (notmuch_config_t *config, in=\r
+t argc, char *argv[])\r
+>> notmuch_database_t *notmuch;\r
+>> search_options_t o =3D {\r
+>> .sort =3D NOTMUCH_SORT_NEWEST_FIRST,\r
+>> - .output =3D OUTPUT_SUMMARY,\r
+>> + .output =3D 0,\r
+>> .offset =3D 0,\r
+>> .limit =3D -1, /* unlimited */\r
+>> .dupe =3D -1,\r
+>\r
+> It is slightly unfortunate that all the other defaults are defined here\r
+> but the default output is after the option parsing but I can't see a\r
+> nice way round that. I only mention it in case you (or anyone else) can\r
+> see a nice way round this.\r
+\r
+Solution would to have --output as NOTMUCH_OPT_KEYWORD rather than\r
+NOTMUCH_OPT_KEYWORD_FLAGS as it was in v2.\r
+\r
+>\r
+>> @@ -366,10 +448,12 @@ notmuch_search_command (notmuch_config_t *config, =\r
+int argc, char *argv[])\r
+>> { "text0", NOTMUCH_FORMAT_TEXT0 },\r
+>> { 0, 0 } } },\r
+>> { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },\r
+>> - { NOTMUCH_OPT_KEYWORD, &o.output, "output", 'o',\r
+>> + { NOTMUCH_OPT_KEYWORD_FLAGS, &o.output, "output", 'o',\r
+>> (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
+>> { "threads", OUTPUT_THREADS },\r
+>> { "messages", OUTPUT_MESSAGES },\r
+>> + { "sender", OUTPUT_SENDER },\r
+>> + { "recipients", OUTPUT_RECIPIENTS },\r
+>> { "files", OUTPUT_FILES },\r
+>> { "tags", OUTPUT_TAGS },\r
+>> { 0, 0 } } },\r
+>> @@ -389,6 +473,9 @@ notmuch_search_command (notmuch_config_t *config, in=\r
+t argc, char *argv[])\r
+>> if (opt_index < 0)\r
+>> return EXIT_FAILURE;\r
+>>\r
+>> + if (! o.output)\r
+>> + o.output =3D OUTPUT_SUMMARY;\r
+>> +\r
+>> switch (format_sel) {\r
+>> case NOTMUCH_FORMAT_TEXT:\r
+>> o.format =3D sprinter_text_create (config, stdout);\r
+>> @@ -455,18 +542,23 @@ notmuch_search_command (notmuch_config_t *config, =\r
+int argc, char *argv[])\r
+>> }\r
+>>\r
+>> switch (o.output) {\r
+>> - default:\r
+>> case OUTPUT_SUMMARY:\r
+>> case OUTPUT_THREADS:\r
+>> ret =3D do_search_threads (&o);\r
+>> break;\r
+>> case OUTPUT_MESSAGES:\r
+>> + case OUTPUT_SENDER:\r
+>> + case OUTPUT_RECIPIENTS:\r
+>> + case OUTPUT_ADDRESSES:\r
+>\r
+> This is the one use of OUTPUT_ADDRESSES that I would replace with\r
+> OUTPUT_SENDER | OUTPUT_RECIPIENTS\r
+\r
+See above.\r
+\r
+-Michal\r