Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / c6 / 5ae51dc69009c7555542f33959e4547fe3ace2
1 Return-Path: <sojkam1@fel.cvut.cz>\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 77A45431FD7\r
6         for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 17:50:18 -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: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 HcBMHicGj9ag for <notmuch@notmuchmail.org>;\r
16         Sat,  1 Nov 2014 17:50:13 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8048C431FAF\r
19         for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 17:50:12 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.7])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id E4A9B5CD296\r
22         for <notmuch@notmuchmail.org>; Sun,  2 Nov 2014 01:50:10 +0100 (CET)\r
23 X-Virus-Scanned: IMAP STYX AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
26         port 10044) with ESMTP id jolsYzbIJnZ3 for <notmuch@notmuchmail.org>;\r
27         Sun,  2 Nov 2014 01:50:06 +0100 (CET)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 16D5C5CD288\r
30         for <notmuch@notmuchmail.org>; Sun,  2 Nov 2014 01:50:05 +0100 (CET)\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
32         (envelope-from <sojkam1@fel.cvut.cz>)\r
33         id 1XkjMq-00084n-DY; Sun, 02 Nov 2014 01:50:04 +0100\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH 01/10] cli: search: Rename options to context\r
37 Date: Sun,  2 Nov 2014 01:49:51 +0100\r
38 Message-Id: <1414889400-30977-2-git-send-email-sojkam1@fel.cvut.cz>\r
39 X-Mailer: git-send-email 2.1.1\r
40 In-Reply-To: <1414889400-30977-1-git-send-email-sojkam1@fel.cvut.cz>\r
41 References: <1414889400-30977-1-git-send-email-sojkam1@fel.cvut.cz>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Sun, 02 Nov 2014 00:50:18 -0000\r
55 \r
56 Just text replacement, no other changes.\r
57 ---\r
58  notmuch-search.c | 136 +++++++++++++++++++++++++++----------------------------\r
59  1 file changed, 68 insertions(+), 68 deletions(-)\r
60 \r
61 diff --git a/notmuch-search.c b/notmuch-search.c\r
62 index 671fe41..c354ddc 100644\r
63 --- a/notmuch-search.c\r
64 +++ b/notmuch-search.c\r
65 @@ -42,7 +42,7 @@ typedef struct {\r
66      int offset;\r
67      int limit;\r
68      int dupe;\r
69 -} search_options_t;\r
70 +} search_context_t;\r
71  \r
72  typedef struct {\r
73      const char *name;\r
74 @@ -89,39 +89,39 @@ get_thread_query (notmuch_thread_t *thread,\r
75  }\r
76  \r
77  static int\r
78 -do_search_threads (search_options_t *opt)\r
79 +do_search_threads (search_context_t *ctx)\r
80  {\r
81      notmuch_thread_t *thread;\r
82      notmuch_threads_t *threads;\r
83      notmuch_tags_t *tags;\r
84 -    sprinter_t *format = opt->format;\r
85 +    sprinter_t *format = ctx->format;\r
86      time_t date;\r
87      int i;\r
88  \r
89 -    if (opt->offset < 0) {\r
90 -       opt->offset += notmuch_query_count_threads (opt->query);\r
91 -       if (opt->offset < 0)\r
92 -           opt->offset = 0;\r
93 +    if (ctx->offset < 0) {\r
94 +       ctx->offset += notmuch_query_count_threads (ctx->query);\r
95 +       if (ctx->offset < 0)\r
96 +           ctx->offset = 0;\r
97      }\r
98  \r
99 -    threads = notmuch_query_search_threads (opt->query);\r
100 +    threads = notmuch_query_search_threads (ctx->query);\r
101      if (threads == NULL)\r
102         return 1;\r
103  \r
104      format->begin_list (format);\r
105  \r
106      for (i = 0;\r
107 -        notmuch_threads_valid (threads) && (opt->limit < 0 || i < opt->offset + opt->limit);\r
108 +        notmuch_threads_valid (threads) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);\r
109          notmuch_threads_move_to_next (threads), i++)\r
110      {\r
111         thread = notmuch_threads_get (threads);\r
112  \r
113 -       if (i < opt->offset) {\r
114 +       if (i < ctx->offset) {\r
115             notmuch_thread_destroy (thread);\r
116             continue;\r
117         }\r
118  \r
119 -       if (opt->output == OUTPUT_THREADS) {\r
120 +       if (ctx->output == OUTPUT_THREADS) {\r
121             format->set_prefix (format, "thread");\r
122             format->string (format,\r
123                             notmuch_thread_get_thread_id (thread));\r
124 @@ -138,7 +138,7 @@ do_search_threads (search_options_t *opt)\r
125  \r
126             format->begin_map (format);\r
127  \r
128 -           if (opt->sort == NOTMUCH_SORT_OLDEST_FIRST)\r
129 +           if (ctx->sort == NOTMUCH_SORT_OLDEST_FIRST)\r
130                 date = notmuch_thread_get_oldest_date (thread);\r
131             else\r
132                 date = notmuch_thread_get_newest_date (thread);\r
133 @@ -230,11 +230,11 @@ do_search_threads (search_options_t *opt)\r
134  }\r
135  \r
136  static void\r
137 -print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
138 +print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox)\r
139  {\r
140      const char *name = mailbox->name;\r
141      const char *addr = mailbox->addr;\r
142 -    sprinter_t *format = opt->format;\r
143 +    sprinter_t *format = ctx->format;\r
144      InternetAddress *ia = internet_address_mailbox_new (name, addr);\r
145      char *name_addr;\r
146  \r
147 @@ -263,7 +263,7 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
148  \r
149  /* Print addresses from InternetAddressList.  */\r
150  static void\r
151 -process_address_list (const search_options_t *opt, InternetAddressList *list)\r
152 +process_address_list (const search_context_t *ctx, InternetAddressList *list)\r
153  {\r
154      InternetAddress *address;\r
155      int i;\r
156 @@ -279,7 +279,7 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)\r
157             if (group_list == NULL)\r
158                 continue;\r
159  \r
160 -           process_address_list (opt, group_list);\r
161 +           process_address_list (ctx, group_list);\r
162         } else {\r
163             InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
164             mailbox_t mbx = {\r
165 @@ -287,14 +287,14 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)\r
166                 .addr = internet_address_mailbox_get_addr (mailbox),\r
167             };\r
168  \r
169 -           print_mailbox (opt, &mbx);\r
170 +           print_mailbox (ctx, &mbx);\r
171         }\r
172      }\r
173  }\r
174  \r
175  /* Print addresses from a message header.  */\r
176  static void\r
177 -process_address_header (const search_options_t *opt, const char *value)\r
178 +process_address_header (const search_context_t *ctx, const char *value)\r
179  {\r
180      InternetAddressList *list;\r
181  \r
182 @@ -305,42 +305,42 @@ process_address_header (const search_options_t *opt, const char *value)\r
183      if (list == NULL)\r
184         return;\r
185  \r
186 -    process_address_list (opt, list);\r
187 +    process_address_list (ctx, list);\r
188  \r
189      g_object_unref (list);\r
190  }\r
191  \r
192  static int\r
193 -do_search_messages (search_options_t *opt)\r
194 +do_search_messages (search_context_t *ctx)\r
195  {\r
196      notmuch_message_t *message;\r
197      notmuch_messages_t *messages;\r
198      notmuch_filenames_t *filenames;\r
199 -    sprinter_t *format = opt->format;\r
200 +    sprinter_t *format = ctx->format;\r
201      int i;\r
202  \r
203 -    if (opt->offset < 0) {\r
204 -       opt->offset += notmuch_query_count_messages (opt->query);\r
205 -       if (opt->offset < 0)\r
206 -           opt->offset = 0;\r
207 +    if (ctx->offset < 0) {\r
208 +       ctx->offset += notmuch_query_count_messages (ctx->query);\r
209 +       if (ctx->offset < 0)\r
210 +           ctx->offset = 0;\r
211      }\r
212  \r
213 -    messages = notmuch_query_search_messages (opt->query);\r
214 +    messages = notmuch_query_search_messages (ctx->query);\r
215      if (messages == NULL)\r
216         return 1;\r
217  \r
218      format->begin_list (format);\r
219  \r
220      for (i = 0;\r
221 -        notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);\r
222 +        notmuch_messages_valid (messages) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);\r
223          notmuch_messages_move_to_next (messages), i++)\r
224      {\r
225 -       if (i < opt->offset)\r
226 +       if (i < ctx->offset)\r
227             continue;\r
228  \r
229         message = notmuch_messages_get (messages);\r
230  \r
231 -       if (opt->output == OUTPUT_FILES) {\r
232 +       if (ctx->output == OUTPUT_FILES) {\r
233             int j;\r
234             filenames = notmuch_message_get_filenames (message);\r
235  \r
236 @@ -348,7 +348,7 @@ do_search_messages (search_options_t *opt)\r
237                  notmuch_filenames_valid (filenames);\r
238                  notmuch_filenames_move_to_next (filenames), j++)\r
239             {\r
240 -               if (opt->dupe < 0 || opt->dupe == j) {\r
241 +               if (ctx->dupe < 0 || ctx->dupe == j) {\r
242                     format->string (format, notmuch_filenames_get (filenames));\r
243                     format->separator (format);\r
244                 }\r
245 @@ -356,27 +356,27 @@ do_search_messages (search_options_t *opt)\r
246             \r
247             notmuch_filenames_destroy( filenames );\r
248  \r
249 -       } else if (opt->output == OUTPUT_MESSAGES) {\r
250 +       } else if (ctx->output == OUTPUT_MESSAGES) {\r
251             format->set_prefix (format, "id");\r
252             format->string (format,\r
253                             notmuch_message_get_message_id (message));\r
254             format->separator (format);\r
255         } else {\r
256 -           if (opt->output & OUTPUT_SENDER) {\r
257 +           if (ctx->output & OUTPUT_SENDER) {\r
258                 const char *addrs;\r
259  \r
260                 addrs = notmuch_message_get_header (message, "from");\r
261 -               process_address_header (opt, addrs);\r
262 +               process_address_header (ctx, addrs);\r
263             }\r
264  \r
265 -           if (opt->output & OUTPUT_RECIPIENTS) {\r
266 +           if (ctx->output & OUTPUT_RECIPIENTS) {\r
267                 const char *hdrs[] = { "to", "cc", "bcc" };\r
268                 const char *addrs;\r
269                 size_t j;\r
270  \r
271                 for (j = 0; j < ARRAY_SIZE (hdrs); j++) {\r
272                     addrs = notmuch_message_get_header (message, hdrs[j]);\r
273 -                   process_address_header (opt, addrs);\r
274 +                   process_address_header (ctx, addrs);\r
275                 }\r
276             }\r
277         }\r
278 @@ -393,13 +393,13 @@ do_search_messages (search_options_t *opt)\r
279  \r
280  static int\r
281  do_search_tags (notmuch_database_t *notmuch,\r
282 -               const search_options_t *opt)\r
283 +               const search_context_t *ctx)\r
284  {\r
285      notmuch_messages_t *messages = NULL;\r
286      notmuch_tags_t *tags;\r
287      const char *tag;\r
288 -    sprinter_t *format = opt->format;\r
289 -    notmuch_query_t *query = opt->query;\r
290 +    sprinter_t *format = ctx->format;\r
291 +    notmuch_query_t *query = ctx->query;\r
292  \r
293      /* should the following only special case if no excluded terms\r
294       * specified? */\r
295 @@ -444,7 +444,7 @@ int\r
296  notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
297  {\r
298      notmuch_database_t *notmuch;\r
299 -    search_options_t opt = {\r
300 +    search_context_t ctx = {\r
301         .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
302         .output = 0,\r
303         .offset = 0,\r
304 @@ -464,7 +464,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
305      } format_sel = NOTMUCH_FORMAT_TEXT;\r
306  \r
307      notmuch_opt_desc_t options[] = {\r
308 -       { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's',\r
309 +       { NOTMUCH_OPT_KEYWORD, &ctx.sort, "sort", 's',\r
310           (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
311                                   { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
312                                   { 0, 0 } } },\r
313 @@ -475,7 +475,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
314                                   { "text0", NOTMUCH_FORMAT_TEXT0 },\r
315                                   { 0, 0 } } },\r
316         { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
317 -       { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',\r
318 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx.output, "output", 'o',\r
319           (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
320                                   { "threads", OUTPUT_THREADS },\r
321                                   { "messages", OUTPUT_MESSAGES },\r
322 @@ -490,9 +490,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
323                                    { "flag", NOTMUCH_EXCLUDE_FLAG },\r
324                                    { "all", NOTMUCH_EXCLUDE_ALL },\r
325                                    { 0, 0 } } },\r
326 -       { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 },\r
327 -       { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0  },\r
328 -       { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0  },\r
329 +       { NOTMUCH_OPT_INT, &ctx.offset, "offset", 'O', 0 },\r
330 +       { NOTMUCH_OPT_INT, &ctx.limit, "limit", 'L', 0  },\r
331 +       { NOTMUCH_OPT_INT, &ctx.dupe, "duplicate", 'D', 0  },\r
332         { 0, 0, 0, 0, 0 }\r
333      };\r
334  \r
335 @@ -500,25 +500,25 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
336      if (opt_index < 0)\r
337         return EXIT_FAILURE;\r
338  \r
339 -    if (! opt.output)\r
340 -       opt.output = OUTPUT_SUMMARY;\r
341 +    if (! ctx.output)\r
342 +       ctx.output = OUTPUT_SUMMARY;\r
343  \r
344      switch (format_sel) {\r
345      case NOTMUCH_FORMAT_TEXT:\r
346 -       opt.format = sprinter_text_create (config, stdout);\r
347 +       ctx.format = sprinter_text_create (config, stdout);\r
348         break;\r
349      case NOTMUCH_FORMAT_TEXT0:\r
350 -       if (opt.output == OUTPUT_SUMMARY) {\r
351 +       if (ctx.output == OUTPUT_SUMMARY) {\r
352             fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");\r
353             return EXIT_FAILURE;\r
354         }\r
355 -       opt.format = sprinter_text0_create (config, stdout);\r
356 +       ctx.format = sprinter_text0_create (config, stdout);\r
357         break;\r
358      case NOTMUCH_FORMAT_JSON:\r
359 -       opt.format = sprinter_json_create (config, stdout);\r
360 +       ctx.format = sprinter_json_create (config, stdout);\r
361         break;\r
362      case NOTMUCH_FORMAT_SEXP:\r
363 -       opt.format = sprinter_sexp_create (config, stdout);\r
364 +       ctx.format = sprinter_sexp_create (config, stdout);\r
365         break;\r
366      default:\r
367         /* this should never happen */\r
368 @@ -541,15 +541,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
369         return EXIT_FAILURE;\r
370      }\r
371  \r
372 -    opt.query = notmuch_query_create (notmuch, query_str);\r
373 -    if (opt.query == NULL) {\r
374 +    ctx.query = notmuch_query_create (notmuch, query_str);\r
375 +    if (ctx.query == NULL) {\r
376         fprintf (stderr, "Out of memory\n");\r
377         return EXIT_FAILURE;\r
378      }\r
379  \r
380 -    notmuch_query_set_sort (opt.query, opt.sort);\r
381 +    notmuch_query_set_sort (ctx.query, ctx.sort);\r
382  \r
383 -    if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {\r
384 +    if (exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {\r
385         /* If we are not doing summary output there is nowhere to\r
386          * print the excluded flag so fall back on including the\r
387          * excluded messages. */\r
388 @@ -564,28 +564,28 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
389         search_exclude_tags = notmuch_config_get_search_exclude_tags\r
390             (config, &search_exclude_tags_length);\r
391         for (i = 0; i < search_exclude_tags_length; i++)\r
392 -           notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]);\r
393 -       notmuch_query_set_omit_excluded (opt.query, exclude);\r
394 +           notmuch_query_add_tag_exclude (ctx.query, search_exclude_tags[i]);\r
395 +       notmuch_query_set_omit_excluded (ctx.query, exclude);\r
396      }\r
397  \r
398 -    if (opt.output == OUTPUT_SUMMARY ||\r
399 -       opt.output == OUTPUT_THREADS)\r
400 -       ret = do_search_threads (&opt);\r
401 -    else if (opt.output == OUTPUT_MESSAGES ||\r
402 -            opt.output == OUTPUT_FILES ||\r
403 -            (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))\r
404 -       ret = do_search_messages (&opt);\r
405 -    else if (opt.output == OUTPUT_TAGS)\r
406 -       ret = do_search_tags (notmuch, &opt);\r
407 +    if (ctx.output == OUTPUT_SUMMARY ||\r
408 +       ctx.output == OUTPUT_THREADS)\r
409 +       ret = do_search_threads (&ctx);\r
410 +    else if (ctx.output == OUTPUT_MESSAGES ||\r
411 +            ctx.output == OUTPUT_FILES ||\r
412 +            (ctx.output & OUTPUT_ADDRESS_FLAGS && !(ctx.output & ~OUTPUT_ADDRESS_FLAGS)))\r
413 +       ret = do_search_messages (&ctx);\r
414 +    else if (ctx.output == OUTPUT_TAGS)\r
415 +       ret = do_search_tags (notmuch, &ctx);\r
416      else {\r
417         fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
418         ret = 1;\r
419      }\r
420  \r
421 -    notmuch_query_destroy (opt.query);\r
422 +    notmuch_query_destroy (ctx.query);\r
423      notmuch_database_destroy (notmuch);\r
424  \r
425 -    talloc_free (opt.format);\r
426 +    talloc_free (ctx.format);\r
427  \r
428      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
429  }\r
430 -- \r
431 2.1.1\r
432 \r