Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 89 / d910c99ac07b6fb00fa5082ac9f5a3a4de362f
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 12673431FD0\r
6         for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 04:31:02 -0700 (PDT)\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 PcPtho5f4EkN for <notmuch@notmuchmail.org>;\r
17         Sat,  1 Nov 2014 04:30:58 -0700 (PDT)\r
18 Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com\r
19         [209.85.212.174]) (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 139FE431FAF\r
22         for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 04:30:57 -0700 (PDT)\r
23 Received: by mail-wi0-f174.google.com with SMTP id d1so3143718wiv.13\r
24         for <notmuch@notmuchmail.org>; Sat, 01 Nov 2014 04:30:57 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=1e100.net; s=20130820;\r
27         h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
28         :references:in-reply-to:references;\r
29         bh=O4cZtjwTJw73+w6zjAZtxUanEcJwLMfRWki4OT6RXSM=;\r
30         b=ckoQsIvTOQ1M5ouJCiL5REbwVk8gsJUQpCIWaxwMoHfSg/C4zBO0VM8I6Es8Dhh+52\r
31         5o+PgFw+X4m4J/QP/RI2jDZMi0WFe7ByE7gmT/abQ/l/YtZ/H44nFVJsXUr3XCBA0xFs\r
32         N06TTTa1QPxR0w2jMhFof1ESZZkU9HQTtR42GcGhN/MpCQpjiqcLrEeLccbogV3nsaWG\r
33         NPB9/QZPs98ULg6tLPPOVhD1YMEVOgrm5TsX5NeyaISNIM2D9Pdcjr9ICHGvguIbwQvA\r
34         o3dPcuPKMUOMo5IMOg3D3UZq84i3HTGOUwcPOiQWmS3T0zNIIn9nTT4vNGjog1tUeKk5\r
35         lx+A==\r
36 X-Gm-Message-State:\r
37  ALoCoQl2hIExmt3awwpeXFUvCEhcS3AT1JOLof2k3+zOBynG1gl+R53rFXij65pZPYvQKMmWWQGL\r
38 X-Received: by 10.181.11.131 with SMTP id ei3mr3422990wid.24.1414841456945;\r
39         Sat, 01 Nov 2014 04:30:56 -0700 (PDT)\r
40 Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi.\r
41         [88.195.109.48])\r
42         by mx.google.com with ESMTPSA id ny6sm1648800wic.22.2014.11.01.04.30.55\r
43         for <multiple recipients>\r
44         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
45         Sat, 01 Nov 2014 04:30:56 -0700 (PDT)\r
46 From: Jani Nikula <jani@nikula.org>\r
47 To: Michal Sojka <sojkam1@fel.cvut.cz>\r
48 Subject: [RFC PATCH 2/2] cli: add notmuch address command\r
49 Date: Sat,  1 Nov 2014 13:30:48 +0200\r
50 Message-Id:\r
51  <1bc05ab764867004fd5b6c79266ffcd0249909cd.1414839970.git.jani@nikula.org>\r
52 X-Mailer: git-send-email 2.1.1\r
53 In-Reply-To: <cover.1414839970.git.jani@nikula.org>\r
54 References: <87egtn2s4z.fsf@steelpick.2x.cz>\r
55         <cover.1414839970.git.jani@nikula.org>\r
56 In-Reply-To: <cover.1414839970.git.jani@nikula.org>\r
57 References: <cover.1414839970.git.jani@nikula.org>\r
58 Cc: notmuch@notmuchmail.org\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Sat, 01 Nov 2014 11:31:02 -0000\r
72 \r
73 ---\r
74  notmuch-client.h |   3 ++\r
75  notmuch-search.c | 128 +++++++++++++++++++++++++++++++++++--------------------\r
76  notmuch.c        |   2 +\r
77  3 files changed, 87 insertions(+), 46 deletions(-)\r
78 \r
79 diff --git a/notmuch-client.h b/notmuch-client.h\r
80 index e1efbe0c8252..5e0d47508c6a 100644\r
81 --- a/notmuch-client.h\r
82 +++ b/notmuch-client.h\r
83 @@ -199,6 +199,9 @@ int\r
84  notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);\r
85  \r
86  int\r
87 +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]);\r
88 +\r
89 +int\r
90  notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);\r
91  \r
92  int\r
93 diff --git a/notmuch-search.c b/notmuch-search.c\r
94 index 671fe4139981..07755f115776 100644\r
95 --- a/notmuch-search.c\r
96 +++ b/notmuch-search.c\r
97 @@ -35,6 +35,7 @@ typedef enum {\r
98  #define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)\r
99  \r
100  typedef struct {\r
101 +    notmuch_bool_t address_command;\r
102      sprinter_t *format;\r
103      notmuch_query_t *query;\r
104      notmuch_sort_t sort;\r
105 @@ -440,17 +441,11 @@ do_search_tags (notmuch_database_t *notmuch,\r
106      return 0;\r
107  }\r
108  \r
109 -int\r
110 -notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
111 +static int\r
112 +_notmuch_search_command (notmuch_config_t *config, int argc, char *argv[],\r
113 +                        search_options_t *opt, notmuch_opt_desc_t *subopts)\r
114  {\r
115      notmuch_database_t *notmuch;\r
116 -    search_options_t opt = {\r
117 -       .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
118 -       .output = 0,\r
119 -       .offset = 0,\r
120 -       .limit = -1, /* unlimited */\r
121 -       .dupe = -1,\r
122 -    };\r
123      char *query_str;\r
124      int opt_index, ret;\r
125      notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;\r
126 @@ -464,7 +459,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
127      } format_sel = NOTMUCH_FORMAT_TEXT;\r
128  \r
129      notmuch_opt_desc_t options[] = {\r
130 -       { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's',\r
131 +       { NOTMUCH_OPT_INHERIT, subopts, NULL, 0, 0 },\r
132 +       { NOTMUCH_OPT_KEYWORD, &opt->sort, "sort", 's',\r
133           (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
134                                   { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
135                                   { 0, 0 } } },\r
136 @@ -475,24 +471,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
137                                   { "text0", NOTMUCH_FORMAT_TEXT0 },\r
138                                   { 0, 0 } } },\r
139         { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
140 -       { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',\r
141 -         (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
142 -                                 { "threads", OUTPUT_THREADS },\r
143 -                                 { "messages", OUTPUT_MESSAGES },\r
144 -                                 { "sender", OUTPUT_SENDER },\r
145 -                                 { "recipients", OUTPUT_RECIPIENTS },\r
146 -                                 { "files", OUTPUT_FILES },\r
147 -                                 { "tags", OUTPUT_TAGS },\r
148 -                                 { 0, 0 } } },\r
149          { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
150            (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },\r
151                                    { "false", NOTMUCH_EXCLUDE_FALSE },\r
152                                    { "flag", NOTMUCH_EXCLUDE_FLAG },\r
153                                    { "all", NOTMUCH_EXCLUDE_ALL },\r
154                                    { 0, 0 } } },\r
155 -       { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 },\r
156 -       { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0  },\r
157 -       { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0  },\r
158 +       { NOTMUCH_OPT_INT, &opt->offset, "offset", 'O', 0 },\r
159 +       { NOTMUCH_OPT_INT, &opt->limit, "limit", 'L', 0  },\r
160 +       { NOTMUCH_OPT_INT, &opt->dupe, "duplicate", 'D', 0  },\r
161         { 0, 0, 0, 0, 0 }\r
162      };\r
163  \r
164 @@ -500,25 +487,25 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
165      if (opt_index < 0)\r
166         return EXIT_FAILURE;\r
167  \r
168 -    if (! opt.output)\r
169 -       opt.output = OUTPUT_SUMMARY;\r
170 +    if (! opt->output)\r
171 +       opt->output = OUTPUT_SUMMARY;\r
172  \r
173      switch (format_sel) {\r
174      case NOTMUCH_FORMAT_TEXT:\r
175 -       opt.format = sprinter_text_create (config, stdout);\r
176 +       opt->format = sprinter_text_create (config, stdout);\r
177         break;\r
178      case NOTMUCH_FORMAT_TEXT0:\r
179 -       if (opt.output == OUTPUT_SUMMARY) {\r
180 +       if (opt->output == OUTPUT_SUMMARY) {\r
181             fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");\r
182             return EXIT_FAILURE;\r
183         }\r
184 -       opt.format = sprinter_text0_create (config, stdout);\r
185 +       opt->format = sprinter_text0_create (config, stdout);\r
186         break;\r
187      case NOTMUCH_FORMAT_JSON:\r
188 -       opt.format = sprinter_json_create (config, stdout);\r
189 +       opt->format = sprinter_json_create (config, stdout);\r
190         break;\r
191      case NOTMUCH_FORMAT_SEXP:\r
192 -       opt.format = sprinter_sexp_create (config, stdout);\r
193 +       opt->format = sprinter_sexp_create (config, stdout);\r
194         break;\r
195      default:\r
196         /* this should never happen */\r
197 @@ -541,15 +528,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
198         return EXIT_FAILURE;\r
199      }\r
200  \r
201 -    opt.query = notmuch_query_create (notmuch, query_str);\r
202 -    if (opt.query == NULL) {\r
203 +    opt->query = notmuch_query_create (notmuch, query_str);\r
204 +    if (opt->query == NULL) {\r
205         fprintf (stderr, "Out of memory\n");\r
206         return EXIT_FAILURE;\r
207      }\r
208  \r
209 -    notmuch_query_set_sort (opt.query, opt.sort);\r
210 +    notmuch_query_set_sort (opt->query, opt->sort);\r
211  \r
212 -    if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {\r
213 +    if (exclude == NOTMUCH_EXCLUDE_FLAG && opt->output != OUTPUT_SUMMARY) {\r
214         /* If we are not doing summary output there is nowhere to\r
215          * print the excluded flag so fall back on including the\r
216          * excluded messages. */\r
217 @@ -564,28 +551,77 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
218         search_exclude_tags = notmuch_config_get_search_exclude_tags\r
219             (config, &search_exclude_tags_length);\r
220         for (i = 0; i < search_exclude_tags_length; i++)\r
221 -           notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]);\r
222 -       notmuch_query_set_omit_excluded (opt.query, exclude);\r
223 +           notmuch_query_add_tag_exclude (opt->query, search_exclude_tags[i]);\r
224 +       notmuch_query_set_omit_excluded (opt->query, exclude);\r
225      }\r
226  \r
227 -    if (opt.output == OUTPUT_SUMMARY ||\r
228 -       opt.output == OUTPUT_THREADS)\r
229 -       ret = do_search_threads (&opt);\r
230 -    else if (opt.output == OUTPUT_MESSAGES ||\r
231 -            opt.output == OUTPUT_FILES ||\r
232 -            (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))\r
233 -       ret = do_search_messages (&opt);\r
234 -    else if (opt.output == OUTPUT_TAGS)\r
235 -       ret = do_search_tags (notmuch, &opt);\r
236 +    if (opt->output == OUTPUT_SUMMARY ||\r
237 +       opt->output == OUTPUT_THREADS)\r
238 +       ret = do_search_threads (opt);\r
239 +    else if (opt->output == OUTPUT_MESSAGES ||\r
240 +            opt->output == OUTPUT_FILES ||\r
241 +            (opt->output & OUTPUT_ADDRESS_FLAGS && !(opt->output & ~OUTPUT_ADDRESS_FLAGS)))\r
242 +       ret = do_search_messages (opt);\r
243 +    else if (opt->output == OUTPUT_TAGS)\r
244 +       ret = do_search_tags (notmuch, opt);\r
245      else {\r
246         fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
247         ret = 1;\r
248      }\r
249  \r
250 -    notmuch_query_destroy (opt.query);\r
251 +    notmuch_query_destroy (opt->query);\r
252      notmuch_database_destroy (notmuch);\r
253  \r
254 -    talloc_free (opt.format);\r
255 +    talloc_free (opt->format);\r
256  \r
257      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
258  }\r
259 +\r
260 +int\r
261 +notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
262 +{\r
263 +    search_options_t opt = {\r
264 +       .address_command = FALSE,\r
265 +       .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
266 +       .output = 0,\r
267 +       .offset = 0,\r
268 +       .limit = -1, /* unlimited */\r
269 +       .dupe = -1,\r
270 +    };\r
271 +\r
272 +    notmuch_opt_desc_t options[] = {\r
273 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',\r
274 +         (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
275 +                                 { "threads", OUTPUT_THREADS },\r
276 +                                 { "messages", OUTPUT_MESSAGES },\r
277 +                                 { "files", OUTPUT_FILES },\r
278 +                                 { "tags", OUTPUT_TAGS },\r
279 +                                 { 0, 0 } } },\r
280 +       { 0, 0, 0, 0, 0 }\r
281 +    };\r
282 +\r
283 +    return _notmuch_search_command (config, argc, argv, &opt, options);\r
284 +}\r
285 +\r
286 +int\r
287 +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
288 +{\r
289 +    search_options_t opt = {\r
290 +       .address_command = TRUE,\r
291 +       .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
292 +       .output = 0,\r
293 +       .offset = 0,\r
294 +       .limit = -1, /* unlimited */\r
295 +       .dupe = -1,\r
296 +    };\r
297 +\r
298 +    notmuch_opt_desc_t options[] = {\r
299 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',\r
300 +         (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER },\r
301 +                                 { "recipients", OUTPUT_RECIPIENTS },\r
302 +                                 { 0, 0 } } },\r
303 +       { 0, 0, 0, 0, 0 }\r
304 +    };\r
305 +\r
306 +    return _notmuch_search_command (config, argc, argv, &opt, options);\r
307 +}\r
308 diff --git a/notmuch.c b/notmuch.c\r
309 index dcda0392a094..0fac0997865e 100644\r
310 --- a/notmuch.c\r
311 +++ b/notmuch.c\r
312 @@ -54,6 +54,8 @@ static command_t commands[] = {\r
313        "Add a new message into the maildir and notmuch database." },\r
314      { "search", notmuch_search_command, FALSE,\r
315        "Search for messages matching the given search terms." },\r
316 +    { "address", notmuch_address_command, FALSE,\r
317 +      "Get addresses from messages matching the given search terms." },\r
318      { "show", notmuch_show_command, FALSE,\r
319        "Show all messages matching the search terms." },\r
320      { "count", notmuch_count_command, FALSE,\r
321 -- \r
322 2.1.1\r
323 \r