--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\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 49148431FAF\r
+ for <notmuch@notmuchmail.org>; Mon, 13 Oct 2014 12:01:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 1xQpcXesZ2EW for <notmuch@notmuchmail.org>;\r
+ Mon, 13 Oct 2014 12:01:20 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id DB1EC431FAE\r
+ for <notmuch@notmuchmail.org>; Mon, 13 Oct 2014 12:01:19 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 148DB100090;\r
+ Mon, 13 Oct 2014 22:00:59 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Michal Sojka <sojkam1@fel.cvut.cz>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 3/4] cli: Extend the search command for\r
+ --output={sender, recipients}\r
+In-Reply-To: <1413150093-8383-4-git-send-email-sojkam1@fel.cvut.cz>\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
+User-Agent: Notmuch/0.18.1+130~ga61922f (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Mon, 13 Oct 2014 22:00:58 +0300\r
+Message-ID: <m238arrdzp.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Mon, 13 Oct 2014 19:01:24 -0000\r
+\r
+On Mon, Oct 13 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
+\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=sender and\r
+> --output=recipients 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
+> 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-completion.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=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )\r
+> + COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) )\r
+> return\r
+> ;;\r
+> --sort)\r
+> diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.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=[display only the first x threads from the search results]:number of threads to show: ' \\r
+> '--first=[omit the first x threads from the search results]:number of threads to omit: ' \\r
+> - '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))'\r
+> + '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \\r
+> + '--output=[select what to output]:output:((summary threads messages 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=(summary|threads|messages|files|tags)``\r
+> + ``--output=(summary|threads|messages|files|tags|sender|recipients)``\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=text0), as a JSON array\r
+> (--format=json), or as an S-Expression list (--format=sexp).\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=text), separated by null characters\r
+> + (--format=text0), as a JSON array (--format=json), or as\r
+> + an S-Expression list (--format=sexp).\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=``\ (**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 = 1 << 0,\r
+> + OUTPUT_THREADS = 1 << 1,\r
+> + OUTPUT_MESSAGES = 1 << 2,\r
+> + OUTPUT_FILES = 1 << 3,\r
+> + OUTPUT_TAGS = 1 << 4,\r
+> + OUTPUT_SENDER = 1 << 5,\r
+> + OUTPUT_RECIPIENTS = 1 << 6,\r
+> + OUTPUT_ADDRESSES = OUTPUT_SENDER | OUTPUT_RECIPIENTS,\r
+\r
+leftover, like mentioned below (this comment added just before sending)\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 *list)\r
+> +{\r
+> + InternetAddress *address;\r
+> + int i;\r
+> +\r
+> + for (i = 0; i < internet_address_list_length (list); i++) {\r
+> + address = internet_address_list_get_address (list, i);\r
+> + if (INTERNET_ADDRESS_IS_GROUP (address)) {\r
+> + InternetAddressGroup *group;\r
+> + InternetAddressList *group_list;\r
+> +\r
+> + group = INTERNET_ADDRESS_GROUP (address);\r
+> + group_list = internet_address_group_get_members (group);\r
+> + if (group_list == 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 = INTERNET_ADDRESS_MAILBOX (address);\r
+> +\r
+> + name = internet_address_get_name (address);\r
+> + addr = internet_address_mailbox_get_addr (mailbox);\r
+> +\r
+> + if (name && *name)\r
+> + full_address = talloc_asprintf (o->format, "%s <%s>", name, addr);\r
+> + else\r
+> + full_address = talloc_strdup (o->format, addr);\r
+> +\r
+> + if (!full_address) {\r
+\r
+Apart from minor style issue like space after ! and the leftover ADDRESSES\r
+parts (w/o that I would not have commented about !<SPC>) the first 3\r
+patches look pretty good to me. I have not tested those yet.\r
+\r
+But we keep to have some disagreement w/ unique/duplicate/filter-by\r
+handling ;/\r
+\r
+I (currently) rest the case of first/last/most common handling to just\r
+how the --sort=(newest-first|oldest-first) affects the order...\r
+\r
+Let's consider the following list of output if no /deduplication/ is done:\r
+\r
+ John Doe <john@example.com>\r
+ Dr. John Doe <john@example.com>\r
+ John Doe <JOHN@EXAMPLE.COM>\r
+ John Doe <john@doe.name>\r
+ Dr. John Doe <john@doe.name>\r
+ John Doe <JOHN@doe.name.example.com>\r
+ John Doe <john@doe.name>\r
+ Dr. John Doe <john@example.com>\r
+ Dr. John Doe <john@example.com>\r
+ Dr. John Doe <john@doe.name>\r
+ John Doe <john@example.com>\r
+ John Doe <john@doe.name.example.com>\r
+\r
+To stir the pool a little more, this could be the output when\r
+--duplicate=all (the default) is given.\r
+\r
+With --duplicate=none the output could be (first match by unique\r
+case-insensitive address):\r
+\r
+ John Doe <john@example.com>\r
+ John Doe <john@doe.name>\r
+ John Doe <john@doe.name.example.com>\r
+\r
+(many people may have the same name, but email address is unique per person\r
+-- therefore I think 'none' limiting that just to John Doe <john@example.com>\r
+would be too little)\r
+\r
+and with --duplicate=address\r
+\r
+ John Doe <john@example.com>\r
+ Dr. John Doe <john@example.com>\r
+ John Doe <john@doe.name>\r
+ Dr. John Doe <john@doe.name>\r
+ John Doe <JOHN@doe.name.example.com>\r
+\r
+(from this output user can choose how the recipient is to be called\r
+(like "pseudonyms" mentioned in id:20141010113202.GE28601@TP_L520.localdomain )\r
+when sending email)\r
+\r
+and --duplicate=address-casesensitive\r
+\r
+ John Doe <john@example.com>\r
+ Dr. John Doe <john@example.com>\r
+ John Doe <JOHN@EXAMPLE.COM>\r
+ John Doe <john@doe.name>\r
+ Dr. John Doe <john@doe.name>\r
+ John Doe <JOHN@doe.name.example.com>\r
+ John Doe <john@doe.name.example.com>\r
+\r
+This reuse of --duplicate was thought out after Jani's irc mention of it.\r
+This scheme would leave no room tho the filter-by=name suggestion -- for\r
+completeness that would make this look:\r
+\r
+ John Doe <john@example.com>\r
+ Dr. John Doe <john@example.com>\r
+\r
+This doesn't look too bad in this particular case but not having ability to\r
+see all potential addresses (perhaps the only working address is now\r
+hidden) isn't not much for general use. Well, maybe for some specific use\r
+--duplicate=no-unique-addresses could be useful :O\r
+\r
+Ok, this took an hour to get written to (w/ some interruptions). Healthy\r
+criticism appreciated :D\r
+\r
+Tomi\r
+\r
+// stuff deleted before some 'ADDRESSES' leftover...\r
+\r
+> @@ -455,18 +542,23 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> }\r
+> \r
+> switch (o.output) {\r
+> - default:\r
+> case OUTPUT_SUMMARY:\r
+> case OUTPUT_THREADS:\r
+> ret = do_search_threads (&o);\r
+> break;\r
+> case OUTPUT_MESSAGES:\r
+> + case OUTPUT_SENDER:\r
+> + case OUTPUT_RECIPIENTS:\r
+> + case OUTPUT_ADDRESSES:\r
+> case OUTPUT_FILES:\r
+> ret = do_search_messages (&o);\r
+> break;\r
+> case OUTPUT_TAGS:\r
+> ret = do_search_tags (notmuch, o.format, o.query);\r
+> break;\r
+> + default:\r
+> + fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
+> + ret = 1;\r
+> }\r
+> \r
+> notmuch_query_destroy (o.query);\r