Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / b3 / 279108da2d8e76c52c53e8a1cde07a040b2bf1
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.363\r
10 X-Spam-Level: *\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
34 MIME-Version: 1.0\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
38 Precedence: list\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
49 \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
56 \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
60 \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
63 ---\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
69 \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
78 -                  output_t output)\r
79 +                  output_t output,\r
80 +                  int initial_thread,\r
81 +                  int last_thread)\r
82  {\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
86  \r
87      fputs (format->results_start, stdout);\r
88  \r
89 +    last_thread -= initial_thread;\r
90 +\r
91 +    for (;\r
92 +        initial_thread > 0 && notmuch_threads_valid (threads);\r
93 +        notmuch_threads_move_to_next (threads))\r
94 +       initial_thread--;\r
95 +\r
96      for (;\r
97 -        notmuch_threads_valid (threads);\r
98 +        last_thread != 0 && notmuch_threads_valid (threads);\r
99          notmuch_threads_move_to_next (threads))\r
100      {\r
101         int first_tag = 1;\r
102 @@ -258,6 +267,7 @@ do_search_threads (const search_format_t *format,\r
103         first_thread = 0;\r
104  \r
105         notmuch_thread_destroy (thread);\r
106 +       last_thread--;\r
107      }\r
108  \r
109      if (first_thread)\r
110 @@ -271,7 +281,9 @@ do_search_threads (const search_format_t *format,\r
111  static int\r
112  do_search_messages (const search_format_t *format,\r
113                     notmuch_query_t *query,\r
114 -                   output_t output)\r
115 +                   output_t output,\r
116 +                   int initial_message,\r
117 +                   int last_message)\r
118  {\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
122  \r
123      fputs (format->results_start, stdout);\r
124  \r
125 +    last_message -= initial_message;\r
126 +\r
127 +    for (;\r
128 +        initial_message > 0 && notmuch_messages_valid (messages);       \r
129 +        notmuch_messages_move_to_next (messages))\r
130 +       initial_message--;\r
131 +\r
132      for (;\r
133 -        notmuch_messages_valid (messages);\r
134 +        last_message != 0 && notmuch_messages_valid (messages);         \r
135          notmuch_messages_move_to_next (messages))\r
136      {\r
137         message = notmuch_messages_get (messages);\r
138 @@ -318,6 +337,7 @@ do_search_messages (const search_format_t *format,\r
139         }\r
140  \r
141         notmuch_message_destroy (message);\r
142 +       last_message--;\r
143      }\r
144  \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
148      int i, ret;\r
149      output_t output = OUTPUT_SUMMARY;\r
150 +    int initial_index = 0;\r
151 +    int last_index = -1;\r
152  \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
157                 return 1;\r
158             }\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
164 +               return 1;\r
165 +           }\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
173      default:\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
178         break;\r
179      case OUTPUT_MESSAGES:\r
180      case OUTPUT_FILES:\r
181 -       ret = do_search_messages (format, query, output);\r
182 +       ret = do_search_messages (format, query, output, initial_index, last_index);\r
183         break;\r
184      case OUTPUT_TAGS:\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
187 +           return 1;\r
188 +       }\r
189         ret = do_search_tags (notmuch, format, query);\r
190         break;\r
191      }\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
203 +        int last_thread)\r
204  {\r
205      notmuch_threads_t *threads;\r
206      notmuch_thread_t *thread;\r
207 @@ -822,9 +824,16 @@ do_show (void *ctx,\r
208  \r
209      fputs (format->message_set_start, stdout);\r
210  \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
218 +    \r
219 +    for (//threads = notmuch_query_search_threads (query)\r
220 +       ;\r
221 +       last_thread !=0 && notmuch_threads_valid (threads);\r
222 +       notmuch_threads_move_to_next (threads))\r
223      {\r
224         thread = notmuch_threads_get (threads);\r
225  \r
226 @@ -842,6 +851,7 @@ do_show (void *ctx,\r
227  \r
228         notmuch_thread_destroy (thread);\r
229  \r
230 +       last_thread--;\r
231      }\r
232  \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
235      int mbox = 0;\r
236      int format_specified = 0;\r
237      int i;\r
238 +    int last_index = -1;\r
239 +    int initial_index = 0;\r
240  \r
241      params.entire_thread = 0;\r
242      params.raw = 0;\r
243 @@ -892,6 +904,16 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
244                 return 1;\r
245             }\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
252 +               return 1;\r
253 +           }\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, &params);\r
263      else\r
264 -       return do_show (ctx, query, format, &params);\r
265 +       return do_show (ctx, query, format, &params, initial_index, last_index);\r
266  \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
271 --- a/notmuch.1\r
272 +++ b/notmuch.1\r
273 @@ -153,6 +153,22 @@ Presents the results in either JSON or plain-text (default).\r
274  \r
275  .RS 4\r
276  .TP 4\r
277 +.B \-\-initial-thread=N\r
278 +\r
279 +Starts presenting results with the Nth result.  This option does not\r
280 +apply if output=tags.\r
281 +.RE\r
282 +\r
283 +.RS 4\r
284 +.TP 4\r
285 +.B \-\-last-thread=N\r
286 +\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
289 +.RE\r
290 +\r
291 +.RS 4\r
292 +.TP 4\r
293  .B \-\-output=(summary|threads|messages|files|tags)\r
294  \r
295  .RS 4\r
296 @@ -313,6 +329,22 @@ message.\r
297  \r
298  .RS 4\r
299  .TP 4\r
300 +.B \-\-initial-thread=N\r
301 +\r
302 +Starts presenting results with the Nth result.  This option does not\r
303 +apply if output=tags.\r
304 +.RE\r
305 +\r
306 +.RS 4\r
307 +.TP 4\r
308 +.B \-\-last-thread=N\r
309 +\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
312 +.RE\r
313 +\r
314 +.RS 4\r
315 +.TP 4\r
316  .B \-\-part=N\r
317  \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
321 --- a/notmuch.c\r
322 +++ b/notmuch.c\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
326        "\n"\r
327 +      "\t--initial-index=N\n"\r
328 +      "\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
331 +      "\n"\r
332 +      "\t--last-index=N\n"\r
333 +      "\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
337 +      "\n"\r
338        "\t--output=(summary|threads|messages|files|tags)\n"\r
339        "\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
343        "\n"\r
344        "\tSee \"notmuch help search-terms\" for details of the search\n"\r
345 -      "\tterms syntax." },\r
346 +      "\tterms syntax." \r
347 +      "\n"},\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
354        "\n"\r
355 +      "\t--last-thread=N\n"\r
356 +      "\n"\r
357 +      "\t\tPresents results up until thread number N.\n"\r
358 +      "\n"\r
359        "\t--part=N\n"\r
360        "\n"\r
361        "\t\tOutput the single decoded MIME part N of a single message.\n"\r
362 -- \r
363 1.7.5.4\r
364 \r