--- /dev/null
+Return-Path: <jani@nikula.org>\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 30CF7431FD4\r
+ for <notmuch@notmuchmail.org>; Sat, 6 Sep 2014 05:53:47 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 4GOAfJbDYRaz for <notmuch@notmuchmail.org>;\r
+ Sat, 6 Sep 2014 05:53:42 -0700 (PDT)\r
+Received: from mail-we0-f176.google.com (mail-we0-f176.google.com\r
+ [74.125.82.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 45838431FBD\r
+ for <notmuch@notmuchmail.org>; Sat, 6 Sep 2014 05:53:37 -0700 (PDT)\r
+Received: by mail-we0-f176.google.com with SMTP id q58so400898wes.35\r
+ for <notmuch@notmuchmail.org>; Sat, 06 Sep 2014 05:53:36 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references;\r
+ bh=9ndb9lXkF7ZULHumz3/uuafOK/wzUqo8XmzYh6voiGU=;\r
+ b=RmzkDhUg31FRGjvyGL364VgGVsi1VizgMTYGBNFP9AhK2/FSxA6ubKRuIOdHRqf/DI\r
+ EYnX37XEI6shbUsEqN+KUy/bXfpZCtKJLpWipRaKH4wiR/WsuvBnsbGihpgc4rvR7iW3\r
+ L2YU3FJog6pQlbIY0PaHsTy21EeLkuKKHtE73dJcPzuMJXgTKjgeEQw+A5b35ajizY6L\r
+ rShkEkhR3d+tt3wXn/EH/82iXNqrBX2pPLYlcl/CJUZzjLUsuwKmP9YXtngHgkwHJZQN\r
+ 4ietNRxl328/ejoW51FjRNHniQ3GJp/GOWw4NkbMF9EIRJWu4nLMToy7P2U7vO6FlaoW\r
+ b7Aw==\r
+X-Gm-Message-State:\r
+ ALoCoQkroxMaoYQYoSPYYKpqv1G0fvKV1pZTgAYULJ0wiL+86gdS8XQoNt59Dpe7UxFHOqudDT1M\r
+X-Received: by 10.180.12.195 with SMTP id a3mr9872923wic.30.1410008016149;\r
+ Sat, 06 Sep 2014 05:53:36 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c374-75.dhcp.inet.fi.\r
+ [88.195.116.75])\r
+ by mx.google.com with ESMTPSA id wx3sm4484199wjc.19.2014.09.06.05.53.35\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 06 Sep 2014 05:53:35 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] cli: deduplicate addresses for --output=address-*\r
+Date: Sat, 6 Sep 2014 15:53:30 +0300\r
+Message-Id: <1410008010-3770-3-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.0\r
+In-Reply-To: <1410008010-3770-1-git-send-email-jani@nikula.org>\r
+References: <1410008010-3770-1-git-send-email-jani@nikula.org>\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: Sat, 06 Sep 2014 12:53:47 -0000\r
+\r
+---\r
+ notmuch-search.c | 32 ++++++++++++++++++++++++++------\r
+ 1 file changed, 26 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index c84ecc31262c..c3ca3246bceb 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -218,7 +218,8 @@ do_search_threads (sprinter_t *format,\r
+ }\r
+ \r
+ static void\r
+-print_address_list (sprinter_t *format, InternetAddressList *list)\r
++print_address_list (sprinter_t *format, GHashTable *addrs,\r
++ InternetAddressList *list)\r
+ {\r
+ InternetAddress *address;\r
+ int i;\r
+@@ -234,7 +235,7 @@ print_address_list (sprinter_t *format, InternetAddressList *list)\r
+ if (group_list == NULL)\r
+ continue;\r
+ \r
+- print_address_list (format, group_list);\r
++ print_address_list (format, addrs, group_list);\r
+ } else {\r
+ InternetAddressMailbox *mailbox;\r
+ const char *name;\r
+@@ -246,6 +247,11 @@ print_address_list (sprinter_t *format, InternetAddressList *list)\r
+ name = internet_address_get_name (address);\r
+ addr = internet_address_mailbox_get_addr (mailbox);\r
+ \r
++ if (g_hash_table_lookup_extended (addrs, addr, NULL, NULL))\r
++ continue;\r
++\r
++ g_hash_table_insert (addrs, talloc_strdup (NULL, addr), NULL);\r
++\r
+ if (name && *name)\r
+ full_address = talloc_asprintf (NULL, "%s <%s>", name, addr);\r
+ else\r
+@@ -263,7 +269,7 @@ print_address_list (sprinter_t *format, InternetAddressList *list)\r
+ }\r
+ \r
+ static void\r
+-print_address_string (sprinter_t *format, const char *recipients)\r
++print_address_string (sprinter_t *format, GHashTable *addrs, const char *recipients)\r
+ {\r
+ InternetAddressList *list;\r
+ \r
+@@ -274,7 +280,13 @@ print_address_string (sprinter_t *format, const char *recipients)\r
+ if (list == NULL)\r
+ return;\r
+ \r
+- print_address_list (format, list);\r
++ print_address_list (format, addrs, list);\r
++}\r
++\r
++static void\r
++_my_talloc_free_for_g_hash (void *ptr)\r
++{\r
++ talloc_free (ptr);\r
+ }\r
+ \r
+ static int\r
+@@ -288,8 +300,13 @@ do_search_messages (sprinter_t *format,\r
+ notmuch_message_t *message;\r
+ notmuch_messages_t *messages;\r
+ notmuch_filenames_t *filenames;\r
++ GHashTable *addresses = NULL;\r
+ int i;\r
+ \r
++ if (output & OUTPUT_ADDRESS_ALL)\r
++ addresses = g_hash_table_new_full (g_str_hash, g_str_equal,\r
++ _my_talloc_free_for_g_hash, NULL);\r
++\r
+ if (offset < 0) {\r
+ offset += notmuch_query_count_messages (query);\r
+ if (offset < 0)\r
+@@ -341,7 +358,7 @@ do_search_messages (sprinter_t *format,\r
+ if (addrs == NULL || *addrs == '\0')\r
+ addrs = notmuch_message_get_header (message, "from");\r
+ \r
+- print_address_string (format, addrs);\r
++ print_address_string (format, addresses, addrs);\r
+ }\r
+ \r
+ if (output & OUTPUT_ADDRESS_TO) {\r
+@@ -351,7 +368,7 @@ do_search_messages (sprinter_t *format,\r
+ \r
+ for (j = 0; j < ARRAY_SIZE (hdrs); j++) {\r
+ addrs = notmuch_message_get_header (message, hdrs[j]);\r
+- print_address_string (format, addrs);\r
++ print_address_string (format, addresses, addrs);\r
+ }\r
+ }\r
+ }\r
+@@ -359,6 +376,9 @@ do_search_messages (sprinter_t *format,\r
+ notmuch_message_destroy (message);\r
+ }\r
+ \r
++ if (addresses)\r
++ g_hash_table_unref (addresses);\r
++\r
+ notmuch_messages_destroy (messages);\r
+ \r
+ format->end (format);\r
+-- \r
+2.1.0\r
+\r