[PATCH 1/2] emacs: add function to resend message to new recipients
[notmuch-archives.git] / ab / d1dd00e06314199c2ed213a4210320b2840e6f
1 Return-Path: <jani@nikula.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 C4130429E36\r
6         for <notmuch@notmuchmail.org>; Sun,  3 Mar 2013 13:55:42 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id ywBCbdX2FNZV for <notmuch@notmuchmail.org>;\r
17         Sun,  3 Mar 2013 13:55:35 -0800 (PST)\r
18 Received: from mail-la0-f51.google.com (mail-la0-f51.google.com\r
19         [209.85.215.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id C7C37431FC4\r
22         for <notmuch@notmuchmail.org>; Sun,  3 Mar 2013 13:55:28 -0800 (PST)\r
23 Received: by mail-la0-f51.google.com with SMTP id fo13so4452375lab.38\r
24         for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 13:55:27 -0800 (PST)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
28         :references:in-reply-to:references:x-gm-message-state;\r
29         bh=O+JcirM1yFTlgiq9i/P1lfsmc7YoUJ92yBY8yiKiecg=;\r
30         b=jjmA21zLq2DXcRoKxCTFxgK5ZlmU+ft8SJ16pW23sXm4igeMzarAdgKxDWopKujZaz\r
31         DF9C437ZSc/kjYUIOLCU8hyg3YbxcO/ugseR0Z0txQsFjdzFAXCmqYxGYq3NhewXlIx0\r
32         4Xg9qlxsLQV/c27wXu4NrwGZbsFBNATqdCNYh6cjQCBQ2JXzvq339xvpb5YGd0lX5TGr\r
33         TbWNnguuQWCkn+tm5VXeXlxJe3R+JcoIoZY0EvOwQThqR7wOvYLiaRZ7TEteYALR3IVp\r
34         m0SJAZpvlGLosrrXUQASWle5PW+7r+TJAi+N4fKLjmu8YVsyGLITCvs4Zz/94OKdCfv0\r
35         uW5w==\r
36 X-Received: by 10.112.23.232 with SMTP id p8mr3714912lbf.38.1362347727087;\r
37         Sun, 03 Mar 2013 13:55:27 -0800 (PST)\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
39         [80.223.81.27])\r
40         by mx.google.com with ESMTPS id gm20sm10730463lab.7.2013.03.03.13.55.25\r
41         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
42         Sun, 03 Mar 2013 13:55:26 -0800 (PST)\r
43 From: Jani Nikula <jani@nikula.org>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: [PATCH v2 5/6] cli: move config open/close to main() from subcommands\r
46 Date: Sun,  3 Mar 2013 23:55:09 +0200\r
47 Message-Id:\r
48  <75b8b04e4d63d67ec79ffe2379829add96b37be0.1362347362.git.jani@nikula.org>\r
49 X-Mailer: git-send-email 1.7.10.4\r
50 In-Reply-To: <cover.1362347362.git.jani@nikula.org>\r
51 References: <cover.1362347362.git.jani@nikula.org>\r
52 In-Reply-To: <cover.1362347362.git.jani@nikula.org>\r
53 References: <cover.1362347362.git.jani@nikula.org>\r
54 X-Gm-Message-State:\r
55  ALoCoQlzeLlLN4cbh8oEbSglSr32TjWfYsb8rIhIiVoprRoQPrNb6l1pNlICR64Pi6ZP9lHZW9Ci\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Sun, 03 Mar 2013 21:55:43 -0000\r
69 \r
70 This allows specifying config file as a top level argument to notmuch,\r
71 and generally makes it possible to override config file options in\r
72 main(), without having to touch the subcommands.\r
73 \r
74 If the config file does not exist, one will be created for the notmuch\r
75 main command and setup and help subcommands. Help is special in this\r
76 regard; the config is created just to avoid errors about missing\r
77 config, but it will not be saved.\r
78 \r
79 This also makes notmuch config the talloc context for subcommands.\r
80 ---\r
81  notmuch-client.h  |   30 +++++++++++---------------\r
82  notmuch-config.c  |   40 +++++++----------------------------\r
83  notmuch-count.c   |   11 +++-------\r
84  notmuch-dump.c    |    7 +-----\r
85  notmuch-new.c     |   17 ++++++---------\r
86  notmuch-reply.c   |   15 +++++--------\r
87  notmuch-restore.c |   11 +++-------\r
88  notmuch-search.c  |   15 +++++--------\r
89  notmuch-setup.c   |   17 ++++++---------\r
90  notmuch-show.c    |   15 +++++--------\r
91  notmuch-tag.c     |   15 +++++--------\r
92  notmuch.c         |   61 +++++++++++++++++++++++++++--------------------------\r
93  12 files changed, 91 insertions(+), 163 deletions(-)\r
94 \r
95 diff --git a/notmuch-client.h b/notmuch-client.h\r
96 index b3dcb21..45749a6 100644\r
97 --- a/notmuch-client.h\r
98 +++ b/notmuch-client.h\r
99 @@ -150,6 +150,8 @@ chomp_newline (char *str)\r
100   */\r
101  extern int notmuch_format_version;\r
102  \r
103 +typedef struct _notmuch_config notmuch_config_t;\r
104 +\r
105  /* Commands that support structured output should support the\r
106   * following argument\r
107   *  { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 }\r
108 @@ -169,40 +171,34 @@ int\r
109  notmuch_crypto_cleanup (notmuch_crypto_t *crypto);\r
110  \r
111  int\r
112 -notmuch_count_command (void *ctx, int argc, char *argv[]);\r
113 -\r
114 -int\r
115 -notmuch_dump_command (void *ctx, int argc, char *argv[]);\r
116 +notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);\r
117  \r
118  int\r
119 -notmuch_new_command (void *ctx, int argc, char *argv[]);\r
120 +notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]);\r
121  \r
122  int\r
123 -notmuch_reply_command (void *ctx, int argc, char *argv[]);\r
124 +notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]);\r
125  \r
126  int\r
127 -notmuch_restore_command (void *ctx, int argc, char *argv[]);\r
128 +notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]);\r
129  \r
130  int\r
131 -notmuch_search_command (void *ctx, int argc, char *argv[]);\r
132 +notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]);\r
133  \r
134  int\r
135 -notmuch_setup_command (void *ctx, int argc, char *argv[]);\r
136 +notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);\r
137  \r
138  int\r
139 -notmuch_show_command (void *ctx, int argc, char *argv[]);\r
140 +notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);\r
141  \r
142  int\r
143 -notmuch_tag_command (void *ctx, int argc, char *argv[]);\r
144 +notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]);\r
145  \r
146  int\r
147 -notmuch_search_tags_command (void *ctx, int argc, char *argv[]);\r
148 +notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]);\r
149  \r
150  int\r
151 -notmuch_cat_command (void *ctx, int argc, char *argv[]);\r
152 -\r
153 -int\r
154 -notmuch_config_command (void *ctx, int argc, char *argv[]);\r
155 +notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]);\r
156  \r
157  const char *\r
158  notmuch_time_relative_date (const void *ctx, time_t then);\r
159 @@ -243,8 +239,6 @@ json_quote_str (const void *ctx, const char *str);\r
160  \r
161  /* notmuch-config.c */\r
162  \r
163 -typedef struct _notmuch_config notmuch_config_t;\r
164 -\r
165  notmuch_config_t *\r
166  notmuch_config_open (void *ctx,\r
167                      const char *filename,\r
168 diff --git a/notmuch-config.c b/notmuch-config.c\r
169 index 247fbe4..48312e3 100644\r
170 --- a/notmuch-config.c\r
171 +++ b/notmuch-config.c\r
172 @@ -705,14 +705,8 @@ _item_split (char *item, char **group, char **key)\r
173  }\r
174  \r
175  static int\r
176 -notmuch_config_command_get (void *ctx, char *item)\r
177 +notmuch_config_command_get (notmuch_config_t *config, char *item)\r
178  {\r
179 -    notmuch_config_t *config;\r
180 -\r
181 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
182 -    if (config == NULL)\r
183 -       return 1;\r
184 -\r
185      if (strcmp(item, "database.path") == 0) {\r
186         printf ("%s\n", notmuch_config_get_database_path (config));\r
187      } else if (strcmp(item, "user.name") == 0) {\r
188 @@ -756,25 +750,17 @@ notmuch_config_command_get (void *ctx, char *item)\r
189         g_strfreev (value);\r
190      }\r
191  \r
192 -    notmuch_config_close (config);\r
193 -\r
194      return 0;\r
195  }\r
196  \r
197  static int\r
198 -notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])\r
199 +notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char *argv[])\r
200  {\r
201 -    notmuch_config_t *config;\r
202      char *group, *key;\r
203 -    int ret;\r
204  \r
205      if (_item_split (item, &group, &key))\r
206         return 1;\r
207  \r
208 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
209 -    if (config == NULL)\r
210 -       return 1;\r
211 -\r
212      /* With only the name of an item, we clear it from the\r
213       * configuration file.\r
214       *\r
215 @@ -795,23 +781,15 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])\r
216         break;\r
217      }\r
218  \r
219 -    ret = notmuch_config_save (config);\r
220 -    notmuch_config_close (config);\r
221 -\r
222 -    return ret;\r
223 +    return notmuch_config_save (config);\r
224  }\r
225  \r
226  static int\r
227 -notmuch_config_command_list (void *ctx)\r
228 +notmuch_config_command_list (notmuch_config_t *config)\r
229  {\r
230 -    notmuch_config_t *config;\r
231      char **groups;\r
232      size_t g, groups_length;\r
233  \r
234 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
235 -    if (config == NULL)\r
236 -       return 1;\r
237 -\r
238      groups = g_key_file_get_groups (config->key_file, &groups_length);\r
239      if (groups == NULL)\r
240         return 1;\r
241 @@ -841,13 +819,11 @@ notmuch_config_command_list (void *ctx)\r
242  \r
243      g_strfreev (groups);\r
244  \r
245 -    notmuch_config_close (config);\r
246 -\r
247      return 0;\r
248  }\r
249  \r
250  int\r
251 -notmuch_config_command (void *ctx, int argc, char *argv[])\r
252 +notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])\r
253  {\r
254      argc--; argv++; /* skip subcommand argument */\r
255  \r
256 @@ -862,16 +838,16 @@ notmuch_config_command (void *ctx, int argc, char *argv[])\r
257                      "one argument.\n");\r
258             return 1;\r
259         }\r
260 -       return notmuch_config_command_get (ctx, argv[1]);\r
261 +       return notmuch_config_command_get (config, argv[1]);\r
262      } else if (strcmp (argv[0], "set") == 0) {\r
263         if (argc < 2) {\r
264             fprintf (stderr, "Error: notmuch config set requires at least "\r
265                      "one argument.\n");\r
266             return 1;\r
267         }\r
268 -       return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);\r
269 +       return notmuch_config_command_set (config, argv[1], argc - 2, argv + 2);\r
270      } else if (strcmp (argv[0], "list") == 0) {\r
271 -       return notmuch_config_command_list (ctx);\r
272 +       return notmuch_config_command_list (config);\r
273      }\r
274  \r
275      fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",\r
276 diff --git a/notmuch-count.c b/notmuch-count.c\r
277 index 61722ed..390794f 100644\r
278 --- a/notmuch-count.c\r
279 +++ b/notmuch-count.c\r
280 @@ -33,9 +33,8 @@ enum {\r
281  };\r
282  \r
283  int\r
284 -notmuch_count_command (void *ctx, int argc, char *argv[])\r
285 +notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
286  {\r
287 -    notmuch_config_t *config;\r
288      notmuch_database_t *notmuch;\r
289      notmuch_query_t *query;\r
290      char *query_str;\r
291 @@ -62,22 +61,18 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
292         return 1;\r
293      }\r
294  \r
295 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
296 -    if (config == NULL)\r
297 -       return 1;\r
298 -\r
299      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
300                                NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
301         return 1;\r
302  \r
303 -    query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
304 +    query_str = query_string_from_args (config, argc-opt_index, argv+opt_index);\r
305      if (query_str == NULL) {\r
306         fprintf (stderr, "Out of memory.\n");\r
307         return 1;\r
308      }\r
309  \r
310      if (*query_str == '\0') {\r
311 -       query_str = talloc_strdup (ctx, "");\r
312 +       query_str = talloc_strdup (config, "");\r
313      }\r
314  \r
315      query = notmuch_query_create (notmuch, query_str);\r
316 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
317 index 845a67e..2024e30 100644\r
318 --- a/notmuch-dump.c\r
319 +++ b/notmuch-dump.c\r
320 @@ -23,9 +23,8 @@\r
321  #include "string-util.h"\r
322  \r
323  int\r
324 -notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
325 +notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
326  {\r
327 -    notmuch_config_t *config;\r
328      notmuch_database_t *notmuch;\r
329      notmuch_query_t *query;\r
330      FILE *output = stdout;\r
331 @@ -34,10 +33,6 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
332      notmuch_tags_t *tags;\r
333      const char *query_str = "";\r
334  \r
335 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
336 -    if (config == NULL)\r
337 -       return 1;\r
338 -\r
339      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
340                                NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
341         return 1;\r
342 diff --git a/notmuch-new.c b/notmuch-new.c\r
343 index 4915418..faa33f1 100644\r
344 --- a/notmuch-new.c\r
345 +++ b/notmuch-new.c\r
346 @@ -840,9 +840,8 @@ _remove_directory (void *ctx,\r
347  }\r
348  \r
349  int\r
350 -notmuch_new_command (void *ctx, int argc, char *argv[])\r
351 +notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
352  {\r
353 -    notmuch_config_t *config;\r
354      notmuch_database_t *notmuch;\r
355      add_files_state_t add_files_state;\r
356      double elapsed;\r
357 @@ -875,10 +874,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
358         return 1;\r
359      }\r
360  \r
361 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
362 -    if (config == NULL)\r
363 -       return 1;\r
364 -\r
365      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
366      add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);\r
367      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
368 @@ -890,7 +885,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
369             return ret;\r
370      }\r
371  \r
372 -    dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
373 +    dot_notmuch_path = talloc_asprintf (config, "%s/%s", db_path, ".notmuch");\r
374  \r
375      if (stat (dot_notmuch_path, &st)) {\r
376         int count;\r
377 @@ -941,9 +936,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
378      add_files_state.removed_messages = add_files_state.renamed_messages = 0;\r
379      gettimeofday (&add_files_state.tv_start, NULL);\r
380  \r
381 -    add_files_state.removed_files = _filename_list_create (ctx);\r
382 -    add_files_state.removed_directories = _filename_list_create (ctx);\r
383 -    add_files_state.directory_mtimes = _filename_list_create (ctx);\r
384 +    add_files_state.removed_files = _filename_list_create (config);\r
385 +    add_files_state.removed_directories = _filename_list_create (config);\r
386 +    add_files_state.directory_mtimes = _filename_list_create (config);\r
387  \r
388      if (! debugger_is_active () && add_files_state.output_is_a_tty\r
389         && ! add_files_state.verbose) {\r
390 @@ -970,7 +965,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
391  \r
392      gettimeofday (&tv_start, NULL);\r
393      for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {\r
394 -       ret = _remove_directory (ctx, notmuch, f->filename, &add_files_state);\r
395 +       ret = _remove_directory (config, notmuch, f->filename, &add_files_state);\r
396         if (ret)\r
397             goto DONE;\r
398         if (do_print_progress) {\r
399 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
400 index 9da42b9..e151f78 100644\r
401 --- a/notmuch-reply.c\r
402 +++ b/notmuch-reply.c\r
403 @@ -702,9 +702,8 @@ enum {\r
404  };\r
405  \r
406  int\r
407 -notmuch_reply_command (void *ctx, int argc, char *argv[])\r
408 +notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
409  {\r
410 -    notmuch_config_t *config;\r
411      notmuch_database_t *notmuch;\r
412      notmuch_query_t *query;\r
413      char *query_string;\r
414 @@ -752,21 +751,17 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
415         reply_format_func = notmuch_reply_format_headers_only;\r
416      } else if (format == FORMAT_JSON) {\r
417         reply_format_func = notmuch_reply_format_sprinter;\r
418 -       sp = sprinter_json_create (ctx, stdout);\r
419 +       sp = sprinter_json_create (config, stdout);\r
420      } else if (format == FORMAT_SEXP) {\r
421         reply_format_func = notmuch_reply_format_sprinter;\r
422 -       sp = sprinter_sexp_create (ctx, stdout);\r
423 +       sp = sprinter_sexp_create (config, stdout);\r
424      } else {\r
425         reply_format_func = notmuch_reply_format_default;\r
426      }\r
427  \r
428      notmuch_exit_if_unsupported_format ();\r
429  \r
430 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
431 -    if (config == NULL)\r
432 -       return 1;\r
433 -\r
434 -    query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
435 +    query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);\r
436      if (query_string == NULL) {\r
437         fprintf (stderr, "Out of memory\n");\r
438         return 1;\r
439 @@ -787,7 +782,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
440         return 1;\r
441      }\r
442  \r
443 -    if (reply_format_func (ctx, config, query, &params, reply_all, sp) != 0)\r
444 +    if (reply_format_func (config, config, query, &params, reply_all, sp) != 0)\r
445         return 1;\r
446  \r
447      notmuch_crypto_cleanup (&params.crypto);\r
448 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
449 index dd2507f..1419621 100644\r
450 --- a/notmuch-restore.c\r
451 +++ b/notmuch-restore.c\r
452 @@ -120,9 +120,8 @@ parse_sup_line (void *ctx, char *line,\r
453  }\r
454  \r
455  int\r
456 -notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
457 +notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
458  {\r
459 -    notmuch_config_t *config;\r
460      notmuch_database_t *notmuch;\r
461      notmuch_bool_t accumulate = FALSE;\r
462      tag_op_flag_t flags = 0;\r
463 @@ -139,10 +138,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
464      int opt_index;\r
465      int input_format = DUMP_FORMAT_AUTO;\r
466  \r
467 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
468 -    if (config == NULL)\r
469 -       return 1;\r
470 -\r
471      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
472                                NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
473         return 1;\r
474 @@ -187,7 +182,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
475         return 1;\r
476      }\r
477  \r
478 -    tag_ops = tag_op_list_create (ctx);\r
479 +    tag_ops = tag_op_list_create (config);\r
480      if (tag_ops == NULL) {\r
481         fprintf (stderr, "Out of memory.\n");\r
482         return 1;\r
483 @@ -226,7 +221,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
484         if (line_ctx != NULL)\r
485             talloc_free (line_ctx);\r
486  \r
487 -       line_ctx = talloc_new (ctx);\r
488 +       line_ctx = talloc_new (config);\r
489         if (input_format == DUMP_FORMAT_SUP) {\r
490             ret = parse_sup_line (line_ctx, line, &query_string, tag_ops);\r
491         } else {\r
492 diff --git a/notmuch-search.c b/notmuch-search.c\r
493 index fac6663..e658639 100644\r
494 --- a/notmuch-search.c\r
495 +++ b/notmuch-search.c\r
496 @@ -290,9 +290,8 @@ enum {\r
497  };\r
498  \r
499  int\r
500 -notmuch_search_command (void *ctx, int argc, char *argv[])\r
501 +notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
502  {\r
503 -    notmuch_config_t *config;\r
504      notmuch_database_t *notmuch;\r
505      notmuch_query_t *query;\r
506      char *query_str;\r
507 @@ -349,20 +348,20 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
508  \r
509      switch (format_sel) {\r
510      case NOTMUCH_FORMAT_TEXT:\r
511 -       format = sprinter_text_create (ctx, stdout);\r
512 +       format = sprinter_text_create (config, stdout);\r
513         break;\r
514      case NOTMUCH_FORMAT_TEXT0:\r
515         if (output == OUTPUT_SUMMARY) {\r
516             fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");\r
517             return 1;\r
518         }\r
519 -       format = sprinter_text0_create (ctx, stdout);\r
520 +       format = sprinter_text0_create (config, stdout);\r
521         break;\r
522      case NOTMUCH_FORMAT_JSON:\r
523 -       format = sprinter_json_create (ctx, stdout);\r
524 +       format = sprinter_json_create (config, stdout);\r
525         break;\r
526      case NOTMUCH_FORMAT_SEXP:\r
527 -       format = sprinter_sexp_create (ctx, stdout);\r
528 +       format = sprinter_sexp_create (config, stdout);\r
529         break;\r
530      default:\r
531         /* this should never happen */\r
532 @@ -371,10 +370,6 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
533  \r
534      notmuch_exit_if_unsupported_format ();\r
535  \r
536 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
537 -    if (config == NULL)\r
538 -       return 1;\r
539 -\r
540      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
541                                NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
542         return 1;\r
543 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
544 index 72d862a..475248b 100644\r
545 --- a/notmuch-setup.c\r
546 +++ b/notmuch-setup.c\r
547 @@ -120,12 +120,11 @@ parse_tag_list (void *ctx, char *response)\r
548  }\r
549  \r
550  int\r
551 -notmuch_setup_command (unused (void *ctx),\r
552 +notmuch_setup_command (notmuch_config_t *config,\r
553                        unused (int argc), unused (char *argv[]))\r
554  {\r
555      char *response = NULL;\r
556      size_t response_size = 0;\r
557 -    notmuch_config_t *config;\r
558      const char **old_other_emails;\r
559      size_t old_other_emails_len;\r
560      GPtrArray *other_emails;\r
561 @@ -146,8 +145,6 @@ notmuch_setup_command (unused (void *ctx),\r
562         chomp_newline (response);                               \\r
563      } while (0)\r
564  \r
565 -    config = notmuch_config_open (ctx, NULL, TRUE);\r
566 -\r
567      if (notmuch_config_is_new (config))\r
568         welcome_message_pre_setup ();\r
569  \r
570 @@ -167,16 +164,16 @@ notmuch_setup_command (unused (void *ctx),\r
571      for (i = 0; i < old_other_emails_len; i++) {\r
572         prompt ("Additional email address [%s]: ", old_other_emails[i]);\r
573         if (strlen (response))\r
574 -           g_ptr_array_add (other_emails, talloc_strdup (ctx, response));\r
575 +           g_ptr_array_add (other_emails, talloc_strdup (config, response));\r
576         else\r
577 -           g_ptr_array_add (other_emails, talloc_strdup (ctx,\r
578 +           g_ptr_array_add (other_emails, talloc_strdup (config,\r
579                                                          old_other_emails[i]));\r
580      }\r
581  \r
582      do {\r
583         prompt ("Additional email address [Press 'Enter' if none]: ");\r
584         if (strlen (response))\r
585 -           g_ptr_array_add (other_emails, talloc_strdup (ctx, response));\r
586 +           g_ptr_array_add (other_emails, talloc_strdup (config, response));\r
587      } while (strlen (response));\r
588      if (other_emails->len)\r
589         notmuch_config_set_user_other_email (config,\r
590 @@ -190,7 +187,7 @@ notmuch_setup_command (unused (void *ctx),\r
591      if (strlen (response)) {\r
592         const char *absolute_path;\r
593  \r
594 -       absolute_path = make_path_absolute (ctx, response);\r
595 +       absolute_path = make_path_absolute (config, response);\r
596         notmuch_config_set_database_path (config, absolute_path);\r
597      }\r
598  \r
599 @@ -201,7 +198,7 @@ notmuch_setup_command (unused (void *ctx),\r
600      prompt ("]: ");\r
601  \r
602      if (strlen (response)) {\r
603 -       GPtrArray *tags = parse_tag_list (ctx, response);\r
604 +       GPtrArray *tags = parse_tag_list (config, response);\r
605  \r
606         notmuch_config_set_new_tags (config, (const char **) tags->pdata,\r
607                                      tags->len);\r
608 @@ -217,7 +214,7 @@ notmuch_setup_command (unused (void *ctx),\r
609      prompt ("]: ");\r
610  \r
611      if (strlen (response)) {\r
612 -       GPtrArray *tags = parse_tag_list (ctx, response);\r
613 +       GPtrArray *tags = parse_tag_list (config, response);\r
614  \r
615         notmuch_config_set_search_exclude_tags (config,\r
616                                                 (const char **) tags->pdata,\r
617 diff --git a/notmuch-show.c b/notmuch-show.c\r
618 index 5ae5d7d..c2ec122 100644\r
619 --- a/notmuch-show.c\r
620 +++ b/notmuch-show.c\r
621 @@ -1056,9 +1056,8 @@ enum {\r
622  };\r
623  \r
624  int\r
625 -notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
626 +notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
627  {\r
628 -    notmuch_config_t *config;\r
629      notmuch_database_t *notmuch;\r
630      notmuch_query_t *query;\r
631      char *query_string;\r
632 @@ -1176,11 +1175,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
633      else\r
634         params.entire_thread = FALSE;\r
635  \r
636 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
637 -    if (config == NULL)\r
638 -       return 1;\r
639 -\r
640 -    query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
641 +    query_string = query_string_from_args (config, argc-opt_index, argv+opt_index);\r
642      if (query_string == NULL) {\r
643         fprintf (stderr, "Out of memory\n");\r
644         return 1;\r
645 @@ -1202,11 +1197,11 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
646      }\r
647  \r
648      /* Create structure printer. */\r
649 -    sprinter = format->new_sprinter(ctx, stdout);\r
650 +    sprinter = format->new_sprinter(config, stdout);\r
651  \r
652      /* If a single message is requested we do not use search_excludes. */\r
653      if (params.part >= 0)\r
654 -       ret = do_show_single (ctx, query, format, sprinter, &params);\r
655 +       ret = do_show_single (config, query, format, sprinter, &params);\r
656      else {\r
657         /* We always apply set the exclude flag. The\r
658          * exclude=true|false option controls whether or not we return\r
659 @@ -1225,7 +1220,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
660             params.omit_excluded = FALSE;\r
661         }\r
662  \r
663 -       ret = do_show (ctx, query, format, sprinter, &params);\r
664 +       ret = do_show (config, query, format, sprinter, &params);\r
665      }\r
666  \r
667      notmuch_crypto_cleanup (&params.crypto);\r
668 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
669 index 148e856..0e73197 100644\r
670 --- a/notmuch-tag.c\r
671 +++ b/notmuch-tag.c\r
672 @@ -178,11 +178,10 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,\r
673  }\r
674  \r
675  int\r
676 -notmuch_tag_command (void *ctx, int argc, char *argv[])\r
677 +notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
678  {\r
679      tag_op_list_t *tag_ops = NULL;\r
680      char *query_string = NULL;\r
681 -    notmuch_config_t *config;\r
682      notmuch_database_t *notmuch;\r
683      struct sigaction action;\r
684      tag_op_flag_t tag_flags = TAG_FLAG_NONE;\r
685 @@ -225,21 +224,17 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
686             return 1;\r
687         }\r
688      } else {\r
689 -       tag_ops = tag_op_list_create (ctx);\r
690 +       tag_ops = tag_op_list_create (config);\r
691         if (tag_ops == NULL) {\r
692             fprintf (stderr, "Out of memory.\n");\r
693             return 1;\r
694         }\r
695  \r
696 -       if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,\r
697 +       if (parse_tag_command_line (config, argc - opt_index, argv + opt_index,\r
698                                     &query_string, tag_ops))\r
699             return 1;\r
700      }\r
701  \r
702 -    config = notmuch_config_open (ctx, NULL, FALSE);\r
703 -    if (config == NULL)\r
704 -       return 1;\r
705 -\r
706      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
707                                NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
708         return 1;\r
709 @@ -248,9 +243,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
710         tag_flags |= TAG_FLAG_MAILDIR_SYNC;\r
711  \r
712      if (batch)\r
713 -       ret = tag_file (ctx, notmuch, tag_flags, input);\r
714 +       ret = tag_file (config, notmuch, tag_flags, input);\r
715      else\r
716 -       ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);\r
717 +       ret = tag_query (config, notmuch, query_string, tag_ops, tag_flags);\r
718  \r
719      notmuch_database_destroy (notmuch);\r
720  \r
721 diff --git a/notmuch.c b/notmuch.c\r
722 index e434d03..3241e23 100644\r
723 --- a/notmuch.c\r
724 +++ b/notmuch.c\r
725 @@ -22,56 +22,57 @@\r
726  \r
727  #include "notmuch-client.h"\r
728  \r
729 -typedef int (*command_function_t) (void *ctx, int argc, char *argv[]);\r
730 +typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]);\r
731  \r
732  typedef struct command {\r
733      const char *name;\r
734      command_function_t function;\r
735 +    notmuch_bool_t create_config;\r
736      const char *arguments;\r
737      const char *summary;\r
738  } command_t;\r
739  \r
740  static int\r
741 -notmuch_help_command (void *ctx, int argc, char *argv[]);\r
742 +notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]);\r
743  \r
744  static int\r
745 -notmuch_command (void *ctx, int argc, char *argv[]);\r
746 +notmuch_command (notmuch_config_t *config, int argc, char *argv[]);\r
747  \r
748  static command_t commands[] = {\r
749 -    { NULL, notmuch_command,\r
750 +    { NULL, notmuch_command, TRUE,\r
751        NULL,\r
752        "Notmuch main command." },\r
753 -    { "setup", notmuch_setup_command,\r
754 +    { "setup", notmuch_setup_command, TRUE,\r
755        NULL,\r
756        "Interactively setup notmuch for first use." },\r
757 -    { "new", notmuch_new_command,\r
758 +    { "new", notmuch_new_command, FALSE,\r
759        "[options...]",\r
760        "Find and import new messages to the notmuch database." },\r
761 -    { "search", notmuch_search_command,\r
762 +    { "search", notmuch_search_command, FALSE,\r
763        "[options...] <search-terms> [...]",\r
764        "Search for messages matching the given search terms." },\r
765 -    { "show", notmuch_show_command,\r
766 +    { "show", notmuch_show_command, FALSE,\r
767        "<search-terms> [...]",\r
768        "Show all messages matching the search terms." },\r
769 -    { "count", notmuch_count_command,\r
770 +    { "count", notmuch_count_command, FALSE,\r
771        "[options...] <search-terms> [...]",\r
772        "Count messages matching the search terms." },\r
773 -    { "reply", notmuch_reply_command,\r
774 +    { "reply", notmuch_reply_command, FALSE,\r
775        "[options...] <search-terms> [...]",\r
776        "Construct a reply template for a set of messages." },\r
777 -    { "tag", notmuch_tag_command,\r
778 +    { "tag", notmuch_tag_command, FALSE,\r
779        "+<tag>|-<tag> [...] [--] <search-terms> [...]" ,\r
780        "Add/remove tags for all messages matching the search terms." },\r
781 -    { "dump", notmuch_dump_command,\r
782 +    { "dump", notmuch_dump_command, FALSE,\r
783        "[<filename>] [--] [<search-terms>]",\r
784        "Create a plain-text dump of the tags for each message." },\r
785 -    { "restore", notmuch_restore_command,\r
786 +    { "restore", notmuch_restore_command, FALSE,\r
787        "[--accumulate] [<filename>]",\r
788        "Restore the tags from the given dump file (see 'dump')." },\r
789 -    { "config", notmuch_config_command,\r
790 +    { "config", notmuch_config_command, FALSE,\r
791        "[get|set] <section>.<item> [value ...]",\r
792        "Get or set settings in the notmuch configuration file." },\r
793 -    { "help", notmuch_help_command,\r
794 +    { "help", notmuch_help_command, TRUE, /* create but don't save config */\r
795        "[<command>]",\r
796        "This message, or more detailed help for the named command." }\r
797  };\r
798 @@ -155,7 +156,7 @@ exec_man (const char *page)\r
799  }\r
800  \r
801  static int\r
802 -notmuch_help_command (void *ctx, int argc, char *argv[])\r
803 +notmuch_help_command (notmuch_config_t *config, int argc, char *argv[])\r
804  {\r
805      command_t *command;\r
806  \r
807 @@ -178,7 +179,7 @@ notmuch_help_command (void *ctx, int argc, char *argv[])\r
808  \r
809      command = find_command (argv[0]);\r
810      if (command) {\r
811 -       char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);\r
812 +       char *page = talloc_asprintf (config, "notmuch-%s", command->name);\r
813         exec_man (page);\r
814      }\r
815  \r
816 @@ -199,28 +200,23 @@ notmuch_help_command (void *ctx, int argc, char *argv[])\r
817   * to be more clever about this in the future.\r
818   */\r
819  static int\r
820 -notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))\r
821 +notmuch_command (notmuch_config_t *config,\r
822 +                unused(int argc), unused(char *argv[]))\r
823  {\r
824 -    notmuch_config_t *config;\r
825      char *db_path;\r
826      struct stat st;\r
827  \r
828 -    config = notmuch_config_open (ctx, NULL, TRUE);\r
829 -\r
830      /* If the user has never configured notmuch, then run\r
831       * notmuch_setup_command which will give a nice welcome message,\r
832       * and interactively guide the user through the configuration. */\r
833 -    if (notmuch_config_is_new (config)) {\r
834 -       notmuch_config_close (config);\r
835 -       return notmuch_setup_command (ctx, 0, NULL);\r
836 -    }\r
837 +    if (notmuch_config_is_new (config))\r
838 +       return notmuch_setup_command (config, 0, NULL);\r
839  \r
840      /* Notmuch is already configured, but is there a database? */\r
841 -    db_path = talloc_asprintf (ctx, "%s/%s",\r
842 +    db_path = talloc_asprintf (config, "%s/%s",\r
843                                notmuch_config_get_database_path (config),\r
844                                ".notmuch");\r
845      if (stat (db_path, &st)) {\r
846 -       notmuch_config_close (config);\r
847         if (errno != ENOENT) {\r
848             fprintf (stderr, "Error looking for notmuch database at %s: %s\n",\r
849                      db_path, strerror (errno));\r
850 @@ -252,8 +248,6 @@ notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))\r
851             notmuch_config_get_user_name (config),\r
852             notmuch_config_get_user_primary_email (config));\r
853  \r
854 -    notmuch_config_close (config);\r
855 -\r
856      return 0;\r
857  }\r
858  \r
859 @@ -264,6 +258,7 @@ main (int argc, char *argv[])\r
860      char *talloc_report;\r
861      const char *command_name = NULL;\r
862      command_t *command;\r
863 +    notmuch_config_t *config;\r
864      notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
865      int opt_index;\r
866      int ret = 0;\r
867 @@ -308,7 +303,13 @@ main (int argc, char *argv[])\r
868         return 1;\r
869      }\r
870  \r
871 -    ret = (command->function)(local, argc - opt_index, argv + opt_index);\r
872 +    config = notmuch_config_open (local, NULL, command->create_config);\r
873 +    if (!config)\r
874 +       return 1;\r
875 +\r
876 +    ret = (command->function)(config, argc - opt_index, argv + opt_index);\r
877 +\r
878 +    notmuch_config_close (config);\r
879  \r
880      talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");\r
881      if (talloc_report && strcmp (talloc_report, "") != 0) {\r
882 -- \r
883 1.7.10.4\r
884 \r