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 6BFF0431FAF
\r
6 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:36 -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 DVO7AneI3bGN for <notmuch@notmuchmail.org>;
\r
16 Sat, 24 Nov 2012 13:20:35 -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 E48BE431FC0
\r
21 for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 13:20:32 -0800 (PST)
\r
22 Received: from fctnnbsc30w-156034089108.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([156.34.89.108] 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 1TcN9M-0006SN-1r; Sat, 24 Nov 2012 17:20:32 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1TcN9G-0008Ct-Im; Sat, 24 Nov 2012 17:20:26 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [Patch v2 07/17] notmuch-dump: add --format=(batch-tag|sup)
\r
34 Date: Sat, 24 Nov 2012 17:20:07 -0400
\r
35 Message-Id: <1353792017-31459-8-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.10.4
\r
37 In-Reply-To: <1353792017-31459-1-git-send-email-david@tethera.net>
\r
38 References: <1353792017-31459-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, 24 Nov 2012 21:20:36 -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- format is valid for notmuch tag, (with the
\r
61 "notmuch tag" omitted from the front of the line). The dump format
\r
62 only uses query strings of a single message-id.
\r
64 Each space seperated tag/message-id is 'hex-encoded' to remove
\r
65 troubling characters. In particular this format won't have the same
\r
66 problem with e.g. spaces in message-ids or tags; they will be
\r
69 dump-restore-private.h | 13 +++++++++++++
\r
70 notmuch-dump.c | 42 ++++++++++++++++++++++++++++++++++++------
\r
71 2 files changed, 49 insertions(+), 6 deletions(-)
\r
72 create mode 100644 dump-restore-private.h
\r
74 diff --git a/dump-restore-private.h b/dump-restore-private.h
\r
75 new file mode 100644
\r
76 index 0000000..896a004
\r
78 +++ b/dump-restore-private.h
\r
80 +#ifndef DUMP_RESTORE_PRIVATE_H
\r
81 +#define DUMP_RESTORE_PRIVATE_H
\r
83 +#include "hex-escape.h"
\r
84 +#include "command-line-arguments.h"
\r
86 +typedef enum dump_formats {
\r
88 + DUMP_FORMAT_BATCH_TAG,
\r
93 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
94 index 88f598a..045ca9e 100644
\r
95 --- a/notmuch-dump.c
\r
96 +++ b/notmuch-dump.c
\r
100 #include "notmuch-client.h"
\r
101 +#include "dump-restore-private.h"
\r
104 notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
105 @@ -43,7 +44,13 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
106 char *output_file_name = NULL;
\r
109 + int output_format = DUMP_FORMAT_SUP;
\r
111 notmuch_opt_desc_t options[] = {
\r
112 + { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
\r
113 + (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
\r
114 + { "batch-tag", DUMP_FORMAT_BATCH_TAG },
\r
116 { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0 },
\r
119 @@ -83,27 +90,50 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
121 notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
123 + char *buffer = NULL;
\r
124 + size_t buffer_size = 0;
\r
126 for (messages = notmuch_query_search_messages (query);
\r
127 notmuch_messages_valid (messages);
\r
128 notmuch_messages_move_to_next (messages)) {
\r
130 + const char *message_id;
\r
132 message = notmuch_messages_get (messages);
\r
133 + message_id = notmuch_message_get_message_id (message);
\r
136 - "%s (", notmuch_message_get_message_id (message));
\r
137 + if (output_format == DUMP_FORMAT_SUP) {
\r
138 + fprintf (output, "%s (", message_id);
\r
141 for (tags = notmuch_message_get_tags (message);
\r
142 notmuch_tags_valid (tags);
\r
143 notmuch_tags_move_to_next (tags)) {
\r
145 - fprintf (output, " ");
\r
146 + const char *tag_str = notmuch_tags_get (tags);
\r
148 - fprintf (output, "%s", notmuch_tags_get (tags));
\r
150 + fputs (" ", output);
\r
154 + if (output_format == DUMP_FORMAT_SUP) {
\r
155 + fputs (tag_str, output);
\r
157 + if (hex_encode (notmuch, tag_str,
\r
158 + &buffer, &buffer_size) != HEX_SUCCESS)
\r
160 + fprintf (output, "+%s", buffer);
\r
164 - fprintf (output, ")\n");
\r
165 + if (output_format == DUMP_FORMAT_SUP) {
\r
166 + fputs (")\n", output);
\r
168 + if (hex_encode (notmuch, message_id,
\r
169 + &buffer, &buffer_size) != HEX_SUCCESS)
\r
171 + fprintf (output, " -- id:%s\n", buffer);
\r
174 notmuch_message_destroy (message);
\r