--- /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 A7A1D431FCB\r
+ for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 14:54:44 -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 5soIv3snTRzV for <notmuch@notmuchmail.org>;\r
+ Fri, 31 Oct 2014 14:54:40 -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 A325E431FD4\r
+ for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 14:54:23 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.7])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id 1C9653D3E93\r
+ for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 22:54:23 +0100 (CET)\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) with ESMTP id bU_blBRr6frH for <notmuch@notmuchmail.org>;\r
+ Fri, 31 Oct 2014 22:54:18 +0100 (CET)\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 2E3755CD10F\r
+ for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 22:54:15 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+ (envelope-from <sojkam1@fel.cvut.cz>)\r
+ id 1XkK92-0007hz-Pm; Fri, 31 Oct 2014 22:54:08 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v6 6/7] cli: search: Add --output=count\r
+Date: Fri, 31 Oct 2014 22:54:00 +0100\r
+Message-Id: <1414792441-29555-7-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1414792441-29555-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1414792441-29555-1-git-send-email-sojkam1@fel.cvut.cz>\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, 31 Oct 2014 21:54:44 -0000\r
+\r
+This output can be used with --output=recipients or --output=sender\r
+and in addition to the addresses, it prints how many times was each\r
+address encountered during search.\r
+---\r
+ completion/notmuch-completion.bash | 2 +-\r
+ completion/notmuch-completion.zsh | 2 +-\r
+ doc/man1/notmuch-search.rst | 9 +++++--\r
+ notmuch-search.c | 51 ++++++++++++++++++++++++++++++++------\r
+ 4 files changed, 52 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
+index cfbd389..39cd829 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 sender recipients" -- "${cur}" ) )\r
++ COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients count" -- "${cur}" ) )\r
+ return\r
+ ;;\r
+ --sort)\r
+diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh\r
+index 3e52a00..d7e5a5e 100644\r
+--- a/completion/notmuch-completion.zsh\r
++++ b/completion/notmuch-completion.zsh\r
+@@ -53,7 +53,7 @@ _notmuch_search()\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
+- '--output=[select what to output]:output:((summary threads messages files tags sender recipients))'\r
++ '--output=[select what to output]:output:((summary threads messages files tags sender recipients count))'\r
+ }\r
+ \r
+ _notmuch()\r
+diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst\r
+index 42f17e4..ec89200 100644\r
+--- a/doc/man1/notmuch-search.rst\r
++++ b/doc/man1/notmuch-search.rst\r
+@@ -96,9 +96,14 @@ Supported options for **search** include\r
+ Like **sender** but for addresses from *To*, *Cc* and\r
+ *Bcc* headers.\r
+ \r
++ **count**\r
++ Can be used in combination with **sender** or\r
++ **recipients** to print the count of how many times was\r
++ the address encountered during search.\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
++ outputs. Currently, this is only supported for **sender**,\r
++ **recipients** and **count** outputs.\r
+ \r
+ ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)\r
+ This option can be used to present results in either\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 43d42c6..4b39dfc 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -30,9 +30,10 @@ typedef enum {\r
+ OUTPUT_TAGS = 1 << 4,\r
+ OUTPUT_SENDER = 1 << 5,\r
+ OUTPUT_RECIPIENTS = 1 << 6,\r
++ OUTPUT_COUNT = 1 << 7,\r
+ } output_t;\r
+ \r
+-#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)\r
++#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS | OUTPUT_COUNT)\r
+ \r
+ typedef struct {\r
+ sprinter_t *format;\r
+@@ -47,6 +48,7 @@ typedef struct {\r
+ typedef struct {\r
+ const char *name;\r
+ const char *addr;\r
++ int count;\r
+ } mailbox_t;\r
+ \r
+ /* Return two stable query strings that identify exactly the matched\r
+@@ -235,17 +237,24 @@ is_duplicate (const search_options_t *opt, GHashTable *addrs, const char *name,\r
+ {\r
+ notmuch_bool_t duplicate;\r
+ char *key;\r
++ mailbox_t *mailbox;\r
+ \r
+ key = talloc_asprintf (opt->format, "%s <%s>", name, addr);\r
+ if (! key)\r
+ return FALSE;\r
+ \r
+- duplicate = g_hash_table_lookup_extended (addrs, key, NULL, NULL);\r
++ duplicate = g_hash_table_lookup_extended (addrs, key, NULL, (gpointer)&mailbox);\r
+ \r
+- if (! duplicate)\r
+- g_hash_table_insert (addrs, key, NULL);\r
+- else\r
++ if (! duplicate) {\r
++ mailbox = talloc (opt->format, mailbox_t);\r
++ mailbox->name = talloc_strdup (mailbox, name);\r
++ mailbox->addr = talloc_strdup (mailbox, addr);\r
++ mailbox->count = 1;\r
++ g_hash_table_insert (addrs, key, mailbox);\r
++ } else {\r
++ mailbox->count++;\r
+ talloc_free (key);\r
++ }\r
+ \r
+ return duplicate;\r
+ }\r
+@@ -255,6 +264,7 @@ 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
++ int count = mailbox->count;\r
+ sprinter_t *format = opt->format;\r
+ InternetAddress *ia = internet_address_mailbox_new (name, addr);\r
+ char *name_addr;\r
+@@ -264,6 +274,10 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
+ name_addr = internet_address_to_string (ia, FALSE);\r
+ \r
+ if (format->is_text_printer) {\r
++ if (count > 0) {\r
++ format->integer (format, count);\r
++ format->string (format, "\t");\r
++ }\r
+ format->string (format, name_addr);\r
+ format->separator (format);\r
+ } else {\r
+@@ -274,6 +288,10 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
+ format->string (format, addr);\r
+ format->map_key (format, "name-addr");\r
+ format->string (format, name_addr);\r
++ if (count > 0) {\r
++ format->map_key (format, "count");\r
++ format->integer (format, count);\r
++ }\r
+ format->end (format);\r
+ format->separator (format);\r
+ }\r
+@@ -282,7 +300,7 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
+ g_free (name_addr);\r
+ }\r
+ \r
+-/* Print addresses from InternetAddressList. */\r
++/* Print or prepare for printing addresses from InternetAddressList. */\r
+ static void\r
+ process_address_list (const search_options_t *opt, GHashTable *addrs,\r
+ InternetAddressList *list)\r
+@@ -307,17 +325,21 @@ process_address_list (const search_options_t *opt, GHashTable *addrs,\r
+ mailbox_t mbx = {\r
+ .name = internet_address_get_name (address),\r
+ .addr = internet_address_mailbox_get_addr (mailbox),\r
++ .count = 0,\r
+ };\r
+ \r
+ if (is_duplicate (opt, addrs, mbx.name, mbx.addr))\r
+ continue;\r
+ \r
++ if (opt->output & OUTPUT_COUNT)\r
++ continue;\r
++\r
+ print_mailbox (opt, &mbx);\r
+ }\r
+ }\r
+ }\r
+ \r
+-/* Print addresses from a message header. */\r
++/* Print or prepare for printing addresses from a message header. */\r
+ static void\r
+ process_address_header (const search_options_t *opt, GHashTable *addrs, const char *value)\r
+ {\r
+@@ -341,6 +363,15 @@ _my_talloc_free_for_g_hash (void *ptr)\r
+ talloc_free (ptr);\r
+ }\r
+ \r
++static void\r
++print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)\r
++{\r
++ const mailbox_t *mailbox = value;\r
++ search_options_t *opt = user_data;\r
++\r
++ print_mailbox (opt, mailbox);\r
++}\r
++\r
+ static int\r
+ do_search_messages (search_options_t *opt)\r
+ {\r
+@@ -353,7 +384,7 @@ do_search_messages (search_options_t *opt)\r
+ \r
+ if (opt->output & OUTPUT_ADDRESS_FLAGS)\r
+ addresses = g_hash_table_new_full (g_str_hash, g_str_equal,\r
+- _my_talloc_free_for_g_hash, NULL);\r
++ _my_talloc_free_for_g_hash, _my_talloc_free_for_g_hash);\r
+ \r
+ if (opt->offset < 0) {\r
+ opt->offset += notmuch_query_count_messages (opt->query);\r
+@@ -420,6 +451,9 @@ do_search_messages (search_options_t *opt)\r
+ notmuch_message_destroy (message);\r
+ }\r
+ \r
++ if (addresses && opt->output & OUTPUT_COUNT)\r
++ g_hash_table_foreach (addresses, print_hash_value, opt);\r
++\r
+ if (addresses)\r
+ g_hash_table_unref (addresses);\r
+ \r
+@@ -522,6 +556,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ { "recipients", OUTPUT_RECIPIENTS },\r
+ { "files", OUTPUT_FILES },\r
+ { "tags", OUTPUT_TAGS },\r
++ { "count", OUTPUT_COUNT },\r
+ { 0, 0 } } },\r
+ { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
+ (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },\r
+-- \r
+2.1.1\r
+\r