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