1 Return-Path: <james.vasile@opensourcematters.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 8FE18429E25
\r
6 for <notmuch@notmuchmail.org>; Thu, 18 Aug 2011 20:10:03 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=1.363 tagged_above=-999 required=5
\r
12 tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] 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 D0cOAfwT90eA for <notmuch@notmuchmail.org>;
\r
16 Thu, 18 Aug 2011 20:10:02 -0700 (PDT)
\r
17 Received: from hackervisions.org (67-207-143-141.slicehost.net
\r
18 [67.207.143.141]) (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 7D19B431FD0
\r
21 for <notmuch@notmuchmail.org>; Thu, 18 Aug 2011 20:10:02 -0700 (PDT)
\r
22 Received: from ool-4572d87b.dyn.optonline.net ([69.114.216.123]
\r
23 helo=localhost) by hackervisions.org with esmtpsa
\r
24 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from
\r
25 <james.vasile@opensourcematters.org>) id 1QuFTz-0002Yu-JZ for
\r
26 notmuch@notmuchmail.org; Thu, 18 Aug 2011 23:10:55 -0400
\r
27 From: James Vasile <james@hackervisions.org>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [PATCH] Added --initial-index and --last-index to search/show
\r
30 User-Agent: Notmuch/0.6.1-213-ge89ce87 (http://notmuchmail.org) Emacs/23.3.1
\r
31 (x86_64-pc-linux-gnu)
\r
32 Date: Thu, 18 Aug 2011 23:09:54 -0400
\r
33 Message-ID: <8739gyw0zh.fsf@opensourcematters.org>
\r
35 Content-Type: text/plain; charset=us-ascii
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.13
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Fri, 19 Aug 2011 03:10:03 -0000
\r
50 Sometimes you need to ask notmuch for just a few messages, and notmuch
\r
51 supports that with date range options. Date ranges, however, are not
\r
52 sufficient for an application that is paging and just wants message x
\r
53 through y, then x+d through y+d, etc. And if you're sending the json
\r
54 results of a search to a client for rendering, it makes sense to just
\r
55 send the small ranges the client actually wants.
\r
57 This patch implements --initial-index and --last-index as options to
\r
58 search and show. It lets you select the xth through the yth message
\r
59 and receive results that pertain only to those messages.
\r
61 I did not enable this option for results specifying --output=tags
\r
62 since the output of a tag search isn't much data.
\r
64 notmuch-search.c | 48 ++++++++++++++++++++++++++++++++++++++++++------
\r
65 notmuch-show.c | 30 ++++++++++++++++++++++++++----
\r
66 notmuch.1 | 32 ++++++++++++++++++++++++++++++++
\r
67 notmuch.c | 18 +++++++++++++++++-
\r
68 4 files changed, 117 insertions(+), 11 deletions(-)
\r
70 diff --git a/notmuch-search.c b/notmuch-search.c
\r
71 index faccaf7..f7deb4a 100644
\r
72 --- a/notmuch-search.c
\r
73 +++ b/notmuch-search.c
\r
74 @@ -194,7 +194,9 @@ static int
\r
75 do_search_threads (const search_format_t *format,
\r
76 notmuch_query_t *query,
\r
77 notmuch_sort_t sort,
\r
80 + int initial_thread,
\r
83 notmuch_thread_t *thread;
\r
84 notmuch_threads_t *threads;
\r
85 @@ -208,8 +210,15 @@ do_search_threads (const search_format_t *format,
\r
87 fputs (format->results_start, stdout);
\r
89 + last_thread -= initial_thread;
\r
92 + initial_thread > 0 && notmuch_threads_valid (threads);
\r
93 + notmuch_threads_move_to_next (threads))
\r
97 - notmuch_threads_valid (threads);
\r
98 + last_thread != 0 && notmuch_threads_valid (threads);
\r
99 notmuch_threads_move_to_next (threads))
\r
102 @@ -258,6 +267,7 @@ do_search_threads (const search_format_t *format,
\r
105 notmuch_thread_destroy (thread);
\r
110 @@ -271,7 +281,9 @@ do_search_threads (const search_format_t *format,
\r
112 do_search_messages (const search_format_t *format,
\r
113 notmuch_query_t *query,
\r
116 + int initial_message,
\r
117 + int last_message)
\r
119 notmuch_message_t *message;
\r
120 notmuch_messages_t *messages;
\r
121 @@ -284,8 +296,15 @@ do_search_messages (const search_format_t *format,
\r
123 fputs (format->results_start, stdout);
\r
125 + last_message -= initial_message;
\r
128 + initial_message > 0 && notmuch_messages_valid (messages);
\r
129 + notmuch_messages_move_to_next (messages))
\r
130 + initial_message--;
\r
133 - notmuch_messages_valid (messages);
\r
134 + last_message != 0 && notmuch_messages_valid (messages);
\r
135 notmuch_messages_move_to_next (messages))
\r
137 message = notmuch_messages_get (messages);
\r
138 @@ -318,6 +337,7 @@ do_search_messages (const search_format_t *format,
\r
141 notmuch_message_destroy (message);
\r
145 notmuch_messages_destroy (messages);
\r
146 @@ -394,6 +414,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
147 const search_format_t *format = &format_text;
\r
149 output_t output = OUTPUT_SUMMARY;
\r
150 + int initial_index = 0;
\r
151 + int last_index = -1;
\r
153 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
154 if (strcmp (argv[i], "--") == 0) {
\r
155 @@ -420,6 +442,16 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
156 fprintf (stderr, "Invalid value for --format: %s\n", opt);
\r
159 + } else if (STRNCMP_LITERAL (argv[i], "--last-index=") == 0) {
\r
160 + opt = argv[i] + sizeof ("--last-index=") - 1;
\r
161 + last_index = atoi(opt);
\r
162 + if (last_index == 0) {
\r
163 + fprintf (stderr, "Last index set to 0.\n");
\r
166 + } else if (STRNCMP_LITERAL (argv[i], "--initial-index=") == 0) {
\r
167 + opt = argv[i] + sizeof ("--initial-index=") - 1;
\r
168 + initial_index = atoi(opt);
\r
169 } else if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
\r
170 opt = argv[i] + sizeof ("--output=") - 1;
\r
171 if (strcmp (opt, "summary") == 0) {
\r
172 @@ -476,13 +508,17 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
174 case OUTPUT_SUMMARY:
\r
175 case OUTPUT_THREADS:
\r
176 - ret = do_search_threads (format, query, sort, output);
\r
177 + ret = do_search_threads (format, query, sort, output, initial_index, last_index);
\r
179 case OUTPUT_MESSAGES:
\r
181 - ret = do_search_messages (format, query, output);
\r
182 + ret = do_search_messages (format, query, output, initial_index, last_index);
\r
185 + if (initial_index != 0 || last_index != -1) {
\r
186 + fprintf(stderr, "--initial-index and --last-index are not supported for searching tags\n");
\r
189 ret = do_search_tags (notmuch, format, query);
\r
192 diff --git a/notmuch-show.c b/notmuch-show.c
\r
193 index fb74300..097557b 100644
\r
194 --- a/notmuch-show.c
\r
195 +++ b/notmuch-show.c
\r
196 @@ -813,7 +813,9 @@ static int
\r
197 do_show (void *ctx,
\r
198 notmuch_query_t *query,
\r
199 const notmuch_show_format_t *format,
\r
200 - notmuch_show_params_t *params)
\r
201 + notmuch_show_params_t *params,
\r
202 + int initial_thread,
\r
205 notmuch_threads_t *threads;
\r
206 notmuch_thread_t *thread;
\r
207 @@ -822,9 +824,16 @@ do_show (void *ctx,
\r
209 fputs (format->message_set_start, stdout);
\r
211 + last_thread -= initial_thread;
\r
212 for (threads = notmuch_query_search_threads (query);
\r
213 - notmuch_threads_valid (threads);
\r
214 - notmuch_threads_move_to_next (threads))
\r
215 + initial_thread > 0 && notmuch_threads_valid (threads);
\r
216 + notmuch_threads_move_to_next (threads))
\r
217 + initial_thread--;
\r
219 + for (//threads = notmuch_query_search_threads (query)
\r
221 + last_thread !=0 && notmuch_threads_valid (threads);
\r
222 + notmuch_threads_move_to_next (threads))
\r
224 thread = notmuch_threads_get (threads);
\r
226 @@ -842,6 +851,7 @@ do_show (void *ctx,
\r
228 notmuch_thread_destroy (thread);
\r
233 fputs (format->message_set_end, stdout);
\r
234 @@ -862,6 +872,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
236 int format_specified = 0;
\r
238 + int last_index = -1;
\r
239 + int initial_index = 0;
\r
241 params.entire_thread = 0;
\r
243 @@ -892,6 +904,16 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
246 format_specified = 1;
\r
247 + } else if (STRNCMP_LITERAL (argv[i], "--last-index=") == 0) {
\r
248 + opt = argv[i] + sizeof ("--last-index=") - 1;
\r
249 + last_index = atoi(opt);
\r
250 + if (last_index == 0) {
\r
251 + fprintf (stderr, "Last index set to 0.\n");
\r
254 + } else if (STRNCMP_LITERAL (argv[i], "--initial-index=") == 0) {
\r
255 + opt = argv[i] + sizeof ("--initial-index=") - 1;
\r
256 + initial_index = atoi(opt);
\r
257 } else if (STRNCMP_LITERAL (argv[i], "--part=") == 0) {
\r
258 params.part = atoi(argv[i] + sizeof ("--part=") - 1);
\r
259 } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {
\r
260 @@ -961,7 +983,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
261 if (params.part >= 0)
\r
262 return do_show_single (ctx, query, format, ¶ms);
\r
264 - return do_show (ctx, query, format, ¶ms);
\r
265 + return do_show (ctx, query, format, ¶ms, initial_index, last_index);
\r
267 notmuch_query_destroy (query);
\r
268 notmuch_database_close (notmuch);
\r
269 diff --git a/notmuch.1 b/notmuch.1
\r
270 index 5a8c83d..2abc8aa 100644
\r
273 @@ -153,6 +153,22 @@ Presents the results in either JSON or plain-text (default).
\r
277 +.B \-\-initial-thread=N
\r
279 +Starts presenting results with the Nth result. This option does not
\r
280 +apply if output=tags.
\r
285 +.B \-\-last-thread=N
\r
287 +Stops presenting results with the Nth result (counting from 0, not
\r
288 +from the initial index). This option does not apply if output=tags.
\r
293 .B \-\-output=(summary|threads|messages|files|tags)
\r
296 @@ -313,6 +329,22 @@ message.
\r
300 +.B \-\-initial-thread=N
\r
302 +Starts presenting results with the Nth result. This option does not
\r
303 +apply if output=tags.
\r
308 +.B \-\-last-thread=N
\r
310 +Stops presenting results with the Nth result (counting from 0, not
\r
311 +from the initial index). This option does not apply if output=tags.
\r
318 Output the single decoded MIME part N of a single message. The search
\r
319 diff --git a/notmuch.c b/notmuch.c
\r
320 index 3973e35..55f712c 100644
\r
323 @@ -183,6 +183,17 @@ static command_t commands[] = {
\r
324 "\t\tPresents the results in either JSON or\n"
\r
325 "\t\tplain-text (default)\n"
\r
327 + "\t--initial-index=N\n"
\r
329 + "\t\tStarts presenting results from the Nth result. This\n"
\r
330 + "\t\toption does not apply if output=tags.\n"
\r
332 + "\t--last-index=N\n"
\r
334 + "\t\tStops presenting results with the Nth result (counting\n"
\r
335 + "\t\tfrom 0, not from the initial index). This option does\n"
\r
336 + "\t\tnot apply if output=tags.\n"
\r
338 "\t--output=(summary|threads|messages|files|tags)\n"
\r
340 "\t\tsummary (default)\n"
\r
341 @@ -223,7 +234,8 @@ static command_t commands[] = {
\r
342 "\t\t(newest-first), which is the default.\n"
\r
344 "\tSee \"notmuch help search-terms\" for details of the search\n"
\r
345 - "\tterms syntax." },
\r
346 + "\tterms syntax."
\r
348 { "show", notmuch_show_command,
\r
349 "<search-terms> [...]",
\r
350 "Show all messages matching the search terms.",
\r
351 @@ -286,6 +298,10 @@ static command_t commands[] = {
\r
352 "\t\tThe raw format must only be used with search terms matching\n"
\r
353 "\t\tsingle message.\n"
\r
355 + "\t--last-thread=N\n"
\r
357 + "\t\tPresents results up until thread number N.\n"
\r
361 "\t\tOutput the single decoded MIME part N of a single message.\n"
\r