1 Return-Path: <polatel@gmail.com>
\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 74675431FBC
\r
6 for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 05:17:46 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.099 tagged_above=-999 required=5 tests=[AWL=0.881,
\r
12 BAYES_00=-2.599, RCVD_IN_SORBS_WEB=0.619] autolearn=no
\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 9UB43sZg3a4A for <notmuch@notmuchmail.org>;
\r
16 Wed, 13 Jan 2010 05:17:45 -0800 (PST)
\r
17 Received: from mail-fx0-f217.google.com (mail-fx0-f217.google.com
\r
19 by olra.theworths.org (Postfix) with ESMTP id 4FD28431FAE
\r
20 for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 05:17:45 -0800 (PST)
\r
21 Received: by fxm9 with SMTP id 9so20804210fxm.30
\r
22 for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 05:17:44 -0800 (PST)
\r
23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
24 h=domainkey-signature:received:received:sender:from:to:subject:date
\r
25 :message-id:x-mailer:in-reply-to:references:organization;
\r
26 bh=2HggMywjex1jI3NqygpcK8qh0Ptb9EqzPbD7dv/tv60=;
\r
27 b=iGr3g4q+PK9j+9P9Ia+rdrvaYuWAB0oRuHeqZMTuuDjz8qAHpqQeYMoaAz6FXU6hdg
\r
28 2FzByFA/lPX1ISky9XWdHZNQcKpc/huFgyaa78/c46jtxkpW3zNexGN86ukDnLCHU5h1
\r
29 FhUT8oH6OYaFq4hwsLTVzEbJQiX9jgJLIC2mI=
\r
30 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
\r
31 h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to
\r
32 :references:organization;
\r
33 b=Yb9aNRjdvYbveLNqfdeC2/JjAmIovI2pG3l0W2IyfRqM/vSh8mnkM8+YXdFZ7gA/e4
\r
34 QVpJkMoD73U7UZXHZg1r02zDaoKY8pXip61dAMafOKFnxH93RvmHVjpkkX3EzEP0+qt1
\r
35 bKGN63YAfCtjHEoSk3afOi1Q579/RPcwfEYSE=
\r
36 Received: by 10.86.198.9 with SMTP id v9mr5216790fgf.14.1263388664293;
\r
37 Wed, 13 Jan 2010 05:17:44 -0800 (PST)
\r
38 Received: from harikalardiyari ([78.179.54.193])
\r
39 by mx.google.com with ESMTPS id 14sm10796277fxm.7.2010.01.13.05.17.42
\r
40 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
41 Wed, 13 Jan 2010 05:17:43 -0800 (PST)
\r
42 Sender: Ali Polatel <polatel@gmail.com>
\r
43 From: Ali Polatel <alip@exherbo.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Date: Wed, 13 Jan 2010 15:17:41 +0200
\r
47 <a05f7197e759dba8e5f61951eaeeb83823d38a0d.1263388420.git.alip@exherbo.org>
\r
48 X-Mailer: git-send-email 1.6.6
\r
50 <cd1ed7d2c2ea5a9f7da351b5916253708b65feb5.1263377759.git.alip@exherbo.org>
\r
52 <cd1ed7d2c2ea5a9f7da351b5916253708b65feb5.1263377759.git.alip@exherbo.org>
\r
53 Organization: Pink Floyd
\r
54 Subject: [notmuch] [RFC/PATCH v2] Add search-files command
\r
55 X-BeenThere: notmuch@notmuchmail.org
\r
56 X-Mailman-Version: 2.1.13
\r
58 List-Id: "Use and development of the notmuch mail system."
\r
59 <notmuch.notmuchmail.org>
\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
63 List-Post: <mailto:notmuch@notmuchmail.org>
\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
67 X-List-Received-Date: Wed, 13 Jan 2010 13:17:46 -0000
\r
69 This command can be used to integrate notmuch with other MUAs as a
\r
70 searching client. The idea is simple, a simple script could get
\r
71 search-terms as argument and create a "virtual" maildir which has
\r
72 symbolic links to files output by search-files command. This is similar
\r
77 - Respect coding style about long lines
\r
78 - Free config structure on exit
\r
81 Makefile.local | 1 +
\r
82 notmuch-client.h | 3 +
\r
83 notmuch-search-files.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++
\r
84 notmuch.c | 13 ++++++
\r
85 4 files changed, 126 insertions(+), 0 deletions(-)
\r
86 create mode 100644 notmuch-search-files.c
\r
88 diff --git a/Makefile.local b/Makefile.local
\r
89 index 933ff4c..78bc25d 100644
\r
90 --- a/Makefile.local
\r
91 +++ b/Makefile.local
\r
92 @@ -12,6 +12,7 @@ notmuch_client_srcs = \
\r
96 + notmuch-search-files.c \
\r
97 notmuch-search-tags.c \
\r
100 diff --git a/notmuch-client.h b/notmuch-client.h
\r
101 index 77766de..d505d30 100644
\r
102 --- a/notmuch-client.h
\r
103 +++ b/notmuch-client.h
\r
104 @@ -96,6 +96,9 @@ int
\r
105 notmuch_search_command (void *ctx, int argc, char *argv[]);
\r
108 +notmuch_search_files_command (void *ctx, int argc, char *argv[]);
\r
111 notmuch_setup_command (void *ctx, int argc, char *argv[]);
\r
114 diff --git a/notmuch-search-files.c b/notmuch-search-files.c
\r
115 new file mode 100644
\r
116 index 0000000..7b6d14d
\r
118 +++ b/notmuch-search-files.c
\r
120 +/* notmuch - Not much of an email program, (just index and search)
\r
122 + * Copyright © 2010 Ali Polatel
\r
124 + * This program is free software: you can redistribute it and/or modify
\r
125 + * it under the terms of the GNU General Public License as published by
\r
126 + * the Free Software Foundation, either version 3 of the License, or
\r
127 + * (at your option) any later version.
\r
129 + * This program is distributed in the hope that it will be useful,
\r
130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
132 + * GNU General Public License for more details.
\r
134 + * You should have received a copy of the GNU General Public License
\r
135 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
137 + * Author: Ali Polatel <alip@exherbo.org>
\r
140 +#include "notmuch-client.h"
\r
143 +do_search_files (notmuch_query_t *query)
\r
145 + notmuch_message_t *message;
\r
146 + notmuch_messages_t *messages;
\r
148 + for (messages = notmuch_query_search_messages (query);
\r
149 + notmuch_messages_has_more (messages);
\r
150 + notmuch_messages_advance (messages))
\r
152 + message = notmuch_messages_get (messages);
\r
153 + printf ("%s\n", notmuch_message_get_filename (message));
\r
154 + notmuch_message_destroy(message);
\r
159 +notmuch_search_files_command (void *ctx, int argc, char *argv[])
\r
161 + notmuch_config_t *config;
\r
162 + notmuch_database_t *notmuch;
\r
163 + notmuch_query_t *query;
\r
166 + notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
169 + for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
170 + if (strcmp (argv[i], "--") == 0) {
\r
174 + if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {
\r
175 + opt = argv[i] + sizeof ("--sort=") - 1;
\r
176 + if (strcmp (opt, "oldest-first") == 0) {
\r
177 + sort = NOTMUCH_SORT_OLDEST_FIRST;
\r
178 + } else if (strcmp (opt, "newest-first") == 0) {
\r
179 + sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
181 + fprintf (stderr, "Invalid value for --sort: %s\n", opt);
\r
185 + fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
193 + config = notmuch_config_open (ctx, NULL, NULL);
\r
194 + if (config == NULL)
\r
197 + notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
198 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
199 + if (notmuch == NULL)
\r
202 + query_str = query_string_from_args (ctx, argc, argv);
\r
203 + if (query_str == NULL) {
\r
204 + fprintf (stderr, "Out of memory.\n");
\r
207 + if (*query_str == '\0') {
\r
208 + fprintf (stderr, "Error: notmuch search-files requires"
\r
209 + " at least one search term.\n");
\r
213 + query = notmuch_query_create (notmuch, query_str);
\r
214 + if (query == NULL) {
\r
215 + fprintf (stderr, "Out of memory\n");
\r
219 + notmuch_query_set_sort (query, sort);
\r
221 + do_search_files (query);
\r
223 + notmuch_config_close (config);
\r
224 + notmuch_query_destroy (query);
\r
225 + notmuch_database_close (notmuch);
\r
229 diff --git a/notmuch.c b/notmuch.c
\r
230 index 87479f8..4907339 100644
\r
233 @@ -165,6 +165,19 @@ command_t commands[] = {
\r
235 "\t\tSee \"notmuch help search-terms\" for details of the search\n"
\r
236 "\t\tterms syntax." },
\r
237 + { "search-files", notmuch_search_files_command,
\r
238 + "[options...] <search-terms> [...]",
\r
239 + "\t\tSearch for filenames matching the given search terms.",
\r
240 + "\t\tSupported options for search-files include:\n"
\r
242 + "\t\t--sort=(newest-first|oldest-first)\n"
\r
244 + "\t\t\tPresent results in either chronological order\n"
\r
245 + "\t\t\t(oldest-first) or reverse chronological order\n"
\r
246 + "\t\t\t(newest-first), which is the default.\n"
\r
248 + "\t\tSee \"notmuch help search-terms\" for details of the search\n"
\r
249 + "\t\tterms syntax." },
\r
250 { "show", notmuch_show_command,
\r
251 "<search-terms> [...]",
\r
252 "\t\tShow all messages matching the search terms.",
\r