1 Return-Path: <sojkam1@fel.cvut.cz>
\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 2E97C429E42
\r
6 for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 17:00:06 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id yVywUpvPJlzq for <notmuch@notmuchmail.org>;
\r
16 Thu, 30 Oct 2014 16:59:57 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 27AA8431FDF
\r
19 for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 16:59:48 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 7F3335CCFF4
\r
22 for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 00:59:47 +0100 (CET)
\r
23 X-Virus-Scanned: IMAP STYX AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,
\r
26 port 10044) with ESMTP id oIR5Spa-B4u7 for <notmuch@notmuchmail.org>;
\r
27 Fri, 31 Oct 2014 00:59:44 +0100 (CET)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id EE9D75CCFFB
\r
30 for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 00:59:40 +0100 (CET)
\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)
\r
32 (envelope-from <sojkam1@fel.cvut.cz>)
\r
33 id 1Xjzcs-0005bb-Se; Fri, 31 Oct 2014 00:59:34 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v5 6/7] cli: search: Add --output=count
\r
37 Date: Fri, 31 Oct 2014 00:59:32 +0100
\r
38 Message-Id: <1414713573-21461-7-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 2.1.1
\r
40 In-Reply-To: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 References: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>
\r
43 Content-Type: text/plain; charset=UTF-8
\r
44 Content-Transfer-Encoding: 8bit
\r
45 X-BeenThere: notmuch@notmuchmail.org
\r
46 X-Mailman-Version: 2.1.13
\r
48 List-Id: "Use and development of the notmuch mail system."
\r
49 <notmuch.notmuchmail.org>
\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
53 List-Post: <mailto:notmuch@notmuchmail.org>
\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
56 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
57 X-List-Received-Date: Fri, 31 Oct 2014 00:00:06 -0000
\r
59 This output can be used with --output=recipients or --output=sender
\r
60 and in addition to the addresses, it prints how many times was each
\r
61 address encountered during search.
\r
63 completion/notmuch-completion.bash | 2 +-
\r
64 completion/notmuch-completion.zsh | 2 +-
\r
65 doc/man1/notmuch-search.rst | 9 +++++--
\r
66 notmuch-search.c | 51 ++++++++++++++++++++++++++++++++------
\r
67 test/T090-search-output.sh | 50 +++++++++++++++++++++++++++++++++++++
\r
68 5 files changed, 102 insertions(+), 12 deletions(-)
\r
70 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
\r
71 index cfbd389..39cd829 100644
\r
72 --- a/completion/notmuch-completion.bash
\r
73 +++ b/completion/notmuch-completion.bash
\r
74 @@ -294,7 +294,7 @@ _notmuch_search()
\r
78 - COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) )
\r
79 + COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients count" -- "${cur}" ) )
\r
83 diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh
\r
84 index 3e52a00..d7e5a5e 100644
\r
85 --- a/completion/notmuch-completion.zsh
\r
86 +++ b/completion/notmuch-completion.zsh
\r
87 @@ -53,7 +53,7 @@ _notmuch_search()
\r
88 '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \
\r
89 '--first=[omit the first x threads from the search results]:number of threads to omit: ' \
\r
90 '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \
\r
91 - '--output=[select what to output]:output:((summary threads messages files tags sender recipients))'
\r
92 + '--output=[select what to output]:output:((summary threads messages files tags sender recipients count))'
\r
96 diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
\r
97 index 42f17e4..ec89200 100644
\r
98 --- a/doc/man1/notmuch-search.rst
\r
99 +++ b/doc/man1/notmuch-search.rst
\r
100 @@ -96,9 +96,14 @@ Supported options for **search** include
\r
101 Like **sender** but for addresses from *To*, *Cc* and
\r
105 + Can be used in combination with **sender** or
\r
106 + **recipients** to print the count of how many times was
\r
107 + the address encountered during search.
\r
109 This option can be given multiple times to combine different
\r
110 - outputs. Currently, this is only supported for **sender** and
\r
111 - **recipients** outputs.
\r
112 + outputs. Currently, this is only supported for **sender**,
\r
113 + **recipients** and **count** outputs.
\r
115 ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
\r
116 This option can be used to present results in either
\r
117 diff --git a/notmuch-search.c b/notmuch-search.c
\r
118 index eae749a..15527c4 100644
\r
119 --- a/notmuch-search.c
\r
120 +++ b/notmuch-search.c
\r
121 @@ -30,9 +30,10 @@ typedef enum {
\r
122 OUTPUT_TAGS = 1 << 4,
\r
123 OUTPUT_SENDER = 1 << 5,
\r
124 OUTPUT_RECIPIENTS = 1 << 6,
\r
125 + OUTPUT_COUNT = 1 << 7,
\r
128 -#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)
\r
129 +#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS | OUTPUT_COUNT)
\r
132 sprinter_t *format;
\r
133 @@ -47,6 +48,7 @@ typedef struct {
\r
140 /* Return two stable query strings that identify exactly the matched
\r
141 @@ -235,17 +237,24 @@ is_duplicate (const search_options_t *opt, GHashTable *addrs, const char *name,
\r
143 notmuch_bool_t duplicate;
\r
145 + mailbox_t *mailbox;
\r
147 key = talloc_asprintf (opt->format, "%s <%s>", name, addr);
\r
151 - duplicate = g_hash_table_lookup_extended (addrs, key, NULL, NULL);
\r
152 + duplicate = g_hash_table_lookup_extended (addrs, key, NULL, (gpointer)&mailbox);
\r
155 - g_hash_table_insert (addrs, key, NULL);
\r
157 + if (! duplicate) {
\r
158 + mailbox = talloc (opt->format, mailbox_t);
\r
159 + mailbox->name = talloc_strdup (mailbox, name);
\r
160 + mailbox->addr = talloc_strdup (mailbox, addr);
\r
161 + mailbox->count = 1;
\r
162 + g_hash_table_insert (addrs, key, mailbox);
\r
164 + mailbox->count++;
\r
170 @@ -255,6 +264,7 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
\r
172 const char *name = mailbox->name;
\r
173 const char *addr = mailbox->addr;
\r
174 + int count = mailbox->count;
\r
175 sprinter_t *format = opt->format;
\r
177 if (format->is_text_printer) {
\r
178 @@ -269,6 +279,10 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
\r
179 fprintf (stderr, "Error: out of memory\n");
\r
183 + format->integer (format, count);
\r
184 + format->string (format, "\t");
\r
186 format->string (format, mailbox_str);
\r
187 format->separator (format);
\r
189 @@ -279,12 +293,16 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
\r
190 format->string (format, name);
\r
191 format->map_key (format, "address");
\r
192 format->string (format, addr);
\r
194 + format->map_key (format, "count");
\r
195 + format->integer (format, count);
\r
197 format->end (format);
\r
198 format->separator (format);
\r
202 -/* Print addresses from InternetAddressList. */
\r
203 +/* Print or prepare for printing addresses from InternetAddressList. */
\r
205 process_address_list (const search_options_t *opt, GHashTable *addrs,
\r
206 InternetAddressList *list)
\r
207 @@ -309,17 +327,21 @@ process_address_list (const search_options_t *opt, GHashTable *addrs,
\r
209 .name = internet_address_get_name (address),
\r
210 .addr = internet_address_mailbox_get_addr (mailbox),
\r
214 if (is_duplicate (opt, addrs, mbx.name, mbx.addr))
\r
217 + if (opt->output & OUTPUT_COUNT)
\r
220 print_mailbox (opt, &mbx);
\r
225 -/* Print addresses from a message header. */
\r
226 +/* Print or prepare for printing addresses from a message header. */
\r
228 process_address_header (const search_options_t *opt, GHashTable *addrs, const char *value)
\r
230 @@ -341,6 +363,15 @@ _my_talloc_free_for_g_hash (void *ptr)
\r
235 +print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)
\r
237 + const mailbox_t *mailbox = value;
\r
238 + search_options_t *opt = user_data;
\r
240 + print_mailbox (opt, mailbox);
\r
244 do_search_messages (search_options_t *opt)
\r
246 @@ -353,7 +384,7 @@ do_search_messages (search_options_t *opt)
\r
248 if (opt->output & OUTPUT_ADDRESS_FLAGS)
\r
249 addresses = g_hash_table_new_full (g_str_hash, g_str_equal,
\r
250 - _my_talloc_free_for_g_hash, NULL);
\r
251 + _my_talloc_free_for_g_hash, _my_talloc_free_for_g_hash);
\r
253 if (opt->offset < 0) {
\r
254 opt->offset += notmuch_query_count_messages (opt->query);
\r
255 @@ -420,6 +451,9 @@ do_search_messages (search_options_t *opt)
\r
256 notmuch_message_destroy (message);
\r
259 + if (addresses && opt->output & OUTPUT_COUNT)
\r
260 + g_hash_table_foreach (addresses, print_hash_value, opt);
\r
263 g_hash_table_unref (addresses);
\r
265 @@ -522,6 +556,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
266 { "recipients", OUTPUT_RECIPIENTS },
\r
267 { "files", OUTPUT_FILES },
\r
268 { "tags", OUTPUT_TAGS },
\r
269 + { "count", OUTPUT_COUNT },
\r
271 { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
\r
272 (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
\r
273 diff --git a/test/T090-search-output.sh b/test/T090-search-output.sh
\r
274 index 841a721..5a9bbc9 100755
\r
275 --- a/test/T090-search-output.sh
\r
276 +++ b/test/T090-search-output.sh
\r
277 @@ -433,6 +433,56 @@ cat <<EOF >EXPECTED
\r
279 test_expect_equal_file OUTPUT EXPECTED
\r
281 +test_begin_subtest "--output=sender --output=count"
\r
282 +notmuch search --output=sender --output=count '*' | sort -n >OUTPUT
\r
283 +cat <<EOF >EXPECTED
\r
284 +1 Adrian Perez de Castro <aperez@igalia.com>
\r
285 +1 Aron Griffis <agriffis@n01se.net>
\r
286 +1 Chris Wilson <chris@chris-wilson.co.uk>
\r
287 +1 François Boulogne <boulogne.f@gmail.com>
\r
288 +1 Ingmar Vanhassel <ingmar@exherbo.org>
\r
289 +1 Israel Herraiz <isra@herraiz.org>
\r
290 +1 Olivier Berger <olivier.berger@it-sudparis.eu>
\r
291 +1 Rolland Santimano <rollandsantimano@yahoo.com>
\r
292 +2 Alex Botero-Lowry <alex.boterolowry@gmail.com>
\r
293 +2 Jjgod Jiang <gzjjgod@gmail.com>
\r
294 +3 Stewart Smith <stewart@flamingspork.com>
\r
295 +4 Alexander Botero-Lowry <alex.boterolowry@gmail.com>
\r
296 +4 Jan Janak <jan@ryngle.com>
\r
297 +5 Lars Kellogg-Stedman <lars@seas.harvard.edu>
\r
298 +5 Mikhail Gusarov <dottedmag@dottedmag.net>
\r
299 +7 Keith Packard <keithp@keithp.com>
\r
300 +12 Carl Worth <cworth@cworth.org>
\r
302 +test_expect_equal_file OUTPUT EXPECTED
\r
304 +test_begin_subtest "--output=sender --output=count --format=json"
\r
305 +# Since the iteration order of GHashTable is not specified, we
\r
306 +# preprocess and sort the results to keep the order stable here.
\r
307 +notmuch search --output=sender --output=count --format=json '*' | \
\r
308 + sed -e 's/^\[//' -e 's/]$//' -e 's/,$//' | \
\r
309 + sort --field-separator=":" --key=4n --key=2 >OUTPUT
\r
310 +cat <<EOF >EXPECTED
\r
311 +{"name": "Adrian Perez de Castro", "address": "aperez@igalia.com", "count": 1}
\r
312 +{"name": "Aron Griffis", "address": "agriffis@n01se.net", "count": 1}
\r
313 +{"name": "Chris Wilson", "address": "chris@chris-wilson.co.uk", "count": 1}
\r
314 +{"name": "François Boulogne", "address": "boulogne.f@gmail.com", "count": 1}
\r
315 +{"name": "Ingmar Vanhassel", "address": "ingmar@exherbo.org", "count": 1}
\r
316 +{"name": "Israel Herraiz", "address": "isra@herraiz.org", "count": 1}
\r
317 +{"name": "Olivier Berger", "address": "olivier.berger@it-sudparis.eu", "count": 1}
\r
318 +{"name": "Rolland Santimano", "address": "rollandsantimano@yahoo.com", "count": 1}
\r
319 +{"name": "Alex Botero-Lowry", "address": "alex.boterolowry@gmail.com", "count": 2}
\r
320 +{"name": "Jjgod Jiang", "address": "gzjjgod@gmail.com", "count": 2}
\r
321 +{"name": "Stewart Smith", "address": "stewart@flamingspork.com", "count": 3}
\r
322 +{"name": "Alexander Botero-Lowry", "address": "alex.boterolowry@gmail.com", "count": 4}
\r
323 +{"name": "Jan Janak", "address": "jan@ryngle.com", "count": 4}
\r
324 +{"name": "Lars Kellogg-Stedman", "address": "lars@seas.harvard.edu", "count": 5}
\r
325 +{"name": "Mikhail Gusarov", "address": "dottedmag@dottedmag.net", "count": 5}
\r
326 +{"name": "Keith Packard", "address": "keithp@keithp.com", "count": 7}
\r
327 +{"name": "Carl Worth", "address": "cworth@cworth.org", "count": 12}
\r
329 +test_expect_equal_file OUTPUT EXPECTED
\r
331 test_begin_subtest "--output=recipients"
\r
332 notmuch search --output=recipients '*' >OUTPUT
\r
333 cat <<EOF >EXPECTED
\r