unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
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	[thread overview]
Message-ID: <b33abd9a0117628932b3f197f536cf1a58793779.1440859765.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1440859765.git.jani@nikula.org>
In-Reply-To: <cover.1440859765.git.jani@nikula.org>

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 *) &notmuch_shared_options, NULL, 0, 0 },
-- 
2.1.4

  parent reply	other threads:[~2015-08-29 14:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-29 14:56 [PATCH 0/5] cli: alternative address deduplication Jani Nikula
2015-08-29 14:56 ` [RFC PATCH 1/5] cli: g_hash_table_lookup_extended is overkill Jani Nikula
2015-08-29 14:56 ` [RFC PATCH 2/5] cli: abstract new mailbox creation Jani Nikula
2015-08-29 14:56 ` [RFC PATCH 3/5] cli: add support for not deduplicating notmuch address results Jani Nikula
2015-08-30  1:29   ` David Bremner
2015-08-30  7:33     ` Jani Nikula
2015-08-29 14:56 ` [RFC PATCH 4/5] cli: change the data structure for notmuch address deduplication Jani Nikula
2015-08-30  1:48   ` David Bremner
2015-08-30  7:45     ` Jani Nikula
2015-08-30 11:46       ` David Bremner
2015-08-30  7:47     ` Jani Nikula
2015-08-29 14:56 ` Jani Nikula [this message]
2015-08-30 12:06   ` [RFC PATCH 5/5] cli: add support for deduplicating based on case insensitive address David Bremner
2015-08-31 10:52     ` Tomi Ollila
2015-08-31 11:15       ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b33abd9a0117628932b3f197f536cf1a58793779.1440859765.git.jani@nikula.org \
    --to=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).