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 1F0D9431FAF
\r
6 for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 17:50:30 -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 Pew+CTG+BqoB for <notmuch@notmuchmail.org>;
\r
16 Sat, 1 Nov 2014 17:50:23 -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 C43AF431FDD
\r
19 for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 17:50:14 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 746535CD28B
\r
22 for <notmuch@notmuchmail.org>; Sun, 2 Nov 2014 01:50:14 +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 zIh7ldlox8Ko for <notmuch@notmuchmail.org>;
\r
27 Sun, 2 Nov 2014 01:50:10 +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 1711F5CD292
\r
30 for <notmuch@notmuchmail.org>; Sun, 2 Nov 2014 01:50:07 +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 1XkjMq-00085B-Hc; Sun, 02 Nov 2014 01:50:04 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH 06/10] cli: Introduce "notmuch address" command
\r
37 Date: Sun, 2 Nov 2014 01:49:56 +0100
\r
38 Message-Id: <1414889400-30977-7-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 2.1.1
\r
40 In-Reply-To: <1414889400-30977-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 References: <1414889400-30977-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: Sun, 02 Nov 2014 00:50:30 -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 addresses later.
\r
67 This was inspired by a patch from Jani Nikula.
\r
69 completion/notmuch-completion.bash | 42 ++++++++++++++-
\r
70 completion/notmuch-completion.zsh | 10 +++-
\r
71 doc/man1/notmuch-address.rst | 99 ++++++++++++++++++++++++++++++++++++
\r
72 doc/man1/notmuch-search.rst | 20 +-------
\r
73 doc/man1/notmuch.rst | 7 +--
\r
74 notmuch-client.h | 3 ++
\r
75 notmuch-search.c | 101 +++++++++++++++++++++++++------------
\r
77 8 files changed, 228 insertions(+), 56 deletions(-)
\r
78 create mode 100644 doc/man1/notmuch-address.rst
\r
80 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
\r
81 index cfbd389..94ea2d5 100644
\r
82 --- a/completion/notmuch-completion.bash
\r
83 +++ b/completion/notmuch-completion.bash
\r
84 @@ -294,7 +294,7 @@ _notmuch_search()
\r
88 - COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) )
\r
89 + COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )
\r
93 @@ -320,6 +320,44 @@ _notmuch_search()
\r
99 + local cur prev words cword split
\r
100 + _init_completion -s || return
\r
103 + case "${prev}" in
\r
105 + COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )
\r
109 + COMPREPLY=( $( compgen -W "sender recipients" -- "${cur}" ) )
\r
113 + COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )
\r
117 + COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
\r
125 + local options="--format= --output= --sort= --exclude="
\r
126 + compopt -o nospace
\r
127 + COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
\r
130 + _notmuch_search_terms
\r
137 local cur prev words cword split
\r
138 @@ -393,7 +431,7 @@ _notmuch_tag()
\r
142 - local _notmuch_commands="compact config count dump help insert new reply restore search setup show tag"
\r
143 + local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag"
\r
144 local arg cur prev words cword split
\r
146 # require bash-completion with _init_completion
\r
147 diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh
\r
148 index 3e52a00..c606b75 100644
\r
149 --- a/completion/notmuch-completion.zsh
\r
150 +++ b/completion/notmuch-completion.zsh
\r
151 @@ -10,6 +10,7 @@ _notmuch_commands()
\r
152 'setup:interactively set up notmuch for first use'
\r
153 'new:find and import any new message to the database'
\r
154 'search:search for messages matching the search terms, display matching threads as results'
\r
155 + 'address:get addresses from messages matching the given search terms'
\r
156 'reply:constructs a reply template for a set of messages'
\r
157 'show:show all messages matching the search terms'
\r
158 'tag:add or remove tags for all messages matching the search terms'
\r
159 @@ -53,7 +54,14 @@ _notmuch_search()
\r
160 '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \
\r
161 '--first=[omit the first x threads from the search results]:number of threads to omit: ' \
\r
162 '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \
\r
163 - '--output=[select what to output]:output:((summary threads messages files tags sender recipients))'
\r
164 + '--output=[select what to output]:output:((summary threads messages files tags))'
\r
167 +_notmuch_address()
\r
169 + _arguments -s : \
\r
170 + '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \
\r
171 + '--output=[select what to output]:output:((sender recipients))'
\r
175 diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst
\r
176 new file mode 100644
\r
177 index 0000000..8109f11
\r
179 +++ b/doc/man1/notmuch-address.rst
\r
188 +**notmuch** **address** [*option* ...] <*search-term*> ...
\r
193 +Search for messages matching the given search terms, and display the
\r
194 +addresses from them.
\r
196 +See **notmuch-search-terms(7)** for details of the supported syntax for
\r
199 +Supported options for **address** include
\r
201 + ``--format=``\ (**json**\ \|\ **sexp**\ \|\ **text**\ \|\ **text0**)
\r
202 + Presents the results in either JSON, S-Expressions, newline
\r
203 + character separated plain-text (default), or null character
\r
204 + separated plain-text (compatible with **xargs(1)** -0 option
\r
205 + where available).
\r
207 + ``--format-version=N``
\r
208 + Use the specified structured output format version. This is
\r
209 + intended for programs that invoke **notmuch(1)** internally. If
\r
210 + omitted, the latest supported version will be used.
\r
212 + ``--output=(sender|recipients)``
\r
214 + Controls which information appears in the output. This option
\r
215 + can be given multiple times to combine different outputs.
\r
216 + Omitting this option is equivalent to
\r
217 + --output=sender --output=recipients.
\r
220 + Output all addresses from the *From* header.
\r
222 + Note: Searching for **sender** should be much faster than
\r
223 + searching for **recipients**, because sender addresses are
\r
224 + cached directly in the database whereas other addresses
\r
225 + need to be fetched from message files.
\r
228 + Output all addresses from the *To*, *Cc* and *Bcc*
\r
231 + ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
\r
232 + This option can be used to present results in either
\r
233 + chronological order (**oldest-first**) or reverse chronological
\r
234 + order (**newest-first**).
\r
236 + By default, results will be displayed in reverse chronological
\r
237 + order, (that is, the newest results will be displayed first).
\r
239 + ``--exclude=(true|false|all|flag)``
\r
240 + A message is called "excluded" if it matches at least one tag in
\r
241 + search.tag\_exclude that does not appear explicitly in the
\r
242 + search terms. This option specifies whether to omit excluded
\r
243 + messages in the search process.
\r
245 + The default value, **true**, prevents excluded messages from
\r
246 + matching the search terms.
\r
248 + **all** additionally prevents excluded messages from appearing
\r
249 + in displayed results, in effect behaving as though the excluded
\r
250 + messages do not exist.
\r
252 + **false** allows excluded messages to match search terms and
\r
253 + appear in displayed results. Excluded messages are still marked
\r
254 + in the relevant outputs.
\r
256 + **flag** only has an effect when ``--output=summary``. The
\r
257 + output is almost identical to **false**, but the "match count"
\r
258 + is the number of matching non-excluded messages in the thread,
\r
259 + rather than the number of matching messages.
\r
264 +This command supports the following special exit status codes
\r
267 + The requested format version is too old.
\r
270 + The requested format version is too new.
\r
275 +**notmuch(1)**, **notmuch-config(1)**, **notmuch-count(1)**,
\r
276 +**notmuch-dump(1)**, **notmuch-hooks(5)**, **notmuch-insert(1)**,
\r
277 +**notmuch-new(1)**, **notmuch-reply(1)**, **notmuch-restore(1)**,
\r
278 +**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**,
\r
279 +***notmuch-search(1)**
\r
280 diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
\r
281 index b6607c9..e919811 100644
\r
282 --- a/doc/man1/notmuch-search.rst
\r
283 +++ b/doc/man1/notmuch-search.rst
\r
284 @@ -78,25 +78,8 @@ Supported options for **search** include
\r
285 by null characters (--format=text0), as a JSON array
\r
286 (--format=json), or as an S-Expression list (--format=sexp).
\r
289 - Output all addresses from the *From* header that appear on
\r
290 - any message matching the search terms, either one per line
\r
291 - (--format=text), separated by null characters
\r
292 - (--format=text0), as a JSON array (--format=json), or as
\r
293 - an S-Expression list (--format=sexp).
\r
295 - Note: Searching for **sender** should be much faster than
\r
296 - searching for **recipients**, because sender addresses are
\r
297 - cached directly in the database whereas other addresses
\r
298 - need to be fetched from message files.
\r
301 - Like **sender** but for addresses from *To*, *Cc* and
\r
304 This option can be given multiple times to combine different
\r
305 - outputs. Currently, this is only supported for **sender** and
\r
306 - **recipients** outputs.
\r
309 ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
\r
310 This option can be used to present results in either
\r
311 @@ -169,3 +152,4 @@ SEE ALSO
\r
312 **notmuch-dump(1)**, **notmuch-hooks(5)**, **notmuch-insert(1)**,
\r
313 **notmuch-new(1)**, **notmuch-reply(1)**, **notmuch-restore(1)**,
\r
314 **notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**
\r
315 +***notmuch-address(1)**
\r
316 diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst
\r
317 index 9710294..98590a4 100644
\r
318 --- a/doc/man1/notmuch.rst
\r
319 +++ b/doc/man1/notmuch.rst
\r
320 @@ -88,8 +88,8 @@ Several of the notmuch commands accept search terms with a common
\r
321 syntax. See **notmuch-search-terms**\ (7) for more details on the
\r
324 -The **search**, **show** and **count** commands are used to query the
\r
326 +The **search**, **show**, **address** and **count** commands are used
\r
327 +to query the email database.
\r
329 The **reply** command is useful for preparing a template for an email
\r
331 @@ -128,7 +128,8 @@ SEE ALSO
\r
332 **notmuch-config(1)**, **notmuch-count(1)**, **notmuch-dump(1)**,
\r
333 **notmuch-hooks(5)**, **notmuch-insert(1)**, **notmuch-new(1)**,
\r
334 **notmuch-reply(1)**, **notmuch-restore(1)**, **notmuch-search(1)**,
\r
335 -**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**
\r
336 +**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**,
\r
337 +***notmuch-address(1)**
\r
339 The notmuch website: **http://notmuchmail.org**
\r
341 diff --git a/notmuch-client.h b/notmuch-client.h
\r
342 index e1efbe0..5e0d475 100644
\r
343 --- a/notmuch-client.h
\r
344 +++ b/notmuch-client.h
\r
345 @@ -199,6 +199,9 @@ int
\r
346 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);
\r
349 +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]);
\r
352 notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);
\r
355 diff --git a/notmuch-search.c b/notmuch-search.c
\r
356 index d7e64eb..7a78ecd 100644
\r
357 --- a/notmuch-search.c
\r
358 +++ b/notmuch-search.c
\r
359 @@ -23,17 +23,18 @@
\r
360 #include "string-util.h"
\r
363 + /* Search command */
\r
364 OUTPUT_SUMMARY = 1 << 0,
\r
365 OUTPUT_THREADS = 1 << 1,
\r
366 OUTPUT_MESSAGES = 1 << 2,
\r
367 OUTPUT_FILES = 1 << 3,
\r
368 OUTPUT_TAGS = 1 << 4,
\r
370 + /* Address command */
\r
371 OUTPUT_SENDER = 1 << 5,
\r
372 OUTPUT_RECIPIENTS = 1 << 6,
\r
375 -#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)
\r
378 NOTMUCH_FORMAT_JSON,
\r
379 NOTMUCH_FORMAT_TEXT,
\r
380 @@ -533,51 +534,55 @@ _notmuch_search_cleanup (search_context_t *ctx)
\r
381 talloc_free (ctx->format);
\r
384 +static search_context_t search_context = {
\r
385 + .format_sel = NOTMUCH_FORMAT_TEXT,
\r
386 + .exclude = NOTMUCH_EXCLUDE_TRUE,
\r
387 + .sort = NOTMUCH_SORT_NEWEST_FIRST,
\r
390 + .limit = -1, /* unlimited */
\r
394 +static const notmuch_opt_desc_t common_options[] = {
\r
395 + { NOTMUCH_OPT_KEYWORD, &search_context.sort, "sort", 's',
\r
396 + (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
397 + { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
399 + { NOTMUCH_OPT_KEYWORD, &search_context.format_sel, "format", 'f',
\r
400 + (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
\r
401 + { "sexp", NOTMUCH_FORMAT_SEXP },
\r
402 + { "text", NOTMUCH_FORMAT_TEXT },
\r
403 + { "text0", NOTMUCH_FORMAT_TEXT0 },
\r
405 + { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
\r
406 + { NOTMUCH_OPT_KEYWORD, &search_context.exclude, "exclude", 'x',
\r
407 + (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
\r
408 + { "false", NOTMUCH_EXCLUDE_FALSE },
\r
409 + { "flag", NOTMUCH_EXCLUDE_FLAG },
\r
410 + { "all", NOTMUCH_EXCLUDE_ALL },
\r
412 + { 0, 0, 0, 0, 0 }
\r
416 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
418 - search_context_t search_context = {
\r
419 - .format_sel = NOTMUCH_FORMAT_TEXT,
\r
420 - .exclude = NOTMUCH_EXCLUDE_TRUE,
\r
421 - .sort = NOTMUCH_SORT_NEWEST_FIRST,
\r
424 - .limit = -1, /* unlimited */
\r
427 search_context_t *ctx = &search_context;
\r
428 int opt_index, ret;
\r
430 notmuch_opt_desc_t options[] = {
\r
431 - { NOTMUCH_OPT_KEYWORD, &ctx->sort, "sort", 's',
\r
432 - (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
433 - { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
435 - { NOTMUCH_OPT_KEYWORD, &ctx->format_sel, "format", 'f',
\r
436 - (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
\r
437 - { "sexp", NOTMUCH_FORMAT_SEXP },
\r
438 - { "text", NOTMUCH_FORMAT_TEXT },
\r
439 - { "text0", NOTMUCH_FORMAT_TEXT0 },
\r
441 - { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
\r
442 { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',
\r
443 (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
\r
444 { "threads", OUTPUT_THREADS },
\r
445 { "messages", OUTPUT_MESSAGES },
\r
446 - { "sender", OUTPUT_SENDER },
\r
447 - { "recipients", OUTPUT_RECIPIENTS },
\r
448 { "files", OUTPUT_FILES },
\r
449 { "tags", OUTPUT_TAGS },
\r
451 - { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x',
\r
452 - (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
\r
453 - { "false", NOTMUCH_EXCLUDE_FALSE },
\r
454 - { "flag", NOTMUCH_EXCLUDE_FLAG },
\r
455 - { "all", NOTMUCH_EXCLUDE_ALL },
\r
457 { NOTMUCH_OPT_INT, &ctx->offset, "offset", 'O', 0 },
\r
458 { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0 },
\r
459 { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0 },
\r
460 + { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },
\r
464 @@ -596,8 +601,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
465 ctx->output == OUTPUT_THREADS)
\r
466 ret = do_search_threads (ctx);
\r
467 else if (ctx->output == OUTPUT_MESSAGES ||
\r
468 - ctx->output == OUTPUT_FILES ||
\r
469 - (ctx->output & OUTPUT_ADDRESS_FLAGS && !(ctx->output & ~OUTPUT_ADDRESS_FLAGS)))
\r
470 + ctx->output == OUTPUT_FILES)
\r
471 ret = do_search_messages (ctx);
\r
472 else if (ctx->output == OUTPUT_TAGS)
\r
473 ret = do_search_tags (ctx);
\r
474 @@ -610,3 +614,36 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
476 return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r
480 +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
\r
482 + search_context_t *ctx = &search_context;
\r
483 + int opt_index, ret;
\r
485 + notmuch_opt_desc_t options[] = {
\r
486 + { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',
\r
487 + (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER },
\r
488 + { "recipients", OUTPUT_RECIPIENTS },
\r
490 + { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },
\r
491 + { 0, 0, 0, 0, 0 }
\r
494 + opt_index = parse_arguments (argc, argv, options, 1);
\r
495 + if (opt_index < 0)
\r
496 + return EXIT_FAILURE;
\r
498 + if (! ctx->output)
\r
499 + search_context.output = OUTPUT_SENDER | OUTPUT_RECIPIENTS;
\r
501 + if (_notmuch_search_prepare (ctx, config,
\r
502 + argc - opt_index, argv + opt_index))
\r
503 + return EXIT_FAILURE;
\r
505 + ret = do_search_messages (ctx);
\r
507 + _notmuch_search_cleanup (ctx);
\r
509 + return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r
511 diff --git a/notmuch.c b/notmuch.c
\r
512 index dcda039..0fac099 100644
\r
515 @@ -54,6 +54,8 @@ static command_t commands[] = {
\r
516 "Add a new message into the maildir and notmuch database." },
\r
517 { "search", notmuch_search_command, FALSE,
\r
518 "Search for messages matching the given search terms." },
\r
519 + { "address", notmuch_address_command, FALSE,
\r
520 + "Get addresses from messages matching the given search terms." },
\r
521 { "show", notmuch_show_command, FALSE,
\r
522 "Show all messages matching the search terms." },
\r
523 { "count", notmuch_count_command, FALSE,
\r