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 8A3B7431FC3
\r
6 for <notmuch@notmuchmail.org>; Sat, 8 Dec 2012 14:57:50 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 pOMLppHPfPn9 for <notmuch@notmuchmail.org>;
\r
16 Sat, 8 Dec 2012 14:57:47 -0800 (PST)
\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])
\r
18 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 2C939431FC2
\r
21 for <notmuch@notmuchmail.org>; Sat, 8 Dec 2012 14:57:42 -0800 (PST)
\r
22 Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([142.167.90.129] helo=zancas.localnet)
\r
24 by tesseract.cs.unb.ca with esmtpsa
\r
25 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)
\r
26 (envelope-from <bremner@tethera.net>)
\r
27 id 1ThTL3-00066d-5N; Sat, 08 Dec 2012 18:57:41 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1ThTKx-0000qP-NI; Sat, 08 Dec 2012 18:57:35 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [Patch v5 01/11] notmuch-dump: add --format=(batch-tag|sup)
\r
34 Date: Sat, 8 Dec 2012 18:56:51 -0400
\r
35 Message-Id: <1355007421-3069-2-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1355007421-3069-1-git-send-email-david@tethera.net>
\r
38 References: <1355007421-3069-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: Sat, 08 Dec 2012 22:57:50 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 sup is the old format, and remains the default, at least until
\r
58 restore is converted to parse this format.
\r
60 Each line of the batch-tag format is modelled on the syntax of notmuch tag:
\r
61 - "notmuch tag" is omitted from the front of the line
\r
62 - The dump format only uses query strings of a single message-id.
\r
63 - Each space seperated tag/message-id is 'hex-encoded' to remove
\r
64 trouble-making characters.
\r
65 - It is permitted (and will be useful) for there to be no tags before
\r
68 In particular this format won't have the same problem with e.g. spaces
\r
69 in message-ids or tags; they will be round-trip-able.
\r
71 dump-restore-private.h | 13 +++++++++++++
\r
72 notmuch-dump.c | 48 ++++++++++++++++++++++++++++++++++++++++++------
\r
73 2 files changed, 55 insertions(+), 6 deletions(-)
\r
74 create mode 100644 dump-restore-private.h
\r
76 diff --git a/dump-restore-private.h b/dump-restore-private.h
\r
77 new file mode 100644
\r
78 index 0000000..896a004
\r
80 +++ b/dump-restore-private.h
\r
82 +#ifndef DUMP_RESTORE_PRIVATE_H
\r
83 +#define DUMP_RESTORE_PRIVATE_H
\r
85 +#include "hex-escape.h"
\r
86 +#include "command-line-arguments.h"
\r
88 +typedef enum dump_formats {
\r
90 + DUMP_FORMAT_BATCH_TAG,
\r
95 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
96 index 88f598a..d2dad40 100644
\r
97 --- a/notmuch-dump.c
\r
98 +++ b/notmuch-dump.c
\r
102 #include "notmuch-client.h"
\r
103 +#include "dump-restore-private.h"
\r
106 notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
107 @@ -43,7 +44,13 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
108 char *output_file_name = NULL;
\r
111 + int output_format = DUMP_FORMAT_SUP;
\r
113 notmuch_opt_desc_t options[] = {
\r
114 + { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
\r
115 + (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
\r
116 + { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
118 { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
\r
121 @@ -83,27 +90,56 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
123 notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
125 + char *buffer = NULL;
\r
126 + size_t buffer_size = 0;
\r
128 for (messages = notmuch_query_search_messages (query);
\r
129 notmuch_messages_valid (messages);
\r
130 notmuch_messages_move_to_next (messages)) {
\r
132 + const char *message_id;
\r
134 message = notmuch_messages_get (messages);
\r
135 + message_id = notmuch_message_get_message_id (message);
\r
138 - "%s (", notmuch_message_get_message_id (message));
\r
139 + if (output_format == DUMP_FORMAT_SUP) {
\r
140 + fprintf (output, "%s (", message_id);
\r
143 for (tags = notmuch_message_get_tags (message);
\r
144 notmuch_tags_valid (tags);
\r
145 notmuch_tags_move_to_next (tags)) {
\r
147 - fprintf (output, " ");
\r
148 + const char *tag_str = notmuch_tags_get (tags);
\r
150 - fprintf (output, "%s", notmuch_tags_get (tags));
\r
152 + fputs (" ", output);
\r
156 + if (output_format == DUMP_FORMAT_SUP) {
\r
157 + fputs (tag_str, output);
\r
159 + if (hex_encode (notmuch, tag_str,
\r
160 + &buffer, &buffer_size) != HEX_SUCCESS) {
\r
161 + fprintf (stderr, "Error: failed to hex-encode tag %s\n",
\r
165 + fprintf (output, "+%s", buffer);
\r
169 - fprintf (output, ")\n");
\r
170 + if (output_format == DUMP_FORMAT_SUP) {
\r
171 + fputs (")\n", output);
\r
173 + if (hex_encode (notmuch, message_id,
\r
174 + &buffer, &buffer_size) != HEX_SUCCESS) {
\r
175 + fprintf (stderr, "Error: failed to hex-encode msg-id %s\n",
\r
179 + fprintf (output, " -- id:%s\n", buffer);
\r
182 notmuch_message_destroy (message);
\r