1 Return-Path: <bremner@tethera.net>
\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 E6CDA429E26
\r
6 for <notmuch@notmuchmail.org>; Sun, 18 Dec 2011 05:15:50 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 A3Tmg-UfTR+I for <notmuch@notmuchmail.org>;
\r
16 Sun, 18 Dec 2011 05:15:49 -0800 (PST)
\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])
\r
18 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 5A65C429E32
\r
21 for <notmuch@notmuchmail.org>; Sun, 18 Dec 2011 05:15:43 -0800 (PST)
\r
22 Received: from zancas.localnet
\r
23 (fctnnbsc36w-156034079193.pppoe-dynamic.High-Speed.nb.bellaliant.net
\r
24 [156.34.79.193]) (authenticated bits=0)
\r
25 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pBIDFdgE017881
\r
26 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);
\r
27 Sun, 18 Dec 2011 09:15:40 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.77)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1RcGaY-0008RS-S1; Sun, 18 Dec 2011 09:15:38 -0400
\r
31 From: David Bremner <david@tethera.net>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH Draft 2 6/9] notmuch-restore: add --format=notmuch support
\r
34 Date: Sun, 18 Dec 2011 09:15:08 -0400
\r
35 Message-Id: <1324214111-32079-7-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.7.3
\r
37 In-Reply-To: <1324214111-32079-1-git-send-email-david@tethera.net>
\r
38 References: <id:87sjkmuck7.fsf@gmail.com>
\r
39 <1324214111-32079-1-git-send-email-david@tethera.net>
\r
40 Cc: David Bremner <bremner@debian.org>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\r
44 List-Id: "Use and development of the notmuch mail system."
\r
45 <notmuch.notmuchmail.org>
\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
49 List-Post: <mailto:notmuch@notmuchmail.org>
\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
53 X-List-Received-Date: Sun, 18 Dec 2011 13:15:51 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 This is format is whitespace separated tokens, encoded by
\r
60 notmuch-restore.c | 81 +++++++++++++++++++++++++++++++++++++++++------------
\r
61 1 files changed, 63 insertions(+), 18 deletions(-)
\r
63 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
64 index 87d9772..f618b47 100644
\r
65 --- a/notmuch-restore.c
\r
66 +++ b/notmuch-restore.c
\r
70 #include "notmuch-client.h"
\r
71 +#include "dump-restore-private.h"
\r
74 notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
75 @@ -35,6 +36,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
79 + int input_format = DUMP_FORMAT_SUP;
\r
81 config = notmuch_config_open (ctx, NULL, NULL);
\r
83 @@ -48,6 +50,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
84 synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
86 notmuch_opt_desc_t options[] = {
\r
87 + FORMAT_DESC (input_format),
\r
88 { NOTMUCH_OPT_POSITION, &input_file_name, 0, 0, 0 },
\r
89 { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
\r
91 @@ -81,33 +84,63 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
92 * non-space characters for the message-id, then one or more
\r
93 * spaces, then a list of space-separated tags as a sequence of
\r
94 * characters within literal '(' and ')'. */
\r
95 - if ( xregcomp (®ex,
\r
96 - "^([^ ]+) \\(([^)]*)\\)$",
\r
98 - INTERNAL_ERROR("compile time constant regex failed.");
\r
99 + if (input_format == DUMP_FORMAT_SUP) {
\r
100 + if ( xregcomp (®ex,
\r
101 + "^([^ ]+) \\(([^)]*)\\)$",
\r
103 + INTERNAL_ERROR("compile time constant regex failed.");
\r
107 + /* These are out here to re-use the buffers with hex_decode */
\r
109 + char *message_id = NULL;
\r
110 + size_t message_id_size = 0;
\r
111 + char *tag = NULL;
\r
112 + size_t tag_size = 0;
\r
114 while ((line_len = getline (&line, &line_size, input)) != -1) {
\r
115 regmatch_t match[3];
\r
116 - char *message_id, *file_tags, *tag, *next;
\r
117 + char *file_tags, *next;
\r
118 notmuch_message_t *message = NULL;
\r
120 notmuch_status_t status;
\r
121 notmuch_tags_t *db_tags;
\r
124 chomp_newline (line);
\r
126 - rerr = xregexec (®ex, line, 3, match, 0);
\r
127 - if (rerr == REG_NOMATCH)
\r
129 - fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",
\r
131 + /* Silently ignore blank lines */
\r
133 + if (line[0] == '\0') {
\r
137 - message_id = xstrndup (line + match[1].rm_so,
\r
138 - match[1].rm_eo - match[1].rm_so);
\r
139 - file_tags = xstrndup (line + match[2].rm_so,
\r
140 - match[2].rm_eo - match[2].rm_so);
\r
141 + if (input_format == DUMP_FORMAT_SUP) {
\r
142 + rerr = xregexec (®ex, line, 3, match, 0);
\r
143 + if (rerr == REG_NOMATCH)
\r
145 + fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",
\r
149 + message_id = talloc_strndup (notmuch, line + match[1].rm_so,
\r
150 + match[1].rm_eo - match[1].rm_so);
\r
151 + file_tags = talloc_strndup (notmuch, line + match[2].rm_so,
\r
152 + match[2].rm_eo - match[2].rm_so);
\r
157 + raw_mid = strsep (&p, " \t");
\r
159 + if (hex_decode (notmuch, raw_mid,
\r
160 + &message_id, &message_id_size) != HEX_SUCCESS)
\r
163 + file_tags = xstrdup (p);
\r
167 status = notmuch_database_find_message (notmuch, message_id, &message);
\r
168 if (status || message == NULL) {
\r
169 @@ -153,7 +186,16 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
173 - tag = strsep (&next, " ");
\r
174 + char *raw_tag = strsep (&next, " ");
\r
176 + if (input_format == DUMP_FORMAT_NOTMUCH) {
\r
177 + if (hex_decode (notmuch, raw_tag,
\r
178 + &tag, &tag_size) != HEX_SUCCESS)
\r
181 + tag = talloc_strdup (notmuch, raw_tag);
\r
186 status = notmuch_message_add_tag (message, tag);
\r
187 @@ -175,11 +217,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
189 notmuch_message_destroy (message);
\r
191 - free (message_id);
\r
192 - free (file_tags);
\r
193 + if (input_format == DUMP_FORMAT_SUP) {
\r
194 + talloc_free (message_id);
\r
195 + talloc_free (file_tags);
\r
199 - regfree (®ex);
\r
200 + if (input_format == DUMP_FORMAT_SUP)
\r
201 + regfree (®ex);
\r