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 906A5431FDB
\r
6 for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:39:44 -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 tM0jdoT-sQLh for <notmuch@notmuchmail.org>;
\r
16 Mon, 22 Sep 2014 02:39:39 -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 93EBB431FC2
\r
19 for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:39:28 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 65B485CCE62;
\r
22 Mon, 22 Sep 2014 11:39:27 +0200 (CEST)
\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
27 with ESMTP id OVZdS9Yu6svX; Mon, 22 Sep 2014 11:39:22 +0200 (CEST)
\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 880765CCE64;
\r
30 Mon, 22 Sep 2014 11:39:22 +0200 (CEST)
\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 1XW05U-0001wG-MI; Mon, 22 Sep 2014 11:39:16 +0200
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH 2/5] cli: Extend the search command for --output=addresses and
\r
38 Date: Mon, 22 Sep 2014 11:37:56 +0200
\r
39 Message-Id: <1411378679-7307-3-git-send-email-sojkam1@fel.cvut.cz>
\r
40 X-Mailer: git-send-email 2.1.0
\r
41 In-Reply-To: <1411378679-7307-1-git-send-email-sojkam1@fel.cvut.cz>
\r
42 References: <1411378679-7307-1-git-send-email-sojkam1@fel.cvut.cz>
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\r
46 List-Id: "Use and development of the notmuch mail system."
\r
47 <notmuch.notmuchmail.org>
\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
51 List-Post: <mailto:notmuch@notmuchmail.org>
\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
55 X-List-Received-Date: Mon, 22 Sep 2014 09:39:44 -0000
\r
57 The new outputs allow printing senders, recipients or both of matching
\r
60 This code based on a patch from Jani Nikula.
\r
62 completion/notmuch-completion.bash | 2 +-
\r
63 completion/notmuch-completion.zsh | 3 +-
\r
64 doc/man1/notmuch-search.rst | 22 +++++++-
\r
65 notmuch-search.c | 100 ++++++++++++++++++++++++++++++++++---
\r
66 4 files changed, 118 insertions(+), 9 deletions(-)
\r
68 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
\r
69 index 0571dc9..c37ddf5 100644
\r
70 --- a/completion/notmuch-completion.bash
\r
71 +++ b/completion/notmuch-completion.bash
\r
72 @@ -294,7 +294,7 @@ _notmuch_search()
\r
76 - COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )
\r
77 + COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients addresses" -- "${cur}" ) )
\r
81 diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh
\r
82 index 67a9aba..bff8fd5 100644
\r
83 --- a/completion/notmuch-completion.zsh
\r
84 +++ b/completion/notmuch-completion.zsh
\r
85 @@ -52,7 +52,8 @@ _notmuch_search()
\r
87 '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \
\r
88 '--first=[omit the first x threads from the search results]:number of threads to omit: ' \
\r
89 - '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))'
\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 addresses))'
\r
95 diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
\r
96 index 90160f2..6094906 100644
\r
97 --- a/doc/man1/notmuch-search.rst
\r
98 +++ b/doc/man1/notmuch-search.rst
\r
99 @@ -35,7 +35,7 @@ Supported options for **search** include
\r
100 intended for programs that invoke **notmuch(1)** internally. If
\r
101 omitted, the latest supported version will be used.
\r
103 - ``--output=(summary|threads|messages|files|tags)``
\r
104 + ``--output=(summary|threads|messages|files|tags|sender|recipients|addresses)``
\r
107 Output a summary of each thread with any message matching
\r
108 @@ -78,6 +78,26 @@ Supported options for **search** include
\r
109 by null characters (--format=text0), as a JSON array
\r
110 (--format=json), or as an S-Expression list (--format=sexp).
\r
113 + Output all addresses from the *From* header that appear on
\r
114 + any message matching the search terms, either one per line
\r
115 + (--format=text), separated by null characters
\r
116 + (--format=text0), as a JSON array (--format=json), or as
\r
117 + an S-Expression list (--format=sexp).
\r
119 + Note: Searching for **sender** should much be faster than
\r
120 + searching for **recipients** or **addresses**, because
\r
121 + sender addresses are cached directly in the database
\r
122 + whereas other addresses need to be fetched from the
\r
123 + message file by parsing it.
\r
126 + Like **sender** but for addresses from *To*, *Cc* and
\r
130 + Like **sender** and **recipients** together.
\r
132 ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
\r
133 This option can be used to present results in either
\r
134 chronological order (**oldest-first**) or reverse chronological
\r
135 diff --git a/notmuch-search.c b/notmuch-search.c
\r
136 index 5ac2a26..0614f10 100644
\r
137 --- a/notmuch-search.c
\r
138 +++ b/notmuch-search.c
\r
139 @@ -23,11 +23,14 @@
\r
140 #include "string-util.h"
\r
148 + OUTPUT_SUMMARY = 1 << 0,
\r
149 + OUTPUT_THREADS = 1 << 1,
\r
150 + OUTPUT_MESSAGES = 1 << 2,
\r
151 + OUTPUT_FILES = 1 << 3,
\r
152 + OUTPUT_TAGS = 1 << 4,
\r
153 + OUTPUT_SENDER = 1 << 5,
\r
154 + OUTPUT_RECIPIENTS = 1 << 6,
\r
155 + OUTPUT_ADDRESSES = OUTPUT_SENDER | OUTPUT_RECIPIENTS,
\r
159 @@ -220,6 +223,67 @@ do_search_threads (search_options_t *o)
\r
164 +print_address_list (const search_options_t *o, InternetAddressList *list)
\r
166 + InternetAddress *address;
\r
169 + for (i = 0; i < internet_address_list_length (list); i++) {
\r
170 + address = internet_address_list_get_address (list, i);
\r
171 + if (INTERNET_ADDRESS_IS_GROUP (address)) {
\r
172 + InternetAddressGroup *group;
\r
173 + InternetAddressList *group_list;
\r
175 + group = INTERNET_ADDRESS_GROUP (address);
\r
176 + group_list = internet_address_group_get_members (group);
\r
177 + if (group_list == NULL)
\r
180 + print_address_list (o, group_list);
\r
182 + InternetAddressMailbox *mailbox;
\r
183 + const char *name;
\r
184 + const char *addr;
\r
185 + char *full_address;
\r
187 + mailbox = INTERNET_ADDRESS_MAILBOX (address);
\r
189 + name = internet_address_get_name (address);
\r
190 + addr = internet_address_mailbox_get_addr (mailbox);
\r
192 + if (name && *name)
\r
193 + full_address = talloc_asprintf (o->format, "%s <%s>", name, addr);
\r
195 + full_address = talloc_strdup (o->format, addr);
\r
197 + if (!full_address) {
\r
198 + fprintf (stderr, "Error: out of memory\n");
\r
201 + o->format->string (o->format, full_address);
\r
202 + o->format->separator (o->format);
\r
204 + talloc_free (full_address);
\r
210 +print_address_string (const search_options_t *o, const char *recipients)
\r
212 + InternetAddressList *list;
\r
214 + if (recipients == NULL)
\r
217 + list = internet_address_list_parse_string (recipients);
\r
218 + if (list == NULL)
\r
221 + print_address_list (o, list);
\r
225 do_search_messages (search_options_t *o)
\r
227 @@ -266,11 +330,29 @@ do_search_messages (search_options_t *o)
\r
229 notmuch_filenames_destroy( filenames );
\r
231 - } else { /* output == OUTPUT_MESSAGES */
\r
232 + } else if (o->output == OUTPUT_MESSAGES) {
\r
233 format->set_prefix (format, "id");
\r
234 format->string (format,
\r
235 notmuch_message_get_message_id (message));
\r
236 format->separator (format);
\r
238 + if (o->output & OUTPUT_SENDER) {
\r
239 + const char *addrs;
\r
241 + addrs = notmuch_message_get_header (message, "from");
\r
242 + print_address_string (o, addrs);
\r
245 + if (o->output & OUTPUT_RECIPIENTS) {
\r
246 + const char *hdrs[] = { "to", "cc", "bcc" };
\r
247 + const char *addrs;
\r
250 + for (j = 0; j < ARRAY_SIZE (hdrs); j++) {
\r
251 + addrs = notmuch_message_get_header (message, hdrs[j]);
\r
252 + print_address_string (o, addrs);
\r
257 notmuch_message_destroy (message);
\r
258 @@ -370,6 +452,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
259 (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
\r
260 { "threads", OUTPUT_THREADS },
\r
261 { "messages", OUTPUT_MESSAGES },
\r
262 + { "sender", OUTPUT_SENDER },
\r
263 + { "recipients", OUTPUT_RECIPIENTS },
\r
264 + { "addresses", OUTPUT_ADDRESSES },
\r
265 { "files", OUTPUT_FILES },
\r
266 { "tags", OUTPUT_TAGS },
\r
268 @@ -461,6 +546,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
269 ret = do_search_threads (&o);
\r
271 case OUTPUT_MESSAGES:
\r
272 + case OUTPUT_SENDER:
\r
273 + case OUTPUT_RECIPIENTS:
\r
274 + case OUTPUT_ADDRESSES:
\r
276 ret = do_search_messages (&o);
\r