From: Jani Nikula Date: Thu, 3 Sep 2015 19:39:59 +0000 (+0300) Subject: [PATCH v2 3/9] cli: add support for not deduplicating notmuch address results X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=65fb5f9f2decc859ed4109a6b3ab3e1455a189ef;p=notmuch-archives.git [PATCH v2 3/9] cli: add support for not deduplicating notmuch address results --- diff --git a/01/00ca82f666fb877e2e91e3a1ab38787bcdf3bc b/01/00ca82f666fb877e2e91e3a1ab38787bcdf3bc new file mode 100644 index 000000000..9f1b2ca25 --- /dev/null +++ b/01/00ca82f666fb877e2e91e3a1ab38787bcdf3bc @@ -0,0 +1,153 @@ +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 971D56DE1607 + for ; Thu, 3 Sep 2015 12:40:33 -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.422 +X-Spam-Level: +X-Spam-Status: No, score=-0.422 tagged_above=-999 required=5 tests=[AWL=0.298, + 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 iRT_XOhNR8o4 for ; + Thu, 3 Sep 2015 12:40:30 -0700 (PDT) +Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com + [209.85.212.179]) + by arlo.cworth.org (Postfix) with ESMTPS id 54C956DE1601 + for ; Thu, 3 Sep 2015 12:40:16 -0700 (PDT) +Received: by wicfx3 with SMTP id fx3so1163164wic.1 + for ; Thu, 03 Sep 2015 12:40:14 -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=hSwKYqPHO7+9nkGxYYNyXcN4RX89T7x7GJPaAR5dNYg=; + b=bGRuOSwHHkd/YMuowWF84q3M0m1elXTWB9C4Xc0PwmrS5VIetKgpZaAgvVDwJhw3c4 + 67EYhIv9Qmx849jOtZ6Pbh5nKojohBZ7umNTa3gkvfKz9kzIRWsVqVhokfcwBrNyWSH2 + JE3DbJaXTxWNOg3r+j/dmvJ3/mCoRGlI5+FlaenRTn9KSpznMDMIUBz+xV6d0s+oWfGP + 1zJ5G4wp8frAi9LcaTmcgZ8kcIMPRv0F0ZVP2IE/99CLUx+ixaxy+OSdRH8CiD/Z/p3n + WGN9g8YDrPN/8ipKdS62W981PDLVD3Od52KBGrYggkAZ/Kjvdhq93QvfjKEBuH7Pokv5 + TmGA== +X-Gm-Message-State: + ALoCoQlaEuF0IG80aLWP/8NIjqrDVeecBRTgcnTq+D1AKBKJpuxnzMH/iSsbI6K3neYZkxDQJQCt +X-Received: by 10.180.99.66 with SMTP id eo2mr2475724wib.88.1441309214443; + Thu, 03 Sep 2015 12:40:14 -0700 (PDT) +Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi. + [188.238.79.131]) + by smtp.gmail.com with ESMTPSA id eu10sm646836wib.5.2015.09.03.12.40.13 + (version=TLSv1/SSLv3 cipher=OTHER); + Thu, 03 Sep 2015 12:40:14 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 3/9] cli: add support for not deduplicating notmuch address + results +Date: Thu, 3 Sep 2015 22:39:59 +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: Thu, 03 Sep 2015 19:40:33 -0000 + +Make it possible to use notmuch address as part of a | sort | uniq -c +pipe instead of forcing --output=count. This is useful for combining +results from multiple notmuch address queries. +--- + notmuch-search.c | 21 ++++++++++++++++++++- + 1 file changed, 20 insertions(+), 1 deletion(-) + +diff --git a/notmuch-search.c b/notmuch-search.c +index 36f58eb8d54c..66404b561679 100644 +--- a/notmuch-search.c ++++ b/notmuch-search.c +@@ -37,12 +37,18 @@ typedef enum { + } output_t; + + typedef enum { ++ DEDUP_NONE, ++ DEDUP_MAILBOX, ++} dedup_t; ++ ++typedef enum { + NOTMUCH_FORMAT_JSON, + NOTMUCH_FORMAT_TEXT, + NOTMUCH_FORMAT_TEXT0, + NOTMUCH_FORMAT_SEXP + } format_sel_t; + ++ + typedef struct { + notmuch_database_t *notmuch; + format_sel_t format_sel; +@@ -55,6 +61,7 @@ typedef struct { + int limit; + int dupe; + GHashTable *addresses; ++ dedup_t dedup; + } search_context_t; + + typedef struct { +@@ -355,7 +362,9 @@ process_address_list (const search_context_t *ctx, + .count = 0, + }; + +- if (is_duplicate (ctx, mbx.name, mbx.addr)) ++ /* OUTPUT_COUNT only works with deduplication */ ++ if (ctx->dedup != DEDUP_NONE && ++ is_duplicate (ctx, mbx.name, mbx.addr)) + continue; + + if (ctx->output & OUTPUT_COUNT) +@@ -656,6 +665,7 @@ static search_context_t search_context = { + .offset = 0, + .limit = -1, /* unlimited */ + .dupe = -1, ++ .dedup = DEDUP_MAILBOX, + }; + + static const notmuch_opt_desc_t common_options[] = { +@@ -755,6 +765,10 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) + (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE }, + { "false", NOTMUCH_EXCLUDE_FALSE }, + { 0, 0 } } }, ++ { NOTMUCH_OPT_KEYWORD, &ctx->dedup, "deduplicate", 'D', ++ (notmuch_keyword_t []){ { "no", DEDUP_NONE }, ++ { "mailbox", DEDUP_MAILBOX }, ++ { 0, 0 } } }, + { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 }, + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, + { 0, 0, 0, 0, 0 } +@@ -769,6 +783,11 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) + if (! (ctx->output & (OUTPUT_SENDER | OUTPUT_RECIPIENTS))) + ctx->output |= OUTPUT_SENDER; + ++ if (ctx->output & OUTPUT_COUNT && ctx->dedup == DEDUP_NONE) { ++ fprintf (stderr, "--output=count is not applicable with --deduplicate=no\n"); ++ return EXIT_FAILURE; ++ } ++ + if (_notmuch_search_prepare (ctx, config, + argc - opt_index, argv + opt_index)) + return EXIT_FAILURE; +-- +2.1.4 +