From f9509e1225bc1d5d69c8e36c34b9dd70d3afe1b1 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 29 Aug 2015 17:56:36 +0300 Subject: [PATCH] [RFC PATCH 5/5] cli: add support for deduplicating based on case insensitive address --- 1f/1f3ca71997dea33a31703a663ce9ad88e996d8 | 137 ++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 1f/1f3ca71997dea33a31703a663ce9ad88e996d8 diff --git a/1f/1f3ca71997dea33a31703a663ce9ad88e996d8 b/1f/1f3ca71997dea33a31703a663ce9ad88e996d8 new file mode 100644 index 000000000..466570a75 --- /dev/null +++ b/1f/1f3ca71997dea33a31703a663ce9ad88e996d8 @@ -0,0 +1,137 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 3BD746DE182F + for ; Sat, 29 Aug 2015 07:57:12 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.371 +X-Spam-Level: +X-Spam-Status: No, score=-0.371 tagged_above=-999 required=5 tests=[AWL=0.349, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id a9dUjBl5yLQV for ; + Sat, 29 Aug 2015 07:57:10 -0700 (PDT) +Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com + [209.85.212.176]) + by arlo.cworth.org (Postfix) with ESMTPS id 35D326DE1422 + for ; Sat, 29 Aug 2015 07:56:50 -0700 (PDT) +Received: by wicfv10 with SMTP id fv10so28398027wic.1 + for ; Sat, 29 Aug 2015 07:56:48 -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:in-reply-to:references; + bh=tOhkooD7NhsNpnCbCtRQLQLFm3P9oiALB4kanGyOPjE=; + b=ZnwfENGpRrt3GTLW7i7gmf8nDaHDvjV9RPcaIGjqkOygX0rlh+ZmxzCA3COC6JVuli + VqXCJgBbG1ybBFXbssOufWBB06bzc1Uaqd3TvQnPJQU7rfEgmrWo1Po7CB51VwUv8EYs + S7KV6LgFaeNDFecSBwAgKpYOcMvsDOX83din5FRZfYDJNR5CuKdvG0depSc2MKKASINE + S+8hSHTgoXkO7kpDRV2b2i+HO3j8q3P0lEIm5xnoy7+wOEAlxc9DzKmNfrtDift0swLP + FWNf/zu8q5XSwhGhnhzupUvEUPJfFQCr6gWKHXSwyZCSnRb73okTEEpJz41AWtfDxCou + pOdQ== +X-Gm-Message-State: + ALoCoQkhzykwUuZOiRHj4/L1cZHUcdvJfyympfRTsbSa80VpbUdvhtidHwUmbLNYHMrzTqg0rI6z +X-Received: by 10.180.107.39 with SMTP id gz7mr10158673wib.82.1440860208383; + Sat, 29 Aug 2015 07:56:48 -0700 (PDT) +Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi. + [188.238.79.131]) + by smtp.gmail.com with ESMTPSA id k2sm8933331wif.4.2015.08.29.07.56.47 + (version=TLSv1/SSLv3 cipher=OTHER); + Sat, 29 Aug 2015 07:56:47 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [RFC PATCH 5/5] cli: add support for deduplicating based on case + insensitive address +Date: Sat, 29 Aug 2015 17:56:36 +0300 +Message-Id: + +X-Mailer: git-send-email 2.1.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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, 29 Aug 2015 14:57:12 -0000 + +Consider all variants of an email address as one, and print the most +common variant. +--- + notmuch-search.c | 33 ++++++++++++++++++++++++++++++++- + 1 file changed, 32 insertions(+), 1 deletion(-) + +diff --git a/notmuch-search.c b/notmuch-search.c +index 60311393198d..537298788ab9 100644 +--- a/notmuch-search.c ++++ b/notmuch-search.c +@@ -447,6 +447,31 @@ _list_free_for_g_hash (void *ptr) + g_list_free_full (ptr, _talloc_free_for_g_hash); + } + ++/* Print the most common variant of a list of unique mailboxes, and ++ * conflate the counts. */ ++static void ++print_popular (const search_context_t *ctx, GList *list) ++{ ++ GList *l; ++ mailbox_t *mailbox = NULL, *m; ++ int max = 0; ++ int total = 0; ++ ++ for (l = list; l; l = l->next) { ++ m = l->data; ++ total += m->count; ++ if (m->count > max) { ++ mailbox = m; ++ max = m->count; ++ } ++ } ++ ++ /* The original count is no longer needed, so overwrite. */ ++ mailbox->count = total; ++ ++ print_mailbox (ctx, mailbox); ++} ++ + static void + print_list_value (void *mailbox, void *context) + { +@@ -456,7 +481,12 @@ print_list_value (void *mailbox, void *context) + static void + print_hash_value (unused (void *key), void *list, void *context) + { +- g_list_foreach (list, print_list_value, context); ++ const search_context_t *ctx = context; ++ ++ if (ctx->dupe == 1) ++ print_popular (ctx, list); ++ else ++ g_list_foreach (list, print_list_value, context); + } + + static int +@@ -817,6 +847,7 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) + { NOTMUCH_OPT_KEYWORD, &ctx->dupe, "deduplicate", 'x', + (notmuch_keyword_t []){ { "yes", -1 }, + { "no", 0 }, ++ { "address", 1 }, + { 0, 0 } } }, + { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 }, + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, +-- +2.1.4 + -- 2.26.2