--- /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 0FD8A429E41\r
+ for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 01:12:03 -0800 (PST)\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 4QqeirgmkbYb for <notmuch@notmuchmail.org>;\r
+ Tue, 4 Nov 2014 01:11:59 -0800 (PST)\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 A3862429E37\r
+ for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 01:11:58 -0800 (PST)\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 1Xla9J-00078p-2q; Tue, 04 Nov 2014 09:11:57 +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 1Xla9I-0005Em-6X; Tue, 04 Nov 2014 09:11:36 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Michal Sojka <sojkam1@fel.cvut.cz>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 09/10] cli: address: Add --output=count\r
+In-Reply-To: <1415058622-21162-10-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1415058622-21162-1-git-send-email-sojkam1@fel.cvut.cz>\r
+ <1415058622-21162-10-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: Tue, 04 Nov 2014 09:11:35 +0000\r
+Message-ID: <87tx2f2uuw.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\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: 32b1b13e68061787bee67abbe2103240 (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: Tue, 04 Nov 2014 09:12:03 -0000\r
+\r
+\r
+On Mon, 03 Nov 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
+> This output prints how many times was each address encountered during\r
+> search.\r
+> ---\r
+> completion/notmuch-completion.bash | 2 +-\r
+> completion/notmuch-completion.zsh | 2 +-\r
+> doc/man1/notmuch-address.rst | 7 ++++++\r
+> notmuch-search.c | 49 ++++++++++++++++++++++++++++++++=\r
+------\r
+> test/T095-address.sh | 48 ++++++++++++++++++++++++++++++++=\r
++++++\r
+> 5 files changed, 99 insertions(+), 9 deletions(-)\r
+>\r
+> diff --git a/completion/notmuch-completion.bash b/completion/notmuch-comp=\r
+letion.bash\r
+> index 94ea2d5..db152f3 100644\r
+> --- a/completion/notmuch-completion.bash\r
+> +++ b/completion/notmuch-completion.bash\r
+> @@ -332,7 +332,7 @@ _notmuch_address()\r
+> return\r
+> ;;\r
+> --output)\r
+> - COMPREPLY=3D( $( compgen -W "sender recipients" -- "${cur}" ) )\r
+> + COMPREPLY=3D( $( compgen -W "sender recipients count" -- "${cur}" )=\r
+ )\r
+> return\r
+> ;;\r
+> --sort)\r
+> diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-compl=\r
+etion.zsh\r
+> index c606b75..8968562 100644\r
+> --- a/completion/notmuch-completion.zsh\r
+> +++ b/completion/notmuch-completion.zsh\r
+> @@ -61,7 +61,7 @@ _notmuch_address()\r
+> {\r
+> _arguments -s : \\r
+> '--sort=3D[sort results]:sorting:((newest-first\:"reverse chronologi=\r
+cal order" oldest-first\:"chronological order"))' \\r
+> - '--output=3D[select what to output]:output:((sender recipients))'\r
+> + '--output=3D[select what to output]:output:((sender recipients count=\r
+))'\r
+> }\r
+>=20=20\r
+> _notmuch()\r
+> diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst\r
+> index 96512b7..18473a7 100644\r
+> --- a/doc/man1/notmuch-address.rst\r
+> +++ b/doc/man1/notmuch-address.rst\r
+> @@ -48,6 +48,13 @@ Supported options for **address** include\r
+> Output all addresses from the *To*, *Cc* and *Bcc*\r
+> headers.\r
+>=20=20\r
+> + **count**\r
+> + Print the count of how many times was the address\r
+> + encountered during search.\r
+> +\r
+> + Note: With this option, addresses are printed only after\r
+> + the whole search is finished. This may take long time.\r
+> +\r
+\r
+Hi\r
+\r
+I think count should be added to the --output=3D(sender|recipients) line a\r
+little above this.\r
+\r
+Also it should say that count ignores the sort order (or possibly that\r
+should go with sort?)\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\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 741702a..d99e530 100644\r
+> --- a/notmuch-search.c\r
+> +++ b/notmuch-search.c\r
+> @@ -33,6 +33,7 @@ typedef enum {\r
+> /* Address command */\r
+> OUTPUT_SENDER =3D 1 << 5,\r
+> OUTPUT_RECIPIENTS =3D 1 << 6,\r
+> + OUTPUT_COUNT =3D 1 << 7,\r
+> } output_t;\r
+>=20=20\r
+> typedef enum {\r
+> @@ -59,6 +60,7 @@ typedef struct {\r
+> typedef struct {\r
+> const char *name;\r
+> const char *addr;\r
+> + int count;\r
+> } mailbox_t;\r
+>=20=20\r
+> /* Return two stable query strings that identify exactly the matched\r
+> @@ -247,17 +249,24 @@ is_duplicate (const search_context_t *ctx, const ch=\r
+ar *name, const char *addr)\r
+> {\r
+> notmuch_bool_t duplicate;\r
+> char *key;\r
+> + mailbox_t *mailbox;\r
+>=20=20\r
+> key =3D talloc_asprintf (ctx->format, "%s <%s>", name, addr);\r
+> if (! key)\r
+> return FALSE;\r
+>=20=20\r
+> - duplicate =3D g_hash_table_lookup_extended (ctx->addresses, key, NUL=\r
+L, NULL);\r
+> + duplicate =3D g_hash_table_lookup_extended (ctx->addresses, key, NUL=\r
+L, (gpointer)&mailbox);\r
+>=20=20\r
+> - if (! duplicate)\r
+> - g_hash_table_insert (ctx->addresses, key, NULL);\r
+> - else\r
+> + if (! duplicate) {\r
+> + mailbox =3D talloc (ctx->format, mailbox_t);\r
+> + mailbox->name =3D talloc_strdup (mailbox, name);\r
+> + mailbox->addr =3D talloc_strdup (mailbox, addr);\r
+> + mailbox->count =3D 1;\r
+> + g_hash_table_insert (ctx->addresses, key, mailbox);\r
+> + } else {\r
+> + mailbox->count++;\r
+> talloc_free (key);\r
+> + }\r
+>=20=20\r
+> return duplicate;\r
+> }\r
+> @@ -267,6 +276,7 @@ print_mailbox (const search_context_t *ctx, const mai=\r
+lbox_t *mailbox)\r
+> {\r
+> const char *name =3D mailbox->name;\r
+> const char *addr =3D mailbox->addr;\r
+> + int count =3D mailbox->count;\r
+> sprinter_t *format =3D ctx->format;\r
+> InternetAddress *ia =3D internet_address_mailbox_new (name, addr);\r
+> char *name_addr;\r
+> @@ -276,6 +286,10 @@ print_mailbox (const search_context_t *ctx, const ma=\r
+ilbox_t *mailbox)\r
+> name_addr =3D internet_address_to_string (ia, FALSE);\r
+>=20=20\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
+> @@ -286,6 +300,10 @@ print_mailbox (const search_context_t *ctx, const ma=\r
+ilbox_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
+> @@ -294,7 +312,7 @@ print_mailbox (const search_context_t *ctx, const mai=\r
+lbox_t *mailbox)\r
+> g_free (name_addr);\r
+> }\r
+>=20=20\r
+> -/* Print addresses from InternetAddressList. */\r
+> +/* Print or prepare for printing addresses from InternetAddressList. */\r
+> static void\r
+> process_address_list (const search_context_t *ctx,\r
+> InternetAddressList *list)\r
+> @@ -319,17 +337,21 @@ process_address_list (const search_context_t *ctx,\r
+> mailbox_t mbx =3D {\r
+> .name =3D internet_address_get_name (address),\r
+> .addr =3D internet_address_mailbox_get_addr (mailbox),\r
+> + .count =3D 0,\r
+> };\r
+>=20=20\r
+> if (is_duplicate (ctx, mbx.name, mbx.addr))\r
+> continue;\r
+>=20=20\r
+> + if (ctx->output & OUTPUT_COUNT)\r
+> + continue;\r
+> +\r
+> print_mailbox (ctx, &mbx);\r
+> }\r
+> }\r
+> }\r
+>=20=20\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_context_t *ctx, const char *value)\r
+> {\r
+> @@ -353,6 +375,15 @@ _my_talloc_free_for_g_hash (void *ptr)\r
+> talloc_free (ptr);\r
+> }\r
+>=20=20\r
+> +static void\r
+> +print_hash_value (unused (gpointer key), gpointer value, gpointer user_d=\r
+ata)\r
+> +{\r
+> + const mailbox_t *mailbox =3D value;\r
+> + search_context_t *ctx =3D user_data;\r
+> +\r
+> + print_mailbox (ctx, mailbox);\r
+> +}\r
+> +\r
+> static int\r
+> _count_filenames (notmuch_message_t *message)\r
+> {\r
+> @@ -448,6 +479,9 @@ do_search_messages (search_context_t *ctx)\r
+> notmuch_message_destroy (message);\r
+> }\r
+>=20=20\r
+> + if (ctx->addresses && ctx->output & OUTPUT_COUNT)\r
+> + g_hash_table_foreach (ctx->addresses, print_hash_value, ctx);\r
+> +\r
+> notmuch_messages_destroy (messages);\r
+>=20=20\r
+> format->end (format);\r
+> @@ -685,6 +719,7 @@ notmuch_address_command (notmuch_config_t *config, in=\r
+t argc, char *argv[])\r
+> { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',\r
+> (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER },\r
+> { "recipients", OUTPUT_RECIPIENTS },\r
+> + { "count", OUTPUT_COUNT },\r
+> { 0, 0 } } },\r
+> { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },\r
+> { 0, 0, 0, 0, 0 }\r
+> @@ -702,7 +737,7 @@ notmuch_address_command (notmuch_config_t *config, in=\r
+t argc, char *argv[])\r
+> return EXIT_FAILURE;\r
+>=20=20\r
+> ctx->addresses =3D 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
+>=20=20\r
+> ret =3D do_search_messages (ctx);\r
+>=20=20\r
+> diff --git a/test/T095-address.sh b/test/T095-address.sh\r
+> index 8a256d2..92e17b0 100755\r
+> --- a/test/T095-address.sh\r
+> +++ b/test/T095-address.sh\r
+> @@ -96,5 +96,53 @@ notmuch address --output=3Dsender --output=3Drecipient=\r
+s '*' >OUTPUT\r
+> # Use EXPECTED from previous subtest\r
+> test_expect_equal_file OUTPUT EXPECTED\r
+>=20=20\r
+> +test_begin_subtest "--output=3Dsender --output=3Dcount"\r
+> +notmuch address --output=3Dsender --output=3Dcount '*' | sort -n >OUTPUT\r
+> +cat <<EOF >EXPECTED\r
+> +1 Adrian Perez de Castro <aperez@igalia.com>\r
+> +1 Aron Griffis <agriffis@n01se.net>\r
+> +1 Chris Wilson <chris@chris-wilson.co.uk>\r
+> +1 Fran=C3=A7ois Boulogne <boulogne.f@gmail.com>\r
+> +1 Ingmar Vanhassel <ingmar@exherbo.org>\r
+> +1 Israel Herraiz <isra@herraiz.org>\r
+> +1 Olivier Berger <olivier.berger@it-sudparis.eu>\r
+> +1 Rolland Santimano <rollandsantimano@yahoo.com>\r
+> +2 Alex Botero-Lowry <alex.boterolowry@gmail.com>\r
+> +2 Jjgod Jiang <gzjjgod@gmail.com>\r
+> +3 Stewart Smith <stewart@flamingspork.com>\r
+> +4 Alexander Botero-Lowry <alex.boterolowry@gmail.com>\r
+> +4 Jan Janak <jan@ryngle.com>\r
+> +5 Lars Kellogg-Stedman <lars@seas.harvard.edu>\r
+> +5 Mikhail Gusarov <dottedmag@dottedmag.net>\r
+> +7 Keith Packard <keithp@keithp.com>\r
+> +12 Carl Worth <cworth@cworth.org>\r
+> +EOF\r
+> +test_expect_equal_file OUTPUT EXPECTED\r
+> +\r
+> +test_begin_subtest "--output=3Dsender --output=3Dcount --format=3Djson"\r
+> +# Since the iteration order of GHashTable is not specified, we\r
+> +# preprocess and sort the results to keep the order stable here.\r
+> +notmuch address --output=3Dsender --output=3Dcount --format=3Djson '*' |=\r
+ \\r
+> + sed -e 's/^\[//' -e 's/]$//' -e 's/,$//' | sort >OUTPUT\r
+> +cat <<EOF >EXPECTED\r
+> +{"name": "Adrian Perez de Castro", "address": "aperez@igalia.com", "name=\r
+-addr": "Adrian Perez de Castro <aperez@igalia.com>", "count": 1}\r
+> +{"name": "Alex Botero-Lowry", "address": "alex.boterolowry@gmail.com", "=\r
+name-addr": "Alex Botero-Lowry <alex.boterolowry@gmail.com>", "count": 2}\r
+> +{"name": "Alexander Botero-Lowry", "address": "alex.boterolowry@gmail.co=\r
+m", "name-addr": "Alexander Botero-Lowry <alex.boterolowry@gmail.com>", "co=\r
+unt": 4}\r
+> +{"name": "Aron Griffis", "address": "agriffis@n01se.net", "name-addr": "=\r
+Aron Griffis <agriffis@n01se.net>", "count": 1}\r
+> +{"name": "Carl Worth", "address": "cworth@cworth.org", "name-addr": "Car=\r
+l Worth <cworth@cworth.org>", "count": 12}\r
+> +{"name": "Chris Wilson", "address": "chris@chris-wilson.co.uk", "name-ad=\r
+dr": "Chris Wilson <chris@chris-wilson.co.uk>", "count": 1}\r
+> +{"name": "Fran=C3=A7ois Boulogne", "address": "boulogne.f@gmail.com", "n=\r
+ame-addr": "Fran=C3=A7ois Boulogne <boulogne.f@gmail.com>", "count": 1}\r
+> +{"name": "Ingmar Vanhassel", "address": "ingmar@exherbo.org", "name-addr=\r
+": "Ingmar Vanhassel <ingmar@exherbo.org>", "count": 1}\r
+> +{"name": "Israel Herraiz", "address": "isra@herraiz.org", "name-addr": "=\r
+Israel Herraiz <isra@herraiz.org>", "count": 1}\r
+> +{"name": "Jan Janak", "address": "jan@ryngle.com", "name-addr": "Jan Jan=\r
+ak <jan@ryngle.com>", "count": 4}\r
+> +{"name": "Jjgod Jiang", "address": "gzjjgod@gmail.com", "name-addr": "Jj=\r
+god Jiang <gzjjgod@gmail.com>", "count": 2}\r
+> +{"name": "Keith Packard", "address": "keithp@keithp.com", "name-addr": "=\r
+Keith Packard <keithp@keithp.com>", "count": 7}\r
+> +{"name": "Lars Kellogg-Stedman", "address": "lars@seas.harvard.edu", "na=\r
+me-addr": "Lars Kellogg-Stedman <lars@seas.harvard.edu>", "count": 5}\r
+> +{"name": "Mikhail Gusarov", "address": "dottedmag@dottedmag.net", "name-=\r
+addr": "Mikhail Gusarov <dottedmag@dottedmag.net>", "count": 5}\r
+> +{"name": "Olivier Berger", "address": "olivier.berger@it-sudparis.eu", "=\r
+name-addr": "Olivier Berger <olivier.berger@it-sudparis.eu>", "count": 1}\r
+> +{"name": "Rolland Santimano", "address": "rollandsantimano@yahoo.com", "=\r
+name-addr": "Rolland Santimano <rollandsantimano@yahoo.com>", "count": 1}\r
+> +{"name": "Stewart Smith", "address": "stewart@flamingspork.com", "name-a=\r
+ddr": "Stewart Smith <stewart@flamingspork.com>", "count": 3}\r
+> +EOF\r
+> +test_expect_equal_file OUTPUT EXPECTED\r
+>=20=20\r
+> test_done\r
+> --=20\r
+> 2.1.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r