Re: maintenance of notmuch ruby bindings
[notmuch-archives.git] / 33 / 407ed0706c5335252db8b792eca13d9b5e0607
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 D6D9C431FBC\r
6         for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 02:24:26 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.601\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.601 tagged_above=-999 required=5 tests=[AWL=1.379,\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 2Ji5myKUjyvr for <notmuch@notmuchmail.org>;\r
16         Wed, 13 Jan 2010 02:24:26 -0800 (PST)\r
17 Received: from mail-fx0-f217.google.com (mail-fx0-f217.google.com\r
18         [209.85.220.217])\r
19         by olra.theworths.org (Postfix) with ESMTP id F2FA5431FAE\r
20         for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 02:24:25 -0800 (PST)\r
21 Received: by fxm9 with SMTP id 9so20655115fxm.30\r
22         for <notmuch@notmuchmail.org>; Wed, 13 Jan 2010 02:24:25 -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:organization;\r
26         bh=ael2cZISmH3AmFN3o8pwRrbpF3oz8wB5dBirFauuZhI=;\r
27         b=MnQsZvt0hxH3JDOxocbtXbLs6BdN0BIXxGrGhxxtMJskDnwBPZH8oFT4l10qN9IoHq\r
28         g8YY141n9/tRbiMfaBMX6RWwgRF3YCnwwtSdjp2yzheDHpvM+v+fNa/o2wnNMCLLwSmy\r
29         uHH+txSzV322yH3bkGdtQ10gYmfm08WnashKw=\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:organization;\r
32         b=wsCphEo6hRuc6IeY/vLX8xg1GTfWNOMF4sd57OK4EQzbA94k00yZNWJJMdOsKWWDTh\r
33         UbutjFn0IbUYSLSGvj+od6dJYZmZ35zYnW5br+sOmc5m/Vuc0Q6ouhExM0/Lh0PIMRWc\r
34         PY/4wneGchqNJhkRJgsZ6cZO5S9DYrkSX1JbQ=\r
35 Received: by 10.87.70.26 with SMTP id x26mr766629fgk.57.1263378264591;\r
36         Wed, 13 Jan 2010 02:24:24 -0800 (PST)\r
37 Received: from harikalardiyari ([78.179.54.193])\r
38         by mx.google.com with ESMTPS id l19sm3526274fgb.3.2010.01.13.02.24.23\r
39         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
40         Wed, 13 Jan 2010 02:24:24 -0800 (PST)\r
41 Sender: Ali Polatel <polatel@gmail.com>\r
42 From: Ali Polatel <alip@exherbo.org>\r
43 To: notmuch@notmuchmail.org\r
44 Date: Wed, 13 Jan 2010 12:24:22 +0200\r
45 Message-Id:\r
46  <cd1ed7d2c2ea5a9f7da351b5916253708b65feb5.1263377759.git.alip@exherbo.org>\r
47 X-Mailer: git-send-email 1.6.6\r
48 Organization: Pink Floyd\r
49 Subject: [notmuch] [RFC/PATCH] Add search-files command\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Wed, 13 Jan 2010 10:24:27 -0000\r
63 \r
64 This command can be used to integrate notmuch with other MUAs as a\r
65 searching client. The idea is simple, a simple script could get\r
66 search-terms as argument and create a "virtual" maildir which has\r
67 symbolic links to files output by search-files command. This is similar\r
68 to nmzmail.\r
69 ---\r
70  Makefile.local         |    1 +\r
71  notmuch-client.h       |    3 +\r
72  notmuch-search-files.c |  107 ++++++++++++++++++++++++++++++++++++++++++++++++\r
73  notmuch.c              |   13 ++++++\r
74  4 files changed, 124 insertions(+), 0 deletions(-)\r
75  create mode 100644 notmuch-search-files.c\r
76 \r
77 diff --git a/Makefile.local b/Makefile.local\r
78 index 933ff4c..78bc25d 100644\r
79 --- a/Makefile.local\r
80 +++ b/Makefile.local\r
81 @@ -12,6 +12,7 @@ notmuch_client_srcs =         \\r
82         notmuch-reply.c         \\r
83         notmuch-restore.c       \\r
84         notmuch-search.c        \\r
85 +       notmuch-search-files.c  \\r
86         notmuch-search-tags.c   \\r
87         notmuch-setup.c         \\r
88         notmuch-show.c          \\r
89 diff --git a/notmuch-client.h b/notmuch-client.h\r
90 index 77766de..d505d30 100644\r
91 --- a/notmuch-client.h\r
92 +++ b/notmuch-client.h\r
93 @@ -96,6 +96,9 @@ int\r
94  notmuch_search_command (void *ctx, int argc, char *argv[]);\r
95  \r
96  int\r
97 +notmuch_search_files_command (void *ctx, int argc, char *argv[]);\r
98 +\r
99 +int\r
100  notmuch_setup_command (void *ctx, int argc, char *argv[]);\r
101  \r
102  int\r
103 diff --git a/notmuch-search-files.c b/notmuch-search-files.c\r
104 new file mode 100644\r
105 index 0000000..b48783a\r
106 --- /dev/null\r
107 +++ b/notmuch-search-files.c\r
108 @@ -0,0 +1,107 @@\r
109 +/* notmuch - Not much of an email program, (just index and search)\r
110 + *\r
111 + * Copyright © 2009 Carl Worth\r
112 + *\r
113 + * This program is free software: you can redistribute it and/or modify\r
114 + * it under the terms of the GNU General Public License as published by\r
115 + * the Free Software Foundation, either version 3 of the License, or\r
116 + * (at your option) any later version.\r
117 + *\r
118 + * This program is distributed in the hope that it will be useful,\r
119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
121 + * GNU General Public License for more details.\r
122 + *\r
123 + * You should have received a copy of the GNU General Public License\r
124 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
125 + *\r
126 + * Author: Ali Polatel <alip@exherbo.org>\r
127 + */\r
128 +\r
129 +#include "notmuch-client.h"\r
130 +\r
131 +static void\r
132 +do_search_files (notmuch_query_t *query)\r
133 +{\r
134 +    notmuch_message_t *message;\r
135 +    notmuch_messages_t *messages;\r
136 +\r
137 +    for (messages = notmuch_query_search_messages (query);\r
138 +        notmuch_messages_has_more (messages);\r
139 +        notmuch_messages_advance (messages))\r
140 +    {\r
141 +       message = notmuch_messages_get (messages);\r
142 +       printf ("%s\n", notmuch_message_get_filename (message));\r
143 +       notmuch_message_destroy(message);\r
144 +    }\r
145 +}\r
146 +\r
147 +int\r
148 +notmuch_search_files_command (void *ctx, int argc, char *argv[])\r
149 +{\r
150 +    notmuch_config_t *config;\r
151 +    notmuch_database_t *notmuch;\r
152 +    notmuch_query_t *query;\r
153 +    char *query_str;\r
154 +    char *opt;\r
155 +    notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;\r
156 +    int i;\r
157 +\r
158 +    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
159 +       if (strcmp (argv[i], "--") == 0) {\r
160 +           i++;\r
161 +           break;\r
162 +       }\r
163 +        if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {\r
164 +           opt = argv[i] + sizeof ("--sort=") - 1;\r
165 +           if (strcmp (opt, "oldest-first") == 0) {\r
166 +               sort = NOTMUCH_SORT_OLDEST_FIRST;\r
167 +           } else if (strcmp (opt, "newest-first") == 0) {\r
168 +               sort = NOTMUCH_SORT_NEWEST_FIRST;\r
169 +           } else {\r
170 +               fprintf (stderr, "Invalid value for --sort: %s\n", opt);\r
171 +               return 1;\r
172 +           }\r
173 +       } else {\r
174 +           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
175 +           return 1;\r
176 +       }\r
177 +    }\r
178 +\r
179 +    argc -= i;\r
180 +    argv += i;\r
181 +\r
182 +    config = notmuch_config_open (ctx, NULL, NULL);\r
183 +    if (config == NULL)\r
184 +       return 1;\r
185 +\r
186 +    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
187 +                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
188 +    if (notmuch == NULL)\r
189 +       return 1;\r
190 +\r
191 +    query_str = query_string_from_args (ctx, argc, argv);\r
192 +    if (query_str == NULL) {\r
193 +       fprintf (stderr, "Out of memory.\n");\r
194 +       return 1;\r
195 +    }\r
196 +    if (*query_str == '\0') {\r
197 +       fprintf (stderr, "Error: notmuch search-files requires at least one search term.\n");\r
198 +       return 1;\r
199 +    }\r
200 +\r
201 +    query = notmuch_query_create (notmuch, query_str);\r
202 +    if (query == NULL) {\r
203 +       fprintf (stderr, "Out of memory\n");\r
204 +       return 1;\r
205 +    }\r
206 +\r
207 +    notmuch_query_set_sort (query, sort);\r
208 +\r
209 +    do_search_files (query);\r
210 +\r
211 +    notmuch_query_destroy (query);\r
212 +    notmuch_database_close (notmuch);\r
213 +\r
214 +    return 0;\r
215 +}\r
216 diff --git a/notmuch.c b/notmuch.c\r
217 index 87479f8..4907339 100644\r
218 --- a/notmuch.c\r
219 +++ b/notmuch.c\r
220 @@ -165,6 +165,19 @@ command_t commands[] = {\r
221        "\n"\r
222        "\t\tSee \"notmuch help search-terms\" for details of the search\n"\r
223        "\t\tterms syntax." },\r
224 +    { "search-files", notmuch_search_files_command,\r
225 +      "[options...] <search-terms> [...]",\r
226 +      "\t\tSearch for filenames matching the given search terms.",\r
227 +      "\t\tSupported options for search-files include:\n"\r
228 +      "\n"\r
229 +      "\t\t--sort=(newest-first|oldest-first)\n"\r
230 +      "\n"\r
231 +      "\t\t\tPresent results in either chronological order\n"\r
232 +      "\t\t\t(oldest-first) or reverse chronological order\n"\r
233 +      "\t\t\t(newest-first), which is the default.\n"\r
234 +      "\n"\r
235 +      "\t\tSee \"notmuch help search-terms\" for details of the search\n"\r
236 +      "\t\tterms syntax." },\r
237      { "show", notmuch_show_command,\r
238        "<search-terms> [...]",\r
239        "\t\tShow all messages matching the search terms.",\r
240 -- \r
241 1.6.6\r
242 \r