unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [RFC Patch 3/3] CLI/address: source by frequency if output=count
Date: Sun, 19 Dec 2021 14:18:54 -0400	[thread overview]
Message-ID: <20211219181854.115918-4-david@tethera.net> (raw)
In-Reply-To: <20211219181854.115918-1-david@tethera.net>

This is the other low hanging fruit, because we already require a
second pass of the hashed values to output.
---
 notmuch-search.c     | 10 ++++++----
 test/T095-address.sh | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/notmuch-search.c b/notmuch-search.c
index ff3967fd..9f698a09 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -522,8 +522,11 @@ process_hash_value (unused (void *key), void *list, void *context)
     if (ctx->dedup == DEDUP_ADDRESS) {
 	mailbox_t *mailbox = summarize_mailboxes (list);
 	ctx->output_mailboxes = g_list_prepend (ctx->output_mailboxes, mailbox);
-    } else
-	g_list_foreach (list, print_list_value, context);
+    } else {
+	for (GList *l = list; l; l = l->next) {
+	    ctx->output_mailboxes = g_list_prepend (ctx->output_mailboxes, l->data);
+	}
+    }
 }
 
 static int
@@ -630,8 +633,7 @@ do_search_messages (search_context_t *ctx)
 	(ctx->output & OUTPUT_COUNT || ctx->dedup == DEDUP_ADDRESS)) {
 	g_hash_table_foreach (ctx->addresses, process_hash_value, ctx);
 	ctx->output_mailboxes = g_list_sort (ctx->output_mailboxes, compare_count);
-	if (ctx->dedup == DEDUP_ADDRESS)
-	    g_list_foreach (ctx->output_mailboxes, print_list_value, ctx);
+	g_list_foreach (ctx->output_mailboxes, print_list_value, ctx);
     }
     notmuch_messages_destroy (messages);
 
diff --git a/test/T095-address.sh b/test/T095-address.sh
index 53886591..204168c7 100755
--- a/test/T095-address.sh
+++ b/test/T095-address.sh
@@ -119,6 +119,14 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "--output=sender --output=count (sort by frequency)"
+notmuch address --output=sender --output=count '*' | head -n 2 >OUTPUT
+cat <<EOF >EXPECTED
+12	Carl Worth <cworth@cworth.org>
+7	Keith Packard <keithp@keithp.com>
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_begin_subtest "--output=recipients --output=address"
 notmuch address --output=recipients --output=address '*' >OUTPUT
 cat <<EOF >EXPECTED
@@ -155,6 +163,14 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "--output=sender --output=address --output=count (sort by frequency)"
+notmuch address --output=sender --output=address --output=count '*' | head -n 2 >OUTPUT
+cat <<EOF >EXPECTED
+12	cworth@cworth.org
+7	keithp@keithp.com
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_begin_subtest "--output=count --format=json"
 # Since the iteration order of GHashTable is not specified, we
 # preprocess and sort the results to keep the order stable here.
@@ -181,6 +197,15 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "--output=count --format=json (sort by frequency)"
+notmuch address --output=count --format=json '*' | \
+    sed -e 's/^\[//' -e 's/]$//' -e 's/,$//' | head -n 2 >OUTPUT
+cat <<EOF >EXPECTED
+{"name": "Carl Worth", "address": "cworth@cworth.org", "name-addr": "Carl Worth <cworth@cworth.org>", "count": 12}
+{"name": "Keith Packard", "address": "keithp@keithp.com", "name-addr": "Keith Packard <keithp@keithp.com>", "count": 7}
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_begin_subtest "--deduplicate=no --sort=oldest-first --output=sender"
 notmuch address --deduplicate=no --sort=oldest-first --output=sender '*' >OUTPUT
 cat <<EOF >EXPECTED
@@ -337,6 +362,15 @@ cat <<EOF >EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "--deduplicate=mailbox --output=sender --output=count (sort by frequency)"
+notmuch address --deduplicate=mailbox --output=sender --output=count from:example.com  | head -n 3 | sort -k2 >OUTPUT
+cat <<EOF >EXPECTED
+2	Baz <foo.bar+baz@example.com>
+2	Foo Bar <foo.bar@example.com>
+2	foo.bar@example.com
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_begin_subtest "--deduplicate=address --output=sender --output=count"
 notmuch address --deduplicate=address --output=sender --output=count from:example.com | sort -n >OUTPUT
 cat <<EOF >EXPECTED
-- 
2.34.1

  parent reply	other threads:[~2021-12-19 18:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-19 18:18 Partial support for sorting the output of notmuch address David Bremner
2021-12-19 18:18 ` [RFC Patch 1/3] CLI/address: refactor/inline print_popular David Bremner
2021-12-19 18:18 ` [RFC Patch 2/3] CLI/address: sort output by frequency with deduplicate=address David Bremner
2021-12-19 18:18 ` David Bremner [this message]
2021-12-20 16:48 ` Partial support for sorting the output of notmuch address inwit
2021-12-20 17:44   ` 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=20211219181854.115918-4-david@tethera.net \
    --to=david@tethera.net \
    --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).