1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id D5E35431FDD
\r
6 for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 02:31:18 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id C62JcoodMM8V for <notmuch@notmuchmail.org>;
\r
17 Sat, 1 Nov 2014 02:31:14 -0700 (PDT)
\r
18 Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com
\r
19 [209.85.212.170]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 3AD8C431FD0
\r
22 for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 02:31:14 -0700 (PDT)
\r
23 Received: by mail-wi0-f170.google.com with SMTP id q5so2848513wiv.1
\r
24 for <notmuch@notmuchmail.org>; Sat, 01 Nov 2014 02:31:12 -0700 (PDT)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=1e100.net; s=20130820;
\r
27 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 :references:in-reply-to:references;
\r
29 bh=6OZMTSURYSdctYk2aJsQra6yGYrzzwbsP4NqbP8eI/k=;
\r
30 b=kNiNb96k1keA2D1MCXj++7hmIcCfDUbo4Z7CW+wn0AHgQ7OnhMeCRRpSwyt8G6vb54
\r
31 pCnNY9Ri/SpYJqRU8gEaVwJMn1m4uurpGqpMOWdIxfPvDH3rXyjRMvqk6MNmCvi6T1pS
\r
32 uUNrRwlPOsK64IvmzeEpNubj4gqEOwr2ltSz2+MZUChm827mSOekrqJGyOAI5UzGYmC2
\r
33 qCeSVHAoYllHmbZmml50F9uQ0rkAG2kl3YQUxjsduQIXghJfLDdnsP6hx5g08xpPYpDe
\r
34 bCnuahd0P3KSs+dZ45fgz4VC/0i/a1+j9cVOj2EF0mi8cgJe8FoFEHCJu8AAEPrtQD5r
\r
37 ALoCoQnKPyrbVX4dplugOxSlS3e0L9wSNEggFThPNxmJqSiSIwJOE3uUywKCvxfHUBCCJZYn9Wdl
\r
38 X-Received: by 10.180.19.234 with SMTP id i10mr2975057wie.28.1414834272829;
\r
39 Sat, 01 Nov 2014 02:31:12 -0700 (PDT)
\r
40 Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi.
\r
42 by mx.google.com with ESMTPSA id n4sm1364692wiz.17.2014.11.01.02.31.11
\r
43 for <multiple recipients>
\r
44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
\r
45 Sat, 01 Nov 2014 02:31:12 -0700 (PDT)
\r
46 From: Jani Nikula <jani@nikula.org>
\r
47 To: notmuch@notmuchmail.org
\r
48 Subject: [PATCH v2 1/2] cli: add support for notmuch search --duplicate=N with
\r
50 Date: Sat, 1 Nov 2014 11:31:06 +0200
\r
52 <848dc1dd0e62dc85abd69f5cf675cbce89f5e127.1414834143.git.jani@nikula.org>
\r
53 X-Mailer: git-send-email 2.1.1
\r
54 In-Reply-To: <cover.1414834143.git.jani@nikula.org>
\r
55 References: <cover.1414834143.git.jani@nikula.org>
\r
56 In-Reply-To: <cover.1414834143.git.jani@nikula.org>
\r
57 References: <cover.1414834143.git.jani@nikula.org>
\r
58 X-BeenThere: notmuch@notmuchmail.org
\r
59 X-Mailman-Version: 2.1.13
\r
61 List-Id: "Use and development of the notmuch mail system."
\r
62 <notmuch.notmuchmail.org>
\r
63 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
65 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
66 List-Post: <mailto:notmuch@notmuchmail.org>
\r
67 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
68 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
69 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
70 X-List-Received-Date: Sat, 01 Nov 2014 09:31:19 -0000
\r
72 Print the message IDs of all messages matching the search terms that
\r
73 have at least N files associated with them.
\r
75 doc/man1/notmuch-search.rst | 12 ++++++++----
\r
76 notmuch-search.c | 35 +++++++++++++++++++++++++++++++----
\r
77 2 files changed, 39 insertions(+), 8 deletions(-)
\r
79 diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
\r
80 index b6607c922cc0..8110086eff4f 100644
\r
81 --- a/doc/man1/notmuch-search.rst
\r
82 +++ b/doc/man1/notmuch-search.rst
\r
83 @@ -142,10 +142,14 @@ Supported options for **search** include
\r
84 rather than the number of matching messages.
\r
87 - Effective with ``--output=files``, output the Nth filename
\r
88 - associated with each message matching the query (N is 1-based).
\r
89 - If N is greater than the number of files associated with the
\r
90 - message, don't print anything.
\r
91 + For ``--output=files``, output the Nth filename associated
\r
92 + with each message matching the query (N is 1-based). If N is
\r
93 + greater than the number of files associated with the message,
\r
94 + don't print anything.
\r
96 + For ``--output=messages``, only output message IDs of messages
\r
97 + matching the search terms that have at least N filenames
\r
98 + associated with them.
\r
100 Note that this option is orthogonal with the **folder:** search
\r
101 prefix. The prefix matches messages based on filenames. This
\r
102 diff --git a/notmuch-search.c b/notmuch-search.c
\r
103 index 671fe4139981..6345fb6280ac 100644
\r
104 --- a/notmuch-search.c
\r
105 +++ b/notmuch-search.c
\r
106 @@ -311,6 +311,24 @@ process_address_header (const search_options_t *opt, const char *value)
\r
110 +_count_filenames (notmuch_message_t *message)
\r
112 + notmuch_filenames_t *filenames;
\r
115 + filenames = notmuch_message_get_filenames (message);
\r
117 + while (notmuch_filenames_valid (filenames)) {
\r
118 + notmuch_filenames_move_to_next (filenames);
\r
122 + notmuch_filenames_destroy (filenames);
\r
128 do_search_messages (search_options_t *opt)
\r
130 notmuch_message_t *message;
\r
131 @@ -357,10 +375,13 @@ do_search_messages (search_options_t *opt)
\r
132 notmuch_filenames_destroy( filenames );
\r
134 } else if (opt->output == OUTPUT_MESSAGES) {
\r
135 - format->set_prefix (format, "id");
\r
136 - format->string (format,
\r
137 - notmuch_message_get_message_id (message));
\r
138 - format->separator (format);
\r
139 + /* special case 1 for speed */
\r
140 + if (opt->dupe <= 1 || opt->dupe <= _count_filenames (message)) {
\r
141 + format->set_prefix (format, "id");
\r
142 + format->string (format,
\r
143 + notmuch_message_get_message_id (message));
\r
144 + format->separator (format);
\r
147 if (opt->output & OUTPUT_SENDER) {
\r
149 @@ -503,6 +524,12 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
151 opt.output = OUTPUT_SUMMARY;
\r
153 + if (opt.output != OUTPUT_FILES && opt.output != OUTPUT_MESSAGES &&
\r
154 + opt.dupe != -1) {
\r
155 + fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");
\r
156 + return EXIT_FAILURE;
\r
159 switch (format_sel) {
\r
160 case NOTMUCH_FORMAT_TEXT:
\r
161 opt.format = sprinter_text_create (config, stdout);
\r