1 Return-Path: <m.walters@qmul.ac.uk>
\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 DAA03431FAF
\r
6 for <notmuch@notmuchmail.org>; Sat, 8 Dec 2012 03:43:15 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5
\r
12 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,
\r
13 NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 LaZc9ZLmDION for <notmuch@notmuchmail.org>;
\r
17 Sat, 8 Dec 2012 03:43:13 -0800 (PST)
\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 4F410431FAE
\r
22 for <notmuch@notmuchmail.org>; Sat, 8 Dec 2012 03:43:13 -0800 (PST)
\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])
\r
24 by mail2.qmul.ac.uk with esmtp (Exim 4.71)
\r
25 (envelope-from <m.walters@qmul.ac.uk>)
\r
26 id 1ThIoE-000750-R4; Sat, 08 Dec 2012 11:43:09 +0000
\r
27 Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)
\r
28 by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)
\r
29 (envelope-from <m.walters@qmul.ac.uk>)
\r
30 id 1ThIoE-0000AT-3L; Sat, 08 Dec 2012 11:43:06 +0000
\r
31 From: Mark Walters <markwalters1009@gmail.com>
\r
32 To: david@tethera.net, notmuch@notmuchmail.org
\r
33 Subject: Re: [Patch v3b 5/9] notmuch-restore: add support for input format
\r
35 In-Reply-To: <1354843607-17980-6-git-send-email-david@tethera.net>
\r
36 References: <1354843607-17980-1-git-send-email-david@tethera.net>
\r
37 <1354843607-17980-6-git-send-email-david@tethera.net>
\r
38 User-Agent: Notmuch/0.14+81~g9730584 (http://notmuchmail.org) Emacs/23.4.1
\r
39 (x86_64-pc-linux-gnu)
\r
40 Date: Sat, 08 Dec 2012 11:43:10 +0000
\r
41 Message-ID: <87wqwsg46p.fsf@qmul.ac.uk>
\r
43 Content-Type: text/plain; charset=us-ascii
\r
44 X-Sender-Host-Address: 93.97.24.31
\r
45 X-QM-SPAM-Info: Sender has good ham record. :)
\r
46 X-QM-Body-MD5: 35178de5bdcb27017b924570bfda7669 (of first 20000 bytes)
\r
47 X-SpamAssassin-Score: -1.8
\r
48 X-SpamAssassin-SpamBar: -
\r
49 X-SpamAssassin-Report: The QM spam filters have analysed this message to
\r
51 spam. We require at least 5.0 points to mark a message as spam.
\r
52 This message scored -1.8 points.
\r
53 Summary of the scoring:
\r
54 * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,
\r
56 * [138.37.6.40 listed in list.dnswl.org]
\r
57 * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
\r
58 provider * (markwalters1009[at]gmail.com)
\r
59 * 0.5 AWL AWL: From: address is in the auto white-list
\r
60 X-QM-Scan-Virus: ClamAV says the message is clean
\r
61 Cc: David Bremner <bremner@debian.org>
\r
62 X-BeenThere: notmuch@notmuchmail.org
\r
63 X-Mailman-Version: 2.1.13
\r
65 List-Id: "Use and development of the notmuch mail system."
\r
66 <notmuch.notmuchmail.org>
\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
70 List-Post: <mailto:notmuch@notmuchmail.org>
\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
73 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
74 X-List-Received-Date: Sat, 08 Dec 2012 11:43:16 -0000
\r
79 Basically LGTM: just one comment below.
\r
81 On Fri, 07 Dec 2012, david@tethera.net wrote:
\r
82 > From: David Bremner <bremner@debian.org>
\r
84 > This can be enabled with the new --format=batch-tag command line
\r
85 > option to "notmuch restore". The input must consist of lines of the
\r
88 > +<tag>|-<tag> [...] [--] id:<msg-id>
\r
90 > Each line is interpreted similarly to "notmuch tag" command line
\r
91 > arguments. The delimiter is one or more spaces ' '. Any characters in
\r
92 > <tag> and <search-terms> MAY be hex encoded with %NN where NN is the
\r
93 > hexadecimal value of the character. Any ' ' and '%' characters in
\r
94 > <tag> and <msg-id> MUST be hex encoded (using %20 and %25,
\r
95 > respectively). Any characters that are not part of <tag> or
\r
96 > <search-terms> MUST NOT be hex encoded.
\r
98 > Leading and trailing space ' ' is ignored. Empty lines and lines
\r
99 > beginning with '#' are ignored.
\r
101 > Commit message mainly stolen from Jani's batch tagging commit, to
\r
104 > notmuch-restore.c | 206 ++++++++++++++++++++++++++++++++++-------------------
\r
105 > 1 file changed, 131 insertions(+), 75 deletions(-)
\r
107 > diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
108 > index f03dcac..ceec2d3 100644
\r
109 > --- a/notmuch-restore.c
\r
110 > +++ b/notmuch-restore.c
\r
111 > @@ -19,18 +19,22 @@
\r
114 > #include "notmuch-client.h"
\r
115 > +#include "dump-restore-private.h"
\r
116 > +#include "tag-util.h"
\r
117 > +#include "string-util.h"
\r
119 > +static volatile sig_atomic_t interrupted;
\r
120 > +static regex_t regex;
\r
123 > -tag_message (notmuch_database_t *notmuch, const char *message_id,
\r
124 > - char *file_tags, notmuch_bool_t remove_all,
\r
125 > - notmuch_bool_t synchronize_flags)
\r
126 > +tag_message (unused (void *ctx),
\r
127 > + notmuch_database_t *notmuch,
\r
128 > + const char *message_id,
\r
129 > + tag_op_list_t *tag_ops,
\r
130 > + tag_op_flag_t flags)
\r
132 > notmuch_status_t status;
\r
133 > - notmuch_tags_t *db_tags;
\r
134 > - char *db_tags_str;
\r
135 > notmuch_message_t *message = NULL;
\r
136 > - const char *tag;
\r
140 > status = notmuch_database_find_message (notmuch, message_id, &message);
\r
141 > @@ -44,55 +48,62 @@ tag_message (notmuch_database_t *notmuch, const char *message_id,
\r
143 > /* In order to detect missing messages, this check/optimization is
\r
144 > * intentionally done *after* first finding the message. */
\r
145 > - if (! remove_all && (file_tags == NULL || *file_tags == '\0'))
\r
148 > - db_tags_str = NULL;
\r
149 > - for (db_tags = notmuch_message_get_tags (message);
\r
150 > - notmuch_tags_valid (db_tags);
\r
151 > - notmuch_tags_move_to_next (db_tags)) {
\r
152 > - tag = notmuch_tags_get (db_tags);
\r
154 > - if (db_tags_str)
\r
155 > - db_tags_str = talloc_asprintf_append (db_tags_str, " %s", tag);
\r
157 > - db_tags_str = talloc_strdup (message, tag);
\r
159 > + if ((flags & TAG_FLAG_REMOVE_ALL) || tag_op_list_size (tag_ops))
\r
160 > + tag_op_list_apply (message, tag_ops, flags);
\r
162 > - if (((file_tags == NULL || *file_tags == '\0') &&
\r
163 > - (db_tags_str == NULL || *db_tags_str == '\0')) ||
\r
164 > - (file_tags && db_tags_str && strcmp (file_tags, db_tags_str) == 0))
\r
166 > + notmuch_message_destroy (message);
\r
168 > - notmuch_message_freeze (message);
\r
172 > - if (remove_all)
\r
173 > - notmuch_message_remove_all_tags (message);
\r
175 > +parse_sup_line (void *ctx, char *line,
\r
176 > + char **query_str, tag_op_list_t *tag_ops)
\r
179 > - next = file_tags;
\r
181 > - tag = strsep (&next, " ");
\r
182 > - if (*tag == '\0')
\r
184 > - status = notmuch_message_add_tag (message, tag);
\r
186 > - fprintf (stderr, "Error applying tag %s to message %s:\n",
\r
187 > - tag, message_id);
\r
188 > - fprintf (stderr, "%s\n", notmuch_status_to_string (status));
\r
191 > + regmatch_t match[3];
\r
192 > + char *file_tags;
\r
195 > + tag_op_list_reset (tag_ops);
\r
197 > + chomp_newline (line);
\r
199 > + /* Silently ignore blank lines */
\r
200 > + if (line[0] == '\0') {
\r
204 > + rerr = xregexec (®ex, line, 3, match, 0);
\r
205 > + if (rerr == REG_NOMATCH) {
\r
206 > + fprintf (stderr, "Warning: Ignoring invalid sup format line: %s\n",
\r
211 > - notmuch_message_thaw (message);
\r
212 > + *query_str = talloc_strndup (ctx, line + match[1].rm_so,
\r
213 > + match[1].rm_eo - match[1].rm_so);
\r
214 > + file_tags = talloc_strndup (ctx, line + match[2].rm_so,
\r
215 > + match[2].rm_eo - match[2].rm_so);
\r
217 > - if (synchronize_flags)
\r
218 > - notmuch_message_tags_to_maildir_flags (message);
\r
219 > + char *tok = file_tags;
\r
220 > + size_t tok_len = 0;
\r
224 > - notmuch_message_destroy (message);
\r
225 > + tag_op_list_reset (tag_ops);
\r
227 > + while ((tok = strtok_len (tok + tok_len, " ", &tok_len)) != NULL) {
\r
229 > + if (*(tok + tok_len) != '\0') {
\r
230 > + *(tok + tok_len) = '\0';
\r
234 > + if (tag_op_list_append (ctx, tag_ops, tok, FALSE))
\r
244 > @@ -100,16 +111,19 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
246 > notmuch_config_t *config;
\r
247 > notmuch_database_t *notmuch;
\r
248 > - notmuch_bool_t synchronize_flags;
\r
249 > notmuch_bool_t accumulate = FALSE;
\r
250 > + tag_op_flag_t flags = 0;
\r
251 > + tag_op_list_t *tag_ops;
\r
253 > char *input_file_name = NULL;
\r
254 > FILE *input = stdin;
\r
255 > char *line = NULL;
\r
256 > size_t line_size;
\r
257 > ssize_t line_len;
\r
263 > + int input_format = DUMP_FORMAT_AUTO;
\r
265 > config = notmuch_config_open (ctx, NULL, NULL);
\r
266 > if (config == NULL)
\r
267 > @@ -119,9 +133,15 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
268 > NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
271 > - synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
272 > + if (notmuch_config_get_maildir_synchronize_flags (config))
\r
273 > + flags |= TAG_FLAG_MAILDIR_SYNC;
\r
275 > notmuch_opt_desc_t options[] = {
\r
276 > + { NOTMUCH_OPT_KEYWORD, &input_format, "format", 'f',
\r
277 > + (notmuch_keyword_t []){ { "auto", DUMP_FORMAT_AUTO },
\r
278 > + { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
279 > + { "sup", DUMP_FORMAT_SUP },
\r
281 > { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
\r
282 > { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
\r
283 > { 0, 0, 0, 0, 0 }
\r
284 > @@ -134,6 +154,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
288 > + if (! accumulate)
\r
289 > + flags |= TAG_FLAG_REMOVE_ALL;
\r
291 > if (input_file_name) {
\r
292 > input = fopen (input_file_name, "r");
\r
293 > if (input == NULL) {
\r
294 > @@ -154,44 +177,77 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
295 > * non-space characters for the message-id, then one or more
\r
296 > * spaces, then a list of space-separated tags as a sequence of
\r
297 > * characters within literal '(' and ')'. */
\r
299 ^^^ shouldn't this comment move to parse_sup_line?
\r
306 > - if ( xregcomp (®ex,
\r
307 > - "^([^ ]+) \\(([^)]*)\\)$",
\r
308 > - REG_EXTENDED) )
\r
309 > - INTERNAL_ERROR ("compile time constant regex failed.");
\r
312 > - while ((line_len = getline (&line, &line_size, input)) != -1) {
\r
313 > - regmatch_t match[3];
\r
314 > - char *message_id, *file_tags;
\r
315 > + line_len = getline (&line, &line_size, input);
\r
316 > + if (line_len == 0)
\r
319 > - chomp_newline (line);
\r
320 > + tag_ops = tag_op_list_create (ctx);
\r
321 > + if (tag_ops == NULL) {
\r
322 > + fprintf (stderr, "Out of memory.\n");
\r
326 > - rerr = xregexec (®ex, line, 3, match, 0);
\r
327 > - if (rerr == REG_NOMATCH) {
\r
328 > - fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",
\r
331 > + for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {
\r
333 > + input_format = DUMP_FORMAT_SUP;
\r
336 > + if (input_format == DUMP_FORMAT_AUTO)
\r
337 > + input_format = DUMP_FORMAT_BATCH_TAG;
\r
339 > + if (input_format == DUMP_FORMAT_SUP)
\r
340 > + if ( xregcomp (®ex,
\r
341 > + "^([^ ]+) \\(([^)]*)\\)$",
\r
342 > + REG_EXTENDED) )
\r
343 > + INTERNAL_ERROR ("compile time constant regex failed.");
\r
346 > + char *query_string;
\r
348 > + if (input_format == DUMP_FORMAT_SUP) {
\r
349 > + ret = parse_sup_line (ctx, line, &query_string, tag_ops);
\r
351 > + ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS,
\r
352 > + &query_string, tag_ops);
\r
354 > + if (ret == 0) {
\r
355 > + if (strncmp ("id:", query_string, 3) != 0) {
\r
356 > + fprintf (stderr, "Unsupported query: %s\n", query_string);
\r
359 > + /* delete id: from front of string; tag_message
\r
360 > + * expects a raw message-id.
\r
362 > + * XXX: Note that query string id:foo and bar will be
\r
363 > + * interpreted as a message id "foo and bar". This
\r
364 > + * should eventually be fixed to give a better error
\r
367 > + query_string = query_string + 3;
\r
371 > - message_id = xstrndup (line + match[1].rm_so,
\r
372 > - match[1].rm_eo - match[1].rm_so);
\r
373 > - file_tags = xstrndup (line + match[2].rm_so,
\r
374 > - match[2].rm_eo - match[2].rm_so);
\r
378 > - tag_message (notmuch, message_id, file_tags, ! accumulate,
\r
379 > - synchronize_flags);
\r
380 > + if (ret < 0 || tag_message (ctx, notmuch, query_string,
\r
381 > + tag_ops, flags))
\r
384 > - free (message_id);
\r
385 > - free (file_tags);
\r
387 > + } while ((line_len = getline (&line, &line_size, input)) != -1);
\r
389 > - regfree (®ex);
\r
390 > + if (input_format == DUMP_FORMAT_SUP)
\r
391 > + regfree (®ex);
\r
396 > notmuch_database_destroy (notmuch);
\r
398 > if (input != stdin)
\r
407 > _______________________________________________
\r
408 > notmuch mailing list
\r
409 > notmuch@notmuchmail.org
\r
410 > http://notmuchmail.org/mailman/listinfo/notmuch
\r