Re: Emacs: Crypto: How to get automatic encryption?
[notmuch-archives.git] / 02 / 5d0905dac026908977a7051323a82e57240aca
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
24 Precedence: list\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
35 \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
38 each message.\r
39 ---\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
46 \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
52  \r
53  emacs: notmuch.elc\r
54  \r
55 -notmuch_client_srcs =          \\r
56 -       notmuch.c               \\r
57 -       notmuch-config.c        \\r
58 -       notmuch-dump.c          \\r
59 -       notmuch-new.c           \\r
60 -       notmuch-reply.c         \\r
61 -       notmuch-restore.c       \\r
62 -       notmuch-search.c        \\r
63 -       notmuch-setup.c         \\r
64 -       notmuch-show.c          \\r
65 -       notmuch-tag.c           \\r
66 -       notmuch-time.c          \\r
67 -       gmime-filter-reply.c    \\r
68 -       query-string.c          \\r
69 +notmuch_client_srcs =                  \\r
70 +       notmuch.c                       \\r
71 +       notmuch-config.c                \\r
72 +       notmuch-dump.c                  \\r
73 +       notmuch-new.c                   \\r
74 +       notmuch-reply.c                 \\r
75 +       notmuch-restore.c               \\r
76 +       notmuch-search.c                \\r
77 +       notmuch-search-messages.c       \\r
78 +       notmuch-setup.c                 \\r
79 +       notmuch-show.c                  \\r
80 +       notmuch-tag.c                   \\r
81 +       notmuch-time.c                  \\r
82 +       gmime-filter-reply.c            \\r
83 +       query-string.c                  \\r
84         show-message.c\r
85  \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
93  \r
94  int\r
95 +notmuch_search_messages_command (void *ctx, int argc, char *argv[]);\r
96 +\r
97 +int\r
98  notmuch_setup_command (void *ctx, int argc, char *argv[]);\r
99  \r
100  int\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
104 --- /dev/null\r
105 +++ b/notmuch-search-messages.c\r
106 @@ -0,0 +1,138 @@\r
107 +/* notmuch - Not much of an email program, (just index and search)\r
108 + *\r
109 + * Copyright © 2009 Carl Worth\r
110 + *\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
115 + *\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
120 + *\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
123 + *\r
124 + * Author: Carl Worth <cworth@cworth.org>\r
125 + */\r
126 +\r
127 +#include "notmuch-client.h"\r
128 +\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
133 +\r
134 +static void\r
135 +do_search_messages (notmuch_query_t *query,\r
136 +                   int first, int max)\r
137 +{\r
138 +    notmuch_messages_t *messages;\r
139 +    notmuch_message_t *message;\r
140 +\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
144 +    {\r
145 +       message = notmuch_messages_get (messages);\r
146 +\r
147 +       printf ("id:%s\n", notmuch_message_get_message_id (message));\r
148 +\r
149 +       notmuch_message_destroy (message);\r
150 +    }\r
151 +}\r
152 +\r
153 +int\r
154 +notmuch_search_messages_command (void *ctx, int argc, char *argv[])\r
155 +{\r
156 +    notmuch_config_t *config;\r
157 +    notmuch_database_t *notmuch;\r
158 +    notmuch_query_t *query;\r
159 +    char *query_str;\r
160 +    int i, first = 0, max = -1;\r
161 +    char *opt, *end;\r
162 +    notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;\r
163 +\r
164 +    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
165 +       if (strcmp (argv[i], "--") == 0) {\r
166 +           i++;\r
167 +           break;\r
168 +       }\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
174 +               return 1;\r
175 +           }\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
181 +               return 1;\r
182 +           }\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
189 +           } else {\r
190 +               fprintf (stderr, "Invalid value for --sort: %s\n", opt);\r
191 +               return 1;\r
192 +           }\r
193 +       } else {\r
194 +           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
195 +           return 1;\r
196 +       }\r
197 +    }\r
198 +\r
199 +    argc -= i;\r
200 +    argv += i;\r
201 +\r
202 +    config = notmuch_config_open (ctx, NULL, NULL);\r
203 +    if (config == NULL)\r
204 +       return 1;\r
205 +\r
206 +    notmuch = notmuch_database_open (notmuch_config_get_database_path (config));\r
207 +    if (notmuch == NULL)\r
208 +       return 1;\r
209 +\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
213 +       return 1;\r
214 +    }\r
215 +    if (*query_str == '\0') {\r
216 +       fprintf (stderr, "Error: notmuch search requires at least one search term.\n");\r
217 +       return 1;\r
218 +    }\r
219 +\r
220 +    query = notmuch_query_create (notmuch, query_str);\r
221 +    if (query == NULL) {\r
222 +       fprintf (stderr, "Out of memory\n");\r
223 +       return 1;\r
224 +    }\r
225 +\r
226 +    notmuch_query_set_sort (query, sort);\r
227 +\r
228 +    if (max < 0 || max > NOTMUCH_SHOW_INITIAL_BURST)\r
229 +    {\r
230 +       do_search_messages (query,\r
231 +                          first, NOTMUCH_SHOW_INITIAL_BURST);\r
232 +\r
233 +       first += NOTMUCH_SHOW_INITIAL_BURST;\r
234 +       if (max > 0)\r
235 +           max -= NOTMUCH_SHOW_INITIAL_BURST;\r
236 +    }\r
237 +\r
238 +    do_search_messages (query, first, max);\r
239 +\r
240 +    notmuch_query_destroy (query);\r
241 +    notmuch_database_close (notmuch);\r
242 +\r
243 +    return 0;\r
244 +}\r
245 diff --git a/notmuch.c b/notmuch.c\r
246 index 14d4865..6440777 100644\r
247 --- a/notmuch.c\r
248 +++ b/notmuch.c\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
258 +      "\n"\r
259 +      "\t\tSupported options for search include:\n"\r
260 +      "\n"\r
261 +      "\t\t--max=<value>\n"\r
262 +      "\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
265 +      "\n"\r
266 +      "\t\t--first=<value>\n"\r
267 +      "\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
270 +      "\n"\r
271 +      "\t\t--sort=(newest-first|oldest-first)\n"\r
272 +      "\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
276 +      "\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
282        "\n"\r
283        "\t\tSupported options for search include:\n"\r
284        "\n"\r
285 -- \r
286 1.6.5.2\r
287 \r