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 9A7F9429E38
\r
6 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 16:26:52 -0800 (PST)
\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 Rsqeu-H1y4nt for <notmuch@notmuchmail.org>;
\r
16 Tue, 4 Nov 2014 16:26:44 -0800 (PST)
\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 785DC431FC3
\r
19 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 16:26:22 -0800 (PST)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id D47BD5CD1AA
\r
22 for <notmuch@notmuchmail.org>; Wed, 5 Nov 2014 01:26:21 +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 ekCy3NQNhquW for <notmuch@notmuchmail.org>;
\r
27 Wed, 5 Nov 2014 01:26:17 +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 42D815CD1AD
\r
30 for <notmuch@notmuchmail.org>; Wed, 5 Nov 2014 01:26:14 +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 1XloQI-0005D2-TT; Wed, 05 Nov 2014 01:26:06 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v3 06/10] cli: Introduce "notmuch address" command
\r
37 Date: Wed, 5 Nov 2014 01:25:55 +0100
\r
38 Message-Id: <1415147159-19946-7-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 2.1.1
\r
40 In-Reply-To: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 References: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Wed, 05 Nov 2014 00:26:52 -0000
\r
56 This moves address-related functionality from search command to the
\r
57 new address command. The implementation shares almost all code and
\r
58 some command line options.
\r
60 Options --offset and --limit were intentionally not included in the
\r
61 address command, because they refer to messages numbers, which users
\r
62 do not see in the output. This could confuse users because, for
\r
63 example, they could see more addresses in the output that what was
\r
64 specified with --limit. This functionality can be correctly
\r
65 reimplemented for address subcommand later.
\r
67 Also useless values of --exclude flag were not included in the address
\r
70 This was inspired by a patch from Jani Nikula.
\r
72 completion/notmuch-completion.bash | 42 ++++++++++++++++-
\r
73 completion/notmuch-completion.zsh | 10 +++-
\r
74 doc/man1/notmuch-address.rst | 89 ++++++++++++++++++++++++++++++++++++
\r
75 doc/man1/notmuch-search.rst | 20 +-------
\r
76 doc/man1/notmuch.rst | 7 +--
\r
77 notmuch-client.h | 3 ++
\r
78 notmuch-search.c | 93 +++++++++++++++++++++++++++-----------
\r
80 8 files changed, 216 insertions(+), 50 deletions(-)
\r
81 create mode 100644 doc/man1/notmuch-address.rst
\r
83 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
\r
84 index cfbd389..94ea2d5 100644
\r
85 --- a/completion/notmuch-completion.bash
\r
86 +++ b/completion/notmuch-completion.bash
\r
87 @@ -294,7 +294,7 @@ _notmuch_search()
\r
91 - COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) )
\r
92 + COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )
\r
96 @@ -320,6 +320,44 @@ _notmuch_search()
\r
100 +_notmuch_address()
\r
102 + local cur prev words cword split
\r
103 + _init_completion -s || return
\r
106 + case "${prev}" in
\r
108 + COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )
\r
112 + COMPREPLY=( $( compgen -W "sender recipients" -- "${cur}" ) )
\r
116 + COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )
\r
120 + COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
\r
128 + local options="--format= --output= --sort= --exclude="
\r
129 + compopt -o nospace
\r
130 + COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
\r
133 + _notmuch_search_terms
\r
140 local cur prev words cword split
\r
141 @@ -393,7 +431,7 @@ _notmuch_tag()
\r
145 - local _notmuch_commands="compact config count dump help insert new reply restore search setup show tag"
\r
146 + local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag"
\r
147 local arg cur prev words cword split
\r
149 # require bash-completion with _init_completion
\r
150 diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh
\r
151 index 3e52a00..c606b75 100644
\r
152 --- a/completion/notmuch-completion.zsh
\r
153 +++ b/completion/notmuch-completion.zsh
\r
154 @@ -10,6 +10,7 @@ _notmuch_commands()
\r
155 'setup:interactively set up notmuch for first use'
\r
156 'new:find and import any new message to the database'
\r
157 'search:search for messages matching the search terms, display matching threads as results'
\r
158 + 'address:get addresses from messages matching the given search terms'
\r
159 'reply:constructs a reply template for a set of messages'
\r
160 'show:show all messages matching the search terms'
\r
161 'tag:add or remove tags for all messages matching the search terms'
\r
162 @@ -53,7 +54,14 @@ _notmuch_search()
\r
163 '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \
\r
164 '--first=[omit the first x threads from the search results]:number of threads to omit: ' \
\r
165 '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \
\r
166 - '--output=[select what to output]:output:((summary threads messages files tags sender recipients))'
\r
167 + '--output=[select what to output]:output:((summary threads messages files tags))'
\r
170 +_notmuch_address()
\r
172 + _arguments -s : \
\r
173 + '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \
\r
174 + '--output=[select what to output]:output:((sender recipients))'
\r
178 diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst
\r
179 new file mode 100644
\r
180 index 0000000..d349237
\r
182 +++ b/doc/man1/notmuch-address.rst
\r
191 +**notmuch** **address** [*option* ...] <*search-term*> ...
\r
196 +Search for messages matching the given search terms, and display the
\r
197 +addresses from them.
\r
199 +See **notmuch-search-terms(7)** for details of the supported syntax for
\r
202 +Supported options for **address** include
\r
204 + ``--format=``\ (**json**\ \|\ **sexp**\ \|\ **text**\ \|\ **text0**)
\r
205 + Presents the results in either JSON, S-Expressions, newline
\r
206 + character separated plain-text (default), or null character
\r
207 + separated plain-text (compatible with **xargs(1)** -0 option
\r
208 + where available).
\r
210 + ``--format-version=N``
\r
211 + Use the specified structured output format version. This is
\r
212 + intended for programs that invoke **notmuch(1)** internally. If
\r
213 + omitted, the latest supported version will be used.
\r
215 + ``--output=(sender|recipients)``
\r
217 + Controls which information appears in the output. This option
\r
218 + can be given multiple times to combine different outputs.
\r
219 + Omitting this option is equivalent to
\r
220 + --output=sender --output=recipients.
\r
223 + Output all addresses from the *From* header.
\r
225 + Note: Searching for **sender** should be much faster than
\r
226 + searching for **recipients**, because sender addresses are
\r
227 + cached directly in the database whereas other addresses
\r
228 + need to be fetched from message files.
\r
231 + Output all addresses from the *To*, *Cc* and *Bcc*
\r
234 + ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
\r
235 + This option can be used to present results in either
\r
236 + chronological order (**oldest-first**) or reverse chronological
\r
237 + order (**newest-first**).
\r
239 + By default, results will be displayed in reverse chronological
\r
240 + order, (that is, the newest results will be displayed first).
\r
242 + ``--exclude=(true|false)``
\r
243 + A message is called "excluded" if it matches at least one tag in
\r
244 + search.tag\_exclude that does not appear explicitly in the
\r
245 + search terms. This option specifies whether to omit excluded
\r
246 + messages in the search process.
\r
248 + The default value, **true**, prevents excluded messages from
\r
249 + matching the search terms.
\r
251 + **false** allows excluded messages to match search terms and
\r
252 + appear in displayed results.
\r
257 +This command supports the following special exit status codes
\r
260 + The requested format version is too old.
\r
263 + The requested format version is too new.
\r
268 +**notmuch(1)**, **notmuch-config(1)**, **notmuch-count(1)**,
\r
269 +**notmuch-dump(1)**, **notmuch-hooks(5)**, **notmuch-insert(1)**,
\r
270 +**notmuch-new(1)**, **notmuch-reply(1)**, **notmuch-restore(1)**,
\r
271 +**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**,
\r
272 +***notmuch-search(1)**
\r
273 diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
\r
274 index 8110086..65df288 100644
\r
275 --- a/doc/man1/notmuch-search.rst
\r
276 +++ b/doc/man1/notmuch-search.rst
\r
277 @@ -78,25 +78,8 @@ Supported options for **search** include
\r
278 by null characters (--format=text0), as a JSON array
\r
279 (--format=json), or as an S-Expression list (--format=sexp).
\r
282 - Output all addresses from the *From* header that appear on
\r
283 - any message matching the search terms, either one per line
\r
284 - (--format=text), separated by null characters
\r
285 - (--format=text0), as a JSON array (--format=json), or as
\r
286 - an S-Expression list (--format=sexp).
\r
288 - Note: Searching for **sender** should be much faster than
\r
289 - searching for **recipients**, because sender addresses are
\r
290 - cached directly in the database whereas other addresses
\r
291 - need to be fetched from message files.
\r
294 - Like **sender** but for addresses from *To*, *Cc* and
\r
297 This option can be given multiple times to combine different
\r
298 - outputs. Currently, this is only supported for **sender** and
\r
299 - **recipients** outputs.
\r
302 ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
\r
303 This option can be used to present results in either
\r
304 @@ -173,3 +156,4 @@ SEE ALSO
\r
305 **notmuch-dump(1)**, **notmuch-hooks(5)**, **notmuch-insert(1)**,
\r
306 **notmuch-new(1)**, **notmuch-reply(1)**, **notmuch-restore(1)**,
\r
307 **notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**
\r
308 +***notmuch-address(1)**
\r
309 diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
\r
310 index 9710294..98590a4 100644
\r
311 --- a/doc/man1/notmuch.rst
\r
312 +++ b/doc/man1/notmuch.rst
\r
313 @@ -88,8 +88,8 @@ Several of the notmuch commands accept search terms with a common
\r
314 syntax. See **notmuch-search-terms**\ (7) for more details on the
\r
317 -The **search**, **show** and **count** commands are used to query the
\r
319 +The **search**, **show**, **address** and **count** commands are used
\r
320 +to query the email database.
\r
322 The **reply** command is useful for preparing a template for an email
\r
324 @@ -128,7 +128,8 @@ SEE ALSO
\r
325 **notmuch-config(1)**, **notmuch-count(1)**, **notmuch-dump(1)**,
\r
326 **notmuch-hooks(5)**, **notmuch-insert(1)**, **notmuch-new(1)**,
\r
327 **notmuch-reply(1)**, **notmuch-restore(1)**, **notmuch-search(1)**,
\r
328 -**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**
\r
329 +**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**,
\r
330 +***notmuch-address(1)**
\r
332 The notmuch website: **http://notmuchmail.org**
\r
334 diff --git a/notmuch-client.h b/notmuch-client.h
\r
335 index e1efbe0..5e0d475 100644
\r
336 --- a/notmuch-client.h
\r
337 +++ b/notmuch-client.h
\r
338 @@ -199,6 +199,9 @@ int
\r
339 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);
\r
342 +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]);
\r
345 notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);
\r
348 diff --git a/notmuch-search.c b/notmuch-search.c
\r
349 index f115359..69938d6 100644
\r
350 --- a/notmuch-search.c
\r
351 +++ b/notmuch-search.c
\r
352 @@ -23,17 +23,18 @@
\r
353 #include "string-util.h"
\r
356 + /* Search command */
\r
357 OUTPUT_SUMMARY = 1 << 0,
\r
358 OUTPUT_THREADS = 1 << 1,
\r
359 OUTPUT_MESSAGES = 1 << 2,
\r
360 OUTPUT_FILES = 1 << 3,
\r
361 OUTPUT_TAGS = 1 << 4,
\r
363 + /* Address command */
\r
364 OUTPUT_SENDER = 1 << 5,
\r
365 OUTPUT_RECIPIENTS = 1 << 6,
\r
368 -#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)
\r
371 NOTMUCH_FORMAT_JSON,
\r
372 NOTMUCH_FORMAT_TEXT,
\r
373 @@ -554,39 +555,42 @@ _notmuch_search_cleanup (search_context_t *ctx)
\r
374 talloc_free (ctx->format);
\r
377 +static search_context_t search_context = {
\r
378 + .format_sel = NOTMUCH_FORMAT_TEXT,
\r
379 + .exclude = NOTMUCH_EXCLUDE_TRUE,
\r
380 + .sort = NOTMUCH_SORT_NEWEST_FIRST,
\r
383 + .limit = -1, /* unlimited */
\r
387 +static const notmuch_opt_desc_t common_options[] = {
\r
388 + { NOTMUCH_OPT_KEYWORD, &search_context.sort, "sort", 's',
\r
389 + (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
390 + { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
392 + { NOTMUCH_OPT_KEYWORD, &search_context.format_sel, "format", 'f',
\r
393 + (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
\r
394 + { "sexp", NOTMUCH_FORMAT_SEXP },
\r
395 + { "text", NOTMUCH_FORMAT_TEXT },
\r
396 + { "text0", NOTMUCH_FORMAT_TEXT0 },
\r
398 + { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
\r
399 + { 0, 0, 0, 0, 0 }
\r
403 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
405 - search_context_t search_context = {
\r
406 - .format_sel = NOTMUCH_FORMAT_TEXT,
\r
407 - .exclude = NOTMUCH_EXCLUDE_TRUE,
\r
408 - .sort = NOTMUCH_SORT_NEWEST_FIRST,
\r
411 - .limit = -1, /* unlimited */
\r
414 search_context_t *ctx = &search_context;
\r
415 int opt_index, ret;
\r
417 notmuch_opt_desc_t options[] = {
\r
418 - { NOTMUCH_OPT_KEYWORD, &ctx->sort, "sort", 's',
\r
419 - (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
420 - { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
422 - { NOTMUCH_OPT_KEYWORD, &ctx->format_sel, "format", 'f',
\r
423 - (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
\r
424 - { "sexp", NOTMUCH_FORMAT_SEXP },
\r
425 - { "text", NOTMUCH_FORMAT_TEXT },
\r
426 - { "text0", NOTMUCH_FORMAT_TEXT0 },
\r
428 - { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
\r
429 { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',
\r
430 (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
\r
431 { "threads", OUTPUT_THREADS },
\r
432 { "messages", OUTPUT_MESSAGES },
\r
433 - { "sender", OUTPUT_SENDER },
\r
434 - { "recipients", OUTPUT_RECIPIENTS },
\r
435 { "files", OUTPUT_FILES },
\r
436 { "tags", OUTPUT_TAGS },
\r
438 @@ -599,6 +603,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
439 { NOTMUCH_OPT_INT, &ctx->offset, "offset", 'O', 0 },
\r
440 { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0 },
\r
441 { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0 },
\r
442 + { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },
\r
446 @@ -623,8 +628,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
447 ctx->output == OUTPUT_THREADS)
\r
448 ret = do_search_threads (ctx);
\r
449 else if (ctx->output == OUTPUT_MESSAGES ||
\r
450 - ctx->output == OUTPUT_FILES ||
\r
451 - (ctx->output & OUTPUT_ADDRESS_FLAGS && !(ctx->output & ~OUTPUT_ADDRESS_FLAGS)))
\r
452 + ctx->output == OUTPUT_FILES)
\r
453 ret = do_search_messages (ctx);
\r
454 else if (ctx->output == OUTPUT_TAGS)
\r
455 ret = do_search_tags (ctx);
\r
456 @@ -637,3 +641,40 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
458 return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r
462 +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
\r
464 + search_context_t *ctx = &search_context;
\r
465 + int opt_index, ret;
\r
467 + notmuch_opt_desc_t options[] = {
\r
468 + { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',
\r
469 + (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER },
\r
470 + { "recipients", OUTPUT_RECIPIENTS },
\r
472 + { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x',
\r
473 + (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
\r
474 + { "false", NOTMUCH_EXCLUDE_FALSE },
\r
476 + { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },
\r
477 + { 0, 0, 0, 0, 0 }
\r
480 + opt_index = parse_arguments (argc, argv, options, 1);
\r
481 + if (opt_index < 0)
\r
482 + return EXIT_FAILURE;
\r
484 + if (! ctx->output)
\r
485 + ctx->output = OUTPUT_SENDER | OUTPUT_RECIPIENTS;
\r
487 + if (_notmuch_search_prepare (ctx, config,
\r
488 + argc - opt_index, argv + opt_index))
\r
489 + return EXIT_FAILURE;
\r
491 + ret = do_search_messages (ctx);
\r
493 + _notmuch_search_cleanup (ctx);
\r
495 + return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r
497 diff --git a/notmuch.c b/notmuch.c
\r
498 index dcda039..0fac099 100644
\r
501 @@ -54,6 +54,8 @@ static command_t commands[] = {
\r
502 "Add a new message into the maildir and notmuch database." },
\r
503 { "search", notmuch_search_command, FALSE,
\r
504 "Search for messages matching the given search terms." },
\r
505 + { "address", notmuch_address_command, FALSE,
\r
506 + "Get addresses from messages matching the given search terms." },
\r
507 { "show", notmuch_show_command, FALSE,
\r
508 "Show all messages matching the search terms." },
\r
509 { "count", notmuch_count_command, FALSE,
\r