--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 2A76C431FC7\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 01:10:28 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, 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 q3uYmRTXMrNq for <notmuch@notmuchmail.org>;\r
+ Thu, 30 Oct 2014 01:10:20 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 2E694431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 01:10:20 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1Xjko9-0004Oe-9t; Thu, 30 Oct 2014 08:10:18 +0000\r
+Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1Xjko8-000887-AY; Thu, 30 Oct 2014 08:10:12 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Michal Sojka <sojkam1@fel.cvut.cz>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v4 4/6] cli: search: Add --output={sender,recipients}\r
+In-Reply-To: <1414421455-3037-5-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1414421455-3037-1-git-send-email-sojkam1@fel.cvut.cz>\r
+ <1414421455-3037-5-git-send-email-sojkam1@fel.cvut.cz>\r
+User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Thu, 30 Oct 2014 08:10:11 +0000\r
+Message-ID: <87h9ymugf0.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 87.81.223.162\r
+X-QM-Geographic: According to ripencc,\r
+ this message was delivered by a machine in Britain (UK) (GB).\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: dce63ec75da32219de800dd1bb597c76 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -0.1\r
+X-SpamAssassin-SpamBar: /\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -0.1 points.\r
+ Summary of the scoring: \r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.1 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Thu, 30 Oct 2014 08:10:28 -0000\r
+\r
+On Mon, 27 Oct 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
+> The new outputs allow printing senders, recipients or both of matching\r
+> messages. To print both, the user can use --output=sender and\r
+> --output=recipients simultaneously.\r
+>\r
+> Currently, the same address can appear multiple times in the output. The\r
+> next patch will change this. For this reason, the test are introduced in\r
+> the next patch as well.\r
+>\r
+> We use mailbox_t rather than InternetAddressMailbox because we will need\r
+> to extend it in a following patch.\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 | 112 ++++++++++++++++++++++++++++++++++++-\r
+> 4 files changed, 134 insertions(+), 5 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..b6607c9 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. Currently, 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 ce46877..ce3bfb2 100644\r
+> --- a/notmuch-search.c\r
+> +++ b/notmuch-search.c\r
+> @@ -28,8 +28,12 @@ typedef enum {\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_t;\r
+> \r
+> +#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)\r
+> +\r
+> typedef struct {\r
+> sprinter_t *format;\r
+> notmuch_query_t *query;\r
+> @@ -40,6 +44,11 @@ typedef struct {\r
+> int dupe;\r
+> } search_options_t;\r
+> \r
+> +typedef struct {\r
+> + const char *name;\r
+> + const char *addr;\r
+> +} mailbox_t;\r
+> +\r
+> /* Return two stable query strings that identify exactly the matched\r
+> * and unmatched messages currently in thread. If there are no\r
+> * matched or unmatched messages, the returned buffers will be\r
+> @@ -220,6 +229,84 @@ do_search_threads (search_options_t *opt)\r
+> return 0;\r
+> }\r
+> \r
+> +static void\r
+> +print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
+> +{\r
+> + const char *name = mailbox->name;\r
+> + const char *addr = mailbox->addr;\r
+> +\r
+> + if (opt->format->is_text_printer) {\r
+> + char *mailbox_str;\r
+> +\r
+> + if (name && *name)\r
+> + mailbox_str = talloc_asprintf (opt->format, "%s <%s>", name, addr);\r
+> + else\r
+> + mailbox_str = talloc_strdup (opt->format, addr);\r
+> +\r
+> + if (! mailbox_str) {\r
+> + fprintf (stderr, "Error: out of memory\n");\r
+> + return;\r
+> + }\r
+> + opt->format->string (opt->format, mailbox_str);\r
+> + opt->format->separator (opt->format);\r
+> +\r
+> + talloc_free (mailbox_str);\r
+> + } else {\r
+> + opt->format->begin_map (opt->format);\r
+> + opt->format->map_key (opt->format, "name");\r
+> + opt->format->string (opt->format, name);\r
+> + opt->format->map_key (opt->format, "address");\r
+> + opt->format->string (opt->format, addr);\r
+> + opt->format->end (opt->format);\r
+> + opt->format->separator (opt->format);\r
+> + }\r
+> +}\r
+\r
+How about letting format = opt->format in all the above. I think it\r
+would improve readability and look more similar to the other cases.\r
+\r
+> +\r
+> +static void\r
+> +process_address_list (const search_options_t *opt, InternetAddressList *list)\r
+> +{\r
+\r
+It might be worth documenting these functions: just something brief\r
+saying what arguments are expected and what is returned.\r
+\r
+Otherwise LGTM.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\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
+> + process_address_list (opt, group_list);\r
+> + } else {\r
+> + InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
+> + mailbox_t mbx = {\r
+> + .name = internet_address_get_name (address),\r
+> + .addr = internet_address_mailbox_get_addr (mailbox),\r
+> + };\r
+> +\r
+> + print_mailbox (opt, &mbx);\r
+> + }\r
+> + }\r
+> +}\r
+> +\r
+> +static void\r
+> +process_address_header (const search_options_t *opt, const char *value)\r
+> +{\r
+> + InternetAddressList *list;\r
+> +\r
+> + if (value == NULL)\r
+> + return;\r
+> +\r
+> + list = internet_address_list_parse_string (value);\r
+> + if (list == NULL)\r
+> + return;\r
+> +\r
+> + process_address_list (opt, list);\r
+> +}\r
+> +\r
+> static int\r
+> do_search_messages (search_options_t *opt)\r
+> {\r
+> @@ -266,11 +353,29 @@ do_search_messages (search_options_t *opt)\r
+> \r
+> notmuch_filenames_destroy( filenames );\r
+> \r
+> - } else { /* output == OUTPUT_MESSAGES */\r
+> + } else if (opt->output == 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 (opt->output & OUTPUT_SENDER) {\r
+> + const char *addrs;\r
+> +\r
+> + addrs = notmuch_message_get_header (message, "from");\r
+> + process_address_header (opt, addrs);\r
+> + }\r
+> +\r
+> + if (opt->output & OUTPUT_RECIPIENTS) {\r
+> + const char *hdrs[] = { "to", "cc", "bcc" };\r
+> + const char *addrs;\r
+> + size_t j;\r
+> +\r
+> + for (j = 0; j < ARRAY_SIZE (hdrs); j++) {\r
+> + addrs = notmuch_message_get_header (message, hdrs[j]);\r
+> + process_address_header (opt, addrs);\r
+> + }\r
+> + }\r
+> }\r
+> \r
+> notmuch_message_destroy (message);\r
+> @@ -371,6 +476,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\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
+> @@ -462,7 +569,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> opt.output == OUTPUT_THREADS)\r
+> ret = do_search_threads (&opt);\r
+> else if (opt.output == OUTPUT_MESSAGES ||\r
+> - opt.output == OUTPUT_FILES)\r
+> + opt.output == OUTPUT_FILES ||\r
+> + (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))\r
+> ret = do_search_messages (&opt);\r
+> else if (opt.output == OUTPUT_TAGS)\r
+> ret = do_search_tags (notmuch, &opt);\r
+> -- \r
+> 2.1.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r