From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GJjTF713v2GSbgAAgWs5BA (envelope-from ) for ; Sun, 19 Dec 2021 19:19:41 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id yJ52E713v2FneQAA1q6Kng (envelope-from ) for ; Sun, 19 Dec 2021 18:19:41 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 20E0612461 for ; Sun, 19 Dec 2021 19:19:41 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2D79F29355; Sun, 19 Dec 2021 13:19:17 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 48A2A27E1E for ; Sun, 19 Dec 2021 13:19:08 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 005A75FC42; Sun, 19 Dec 2021 13:19:07 -0500 (EST) Received: (nullmailer pid 115987 invoked by uid 1000); Sun, 19 Dec 2021 18:19:03 -0000 From: David Bremner 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 Message-Id: <20211219181854.115918-4-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211219181854.115918-1-david@tethera.net> References: <20211219181854.115918-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 6WICOLPM3F4PZZ3SVM4LZRSCD5D47KJA X-Message-ID-Hash: 6WICOLPM3F4PZZ3SVM4LZRSCD5D47KJA X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: FR ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1639937981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=5otWgkvHtWDM7DynIxxEBKkWSn3G8+3bOowcKsPsCKM=; b=Ifo3t9YK3/ttczpWxv5JXXBOu7Ra+ZSpz90F+nVaWcQUfEtErXgbNA0wtbTOMjE7lFCKqL IjN097Wuic3H8QYCuz4rwsLMOHf/jH6SWZeoLy/8ibCVneCa+YeoQgn6vHgYa3ECYzCitn WDA4F5t5tGU0YSkpN4ty4pF7Vaia7EQXoRZ+qIIO5rGsCDTxdyZfTbQ477zELT5mXyMOxC 7USs+PAK43xNkR/UdTjR46P4BN0OkbGK4QfFHfKs2iGqW7f3Fnb2q7agVBN0V2qvR4ubr3 +DhBw/eJGgSC3nrJVb3VcP5CD7d8r3bt3Jg+u70KYaxsep0yhT9gBCPqvWEWSQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1639937981; a=rsa-sha256; cv=none; b=cMN3DlTDOZLvEcT4pHaIyVSIDU53mocJsFxvRKkGhBhcYUbT6A+P5Awwoz/Tv6awLyHa2L qP95xZOl0bbTG72WAhAJqWUR/HLmHQRl12mI90e9No1lZc87rxCYeygR9QdZE16Kkl7Yuf Z9nve3A7gPEiVnDETD4FqrZjwDalkScL9u/nGvirPzzMoR4SqL4wdBDpCvmZPgNH5ssHqQ ap9CGrTrE3ORS113nc7BzYgysLe24mQdXANsinWtfquuB8rvd7+FnX9tkQKinrF3sf01NV 1XZ/R30MnjmFuwNYa5Iy8P3H6G2/v3RLfrL0jNiDpjOh75JRFjhadOWXPB9L7A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 2.00 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 20E0612461 X-Spam-Score: 2.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: jYdgHSE+NWOa 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 <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 <EXPECTED +12 Carl Worth +7 Keith Packard +EOF +test_expect_equal_file EXPECTED OUTPUT + test_begin_subtest "--output=recipients --output=address" notmuch address --output=recipients --output=address '*' >OUTPUT cat <EXPECTED @@ -155,6 +163,14 @@ cat <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 <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 <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 <EXPECTED +{"name": "Carl Worth", "address": "cworth@cworth.org", "name-addr": "Carl Worth ", "count": 12} +{"name": "Keith Packard", "address": "keithp@keithp.com", "name-addr": "Keith Packard ", "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 <EXPECTED @@ -337,6 +362,15 @@ cat <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 <EXPECTED +2 Baz +2 Foo Bar +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 <EXPECTED -- 2.34.1