1 Return-Path: <bremner@pivot.cs.unb.ca>
\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 3E621429E2F
\r
6 for <notmuch@notmuchmail.org>; Tue, 13 Dec 2011 12:28:23 -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 uDlRL4q1CY8F for <notmuch@notmuchmail.org>;
\r
16 Tue, 13 Dec 2011 12:28:21 -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 76D9D429E2E
\r
21 for <notmuch@notmuchmail.org>; Tue, 13 Dec 2011 12:28:18 -0800 (PST)
\r
22 Received: from convex-new.cs.unb.ca ([131.202.13.154])
\r
23 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pBDKSAbw002929;
\r
24 Tue, 13 Dec 2011 16:28:10 -0400
\r
25 Received: from bremner by convex-new.cs.unb.ca with local (Exim 4.72)
\r
26 (envelope-from <bremner@pivot.cs.unb.ca>)
\r
27 id 1RaYxO-0001xT-GU; Tue, 13 Dec 2011 16:28:10 -0400
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [Alpha PATCH 5/6] notmuch-restore: add --format=notmuch support
\r
31 Date: Tue, 13 Dec 2011 16:27:54 -0400
\r
32 Message-Id: <1323808075-7417-6-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 1.7.5.4
\r
34 In-Reply-To: <1323808075-7417-1-git-send-email-david@tethera.net>
\r
35 References: <1323808075-7417-1-git-send-email-david@tethera.net>
\r
36 Cc: David Bremner <bremner@debian.org>, pere@hungry.com
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Tue, 13 Dec 2011 20:28:23 -0000
\r
51 From: David Bremner <bremner@debian.org>
\r
53 This is format is whitespace separated tokens, encoded by
\r
56 notmuch-restore.c | 83 ++++++++++++++++++++++++++++++++++++++++------------
\r
57 1 files changed, 64 insertions(+), 19 deletions(-)
\r
59 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
60 index 87d9772..f392590 100644
\r
61 --- a/notmuch-restore.c
\r
62 +++ b/notmuch-restore.c
\r
66 #include "notmuch-client.h"
\r
67 +#include "dump-restore-private.h"
\r
70 notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
71 @@ -35,6 +36,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
75 + int input_format = DUMP_FORMAT_SUP;
\r
77 config = notmuch_config_open (ctx, NULL, NULL);
\r
79 @@ -48,6 +50,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
80 synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
82 notmuch_opt_desc_t options[] = {
\r
83 + FORMAT_DESC (input_format),
\r
84 { NOTMUCH_OPT_POSITION, &input_file_name, 0, 0, 0 },
\r
85 { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },
\r
87 @@ -81,33 +84,63 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
88 * non-space characters for the message-id, then one or more
\r
89 * spaces, then a list of space-separated tags as a sequence of
\r
90 * characters within literal '(' and ')'. */
\r
91 - if ( xregcomp (®ex,
\r
92 - "^([^ ]+) \\(([^)]*)\\)$",
\r
94 - INTERNAL_ERROR("compile time constant regex failed.");
\r
95 + if (input_format == DUMP_FORMAT_SUP) {
\r
96 + if ( xregcomp (®ex,
\r
97 + "^([^ ]+) \\(([^)]*)\\)$",
\r
99 + INTERNAL_ERROR("compile time constant regex failed.");
\r
103 + /* These are out here to re-use the buffers with hex_decode */
\r
105 + char *message_id = NULL;
\r
106 + size_t message_id_size=0;
\r
107 + char *tag = NULL;
\r
108 + size_t tag_size=0;
\r
110 while ((line_len = getline (&line, &line_size, input)) != -1) {
\r
111 regmatch_t match[3];
\r
112 - char *message_id, *file_tags, *tag, *next;
\r
113 + char *file_tags, *next;
\r
114 notmuch_message_t *message = NULL;
\r
116 notmuch_status_t status;
\r
117 notmuch_tags_t *db_tags;
\r
120 chomp_newline (line);
\r
122 - rerr = xregexec (®ex, line, 3, match, 0);
\r
123 - if (rerr == REG_NOMATCH)
\r
125 - fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",
\r
128 + /* Silently ignore blank lines */
\r
130 + if (line[0] == '\0') {
\r
134 + if (input_format == DUMP_FORMAT_SUP) {
\r
135 + rerr = xregexec (®ex, line, 3, match, 0);
\r
136 + if (rerr == REG_NOMATCH)
\r
138 + fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",
\r
142 + message_id = talloc_strndup (notmuch, line + match[1].rm_so,
\r
143 + match[1].rm_eo - match[1].rm_so);
\r
144 + file_tags = talloc_strndup (notmuch, line + match[2].rm_so,
\r
145 + match[2].rm_eo - match[2].rm_so);
\r
150 + raw_mid = strsep (&p, " \t");
\r
152 + if (hex_decode (notmuch, raw_mid,
\r
153 + &message_id, &message_id_size) != HEX_SUCCESS)
\r
156 + file_tags = xstrdup (p);
\r
159 - message_id = xstrndup (line + match[1].rm_so,
\r
160 - match[1].rm_eo - match[1].rm_so);
\r
161 - file_tags = xstrndup (line + match[2].rm_so,
\r
162 - match[2].rm_eo - match[2].rm_so);
\r
164 status = notmuch_database_find_message (notmuch, message_id, &message);
\r
165 if (status || message == NULL) {
\r
166 @@ -153,7 +186,16 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
170 - tag = strsep (&next, " ");
\r
171 + char *raw_tag = strsep (&next, " ");
\r
173 + if (input_format == DUMP_FORMAT_NOTMUCH) {
\r
174 + if (hex_decode (notmuch, raw_tag,
\r
175 + &tag, &tag_size) != HEX_SUCCESS)
\r
178 + tag = talloc_strdup(notmuch, raw_tag);
\r
183 status = notmuch_message_add_tag (message, tag);
\r
184 @@ -175,11 +217,14 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
186 notmuch_message_destroy (message);
\r
188 - free (message_id);
\r
189 - free (file_tags);
\r
190 + if (input_format == DUMP_FORMAT_SUP) {
\r
191 + talloc_free (message_id);
\r
192 + talloc_free (file_tags);
\r
196 - regfree (®ex);
\r
197 + if (input_format == DUMP_FORMAT_SUP)
\r
198 + regfree (®ex);
\r