1 Return-Path: <cworth@cworth.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 3EE83431FC4
\r
6 for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 08:25:15 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id CaTBf7YbKHof; Sat, 21 Nov 2009 08:25:14 -0800 (PST)
\r
11 Received: from localhost.localdomain (localhost [127.0.0.1])
\r
12 by olra.theworths.org (Postfix) with ESMTP id 717B2431FAE;
\r
13 Sat, 21 Nov 2009 08:25:13 -0800 (PST)
\r
14 From: Carl Worth <cworth@cworth.org>
\r
15 To: notmuch@notmuchmail.org
\r
16 Date: Sat, 21 Nov 2009 17:24:19 +0100
\r
17 Message-Id: <1258820659-24473-3-git-send-email-cworth@cworth.org>
\r
18 X-Mailer: git-send-email 1.6.5.2
\r
19 In-Reply-To: <1258820659-24473-1-git-send-email-cworth@cworth.org>
\r
20 References: <1258820659-24473-1-git-send-email-cworth@cworth.org>
\r
21 Subject: [notmuch] [PATCH 2/2] Add a new "notmuch search-messages" command.
\r
22 X-BeenThere: notmuch@notmuchmail.org
\r
23 X-Mailman-Version: 2.1.12
\r
25 List-Id: "Use and development of the notmuch mail system."
\r
26 <notmuch.notmuchmail.org>
\r
27 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
28 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
29 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
30 List-Post: <mailto:notmuch@notmuchmail.org>
\r
31 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
32 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
33 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
34 X-List-Received-Date: Sat, 21 Nov 2009 16:25:15 -0000
\r
36 This allows for searching for individual messages, rather than threads
\r
37 as "notmuch search" does. Currently just prints out the message id for
\r
40 Makefile.local | 29 +++++-----
\r
41 notmuch-client.h | 3 +
\r
42 notmuch-search-messages.c | 138 +++++++++++++++++++++++++++++++++++++++++++++
\r
43 notmuch.c | 29 ++++++++-
\r
44 4 files changed, 181 insertions(+), 18 deletions(-)
\r
45 create mode 100644 notmuch-search-messages.c
\r
47 diff --git a/Makefile.local b/Makefile.local
\r
48 index 3c99624..288d5e9 100644
\r
49 --- a/Makefile.local
\r
50 +++ b/Makefile.local
\r
51 @@ -2,20 +2,21 @@ all: notmuch notmuch.1.gz
\r
55 -notmuch_client_srcs = \
\r
57 - notmuch-config.c \
\r
61 - notmuch-restore.c \
\r
62 - notmuch-search.c \
\r
67 - gmime-filter-reply.c \
\r
69 +notmuch_client_srcs = \
\r
71 + notmuch-config.c \
\r
75 + notmuch-restore.c \
\r
76 + notmuch-search.c \
\r
77 + notmuch-search-messages.c \
\r
82 + gmime-filter-reply.c \
\r
86 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
\r
87 diff --git a/notmuch-client.h b/notmuch-client.h
\r
88 index b65aa77..c4ca687 100644
\r
89 --- a/notmuch-client.h
\r
90 +++ b/notmuch-client.h
\r
91 @@ -106,6 +106,9 @@ int
\r
92 notmuch_search_command (void *ctx, int argc, char *argv[]);
\r
95 +notmuch_search_messages_command (void *ctx, int argc, char *argv[]);
\r
98 notmuch_setup_command (void *ctx, int argc, char *argv[]);
\r
101 diff --git a/notmuch-search-messages.c b/notmuch-search-messages.c
\r
102 new file mode 100644
\r
103 index 0000000..b01d566
\r
105 +++ b/notmuch-search-messages.c
\r
107 +/* notmuch - Not much of an email program, (just index and search)
\r
109 + * Copyright © 2009 Carl Worth
\r
111 + * This program is free software: you can redistribute it and/or modify
\r
112 + * it under the terms of the GNU General Public License as published by
\r
113 + * the Free Software Foundation, either version 3 of the License, or
\r
114 + * (at your option) any later version.
\r
116 + * This program is distributed in the hope that it will be useful,
\r
117 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
118 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
119 + * GNU General Public License for more details.
\r
121 + * You should have received a copy of the GNU General Public License
\r
122 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
124 + * Author: Carl Worth <cworth@cworth.org>
\r
127 +#include "notmuch-client.h"
\r
129 +/* If the user asks for a *lot* of results, lets give some results as
\r
130 + * quickly as possible and let the user read those while we compute
\r
131 + * the remainder. */
\r
132 +#define NOTMUCH_SHOW_INITIAL_BURST 100
\r
135 +do_search_messages (notmuch_query_t *query,
\r
136 + int first, int max)
\r
138 + notmuch_messages_t *messages;
\r
139 + notmuch_message_t *message;
\r
141 + for (messages = notmuch_query_search_messages (query, first, max);
\r
142 + notmuch_messages_has_more (messages);
\r
143 + notmuch_messages_advance (messages))
\r
145 + message = notmuch_messages_get (messages);
\r
147 + printf ("id:%s\n", notmuch_message_get_message_id (message));
\r
149 + notmuch_message_destroy (message);
\r
154 +notmuch_search_messages_command (void *ctx, int argc, char *argv[])
\r
156 + notmuch_config_t *config;
\r
157 + notmuch_database_t *notmuch;
\r
158 + notmuch_query_t *query;
\r
160 + int i, first = 0, max = -1;
\r
162 + notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
164 + for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
165 + if (strcmp (argv[i], "--") == 0) {
\r
169 + if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {
\r
170 + opt = argv[i] + sizeof ("--first=") - 1;
\r
171 + first = strtoul (opt, &end, 10);
\r
172 + if (*opt == '\0' || *end != '\0') {
\r
173 + fprintf (stderr, "Invalid value for --first: %s\n", opt);
\r
176 + } else if (STRNCMP_LITERAL (argv[i], "--max=") == 0) {
\r
177 + opt = argv[i] + sizeof ("--max=") - 1;
\r
178 + max = strtoul (opt, &end, 10);
\r
179 + if (*opt == '\0' || *end != '\0') {
\r
180 + fprintf (stderr, "Invalid value for --max: %s\n", opt);
\r
183 + } else if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {
\r
184 + opt = argv[i] + sizeof ("--sort=") - 1;
\r
185 + if (strcmp (opt, "oldest-first") == 0) {
\r
186 + sort = NOTMUCH_SORT_OLDEST_FIRST;
\r
187 + } else if (strcmp (opt, "newest-first") == 0) {
\r
188 + sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
190 + fprintf (stderr, "Invalid value for --sort: %s\n", opt);
\r
194 + fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
202 + config = notmuch_config_open (ctx, NULL, NULL);
\r
203 + if (config == NULL)
\r
206 + notmuch = notmuch_database_open (notmuch_config_get_database_path (config));
\r
207 + if (notmuch == NULL)
\r
210 + query_str = query_string_from_args (ctx, argc, argv);
\r
211 + if (query_str == NULL) {
\r
212 + fprintf (stderr, "Out of memory.\n");
\r
215 + if (*query_str == '\0') {
\r
216 + fprintf (stderr, "Error: notmuch search requires at least one search term.\n");
\r
220 + query = notmuch_query_create (notmuch, query_str);
\r
221 + if (query == NULL) {
\r
222 + fprintf (stderr, "Out of memory\n");
\r
226 + notmuch_query_set_sort (query, sort);
\r
228 + if (max < 0 || max > NOTMUCH_SHOW_INITIAL_BURST)
\r
230 + do_search_messages (query,
\r
231 + first, NOTMUCH_SHOW_INITIAL_BURST);
\r
233 + first += NOTMUCH_SHOW_INITIAL_BURST;
\r
235 + max -= NOTMUCH_SHOW_INITIAL_BURST;
\r
238 + do_search_messages (query, first, max);
\r
240 + notmuch_query_destroy (query);
\r
241 + notmuch_database_close (notmuch);
\r
245 diff --git a/notmuch.c b/notmuch.c
\r
246 index 14d4865..6440777 100644
\r
249 @@ -132,10 +132,31 @@ command_t commands[] = {
\r
250 "\t\tnot previously been run." },
\r
251 { "search", notmuch_search_command,
\r
252 "[options...] <search-terms> [...]",
\r
253 - "\t\tSearch for messages matching the given search terms.",
\r
254 - "\t\tNote that the individual mail messages will be matched\n"
\r
255 - "\t\tagainst the search terms, but the results will be the\n"
\r
256 - "\t\tthreads (one per line) containing the matched messages.\n"
\r
257 + "\t\tSearch for threads with messages matching the search terms.",
\r
259 + "\t\tSupported options for search include:\n"
\r
261 + "\t\t--max=<value>\n"
\r
263 + "\t\t\tRestricts displayed search results to a subset\n"
\r
264 + "\t\t\tof the results that would match the terms.\n"
\r
266 + "\t\t--first=<value>\n"
\r
268 + "\t\t\tOmits the first <value> threads from the search\n"
\r
269 + "\t\t\tresults that would otherwise be displayed.\n"
\r
271 + "\t\t--sort=(newest-first|oldest-first)\n"
\r
273 + "\t\t\tPresent results in either chronological order\n"
\r
274 + "\t\t\t(oldest-first) or reverse chronological order\n"
\r
275 + "\t\t\t(newest-first), which is the default.\n"
\r
277 + "\t\tSee \"notmuch help search-terms\" for details of the search\n"
\r
278 + "\t\tterms syntax." },
\r
279 + { "search-messages", notmuch_search_messages_command,
\r
280 + "[options...] <search-terms> [...]",
\r
281 + "\t\tSearch for messages matching the search terms.",
\r
283 "\t\tSupported options for search include:\n"
\r