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 41465429E26
\r
6 for <notmuch@notmuchmail.org>; Sun, 18 Dec 2011 05:15:52 -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 w7tnTZHEasHd for <notmuch@notmuchmail.org>;
\r
16 Sun, 18 Dec 2011 05:15:51 -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 8152C429E34
\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 pBIDFcfD017879
\r
26 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);
\r
27 Sun, 18 Dec 2011 09:15:39 -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-0008RM-KU; 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 4/9] notmuch-dump: add --format=(notmuch|sup)
\r
34 Date: Sun, 18 Dec 2011 09:15:06 -0400
\r
35 Message-Id: <1324214111-32079-5-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:52 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 sup is the old format, and remains the default.
\r
59 Each line of the notmuch format is "msg_id tag tag...tag" where each
\r
60 space seperated token is 'hex-encoded' to remove troubling characters.
\r
61 In particular this format won't have the same problem with e.g. spaces
\r
62 in message-ids or tags; they will be round-trip-able.
\r
64 dump-restore-private.h | 12 ++++++++++++
\r
65 notmuch-dump.c | 47 +++++++++++++++++++++++++++++++++++++++--------
\r
66 2 files changed, 51 insertions(+), 8 deletions(-)
\r
67 create mode 100644 dump-restore-private.h
\r
69 diff --git a/dump-restore-private.h b/dump-restore-private.h
\r
70 new file mode 100644
\r
71 index 0000000..34a5022
\r
73 +++ b/dump-restore-private.h
\r
75 +#ifndef DUMP_RESTORE_PRIVATE_H
\r
76 +#define DUMP_RESTORE_PRIVATE_H
\r
78 +#include "hex-escape.h"
\r
79 +#include "command-line-arguments.h"
\r
81 +typedef enum dump_formats {
\r
83 + DUMP_FORMAT_NOTMUCH
\r
87 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
88 index a735875..0231db2 100644
\r
89 --- a/notmuch-dump.c
\r
90 +++ b/notmuch-dump.c
\r
94 #include "notmuch-client.h"
\r
95 +#include "dump-restore-private.h"
\r
98 notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
99 @@ -44,9 +45,15 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
100 char *output_file_name = NULL;
\r
103 + int output_format = DUMP_FORMAT_SUP;
\r
105 notmuch_opt_desc_t options[] = {
\r
106 - { NOTMUCH_OPT_POSITION, &output_file_name, 0, 0, 0 },
\r
107 - { 0, 0, 0, 0, 0 }
\r
108 + { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',
\r
109 + (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },
\r
110 + { "notmuch", DUMP_FORMAT_NOTMUCH },
\r
112 + { NOTMUCH_OPT_POSITION, &output_file_name, 0, 0, 0 },
\r
113 + { 0, 0, 0, 0, 0 }
\r
116 opt_index = parse_arguments (argc, argv, options, 1);
\r
117 @@ -85,29 +92,53 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
119 notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
121 + char *buffer = NULL;
\r
122 + size_t buffer_size = 0;
\r
124 for (messages = notmuch_query_search_messages (query);
\r
125 notmuch_messages_valid (messages);
\r
126 notmuch_messages_move_to_next (messages))
\r
129 - message = notmuch_messages_get (messages);
\r
130 + const char *message_id;
\r
133 - "%s (", notmuch_message_get_message_id (message));
\r
134 + message = notmuch_messages_get (messages);
\r
135 + message_id = notmuch_message_get_message_id (message);
\r
137 + if (output_format == DUMP_FORMAT_SUP) {
\r
138 + fprintf (output, "%s (", message_id);
\r
140 + if (hex_encode (notmuch, message_id,
\r
141 + &buffer, &buffer_size) != HEX_SUCCESS)
\r
143 + fprintf (output, "%s ", buffer);
\r
146 for (tags = notmuch_message_get_tags (message);
\r
147 notmuch_tags_valid (tags);
\r
148 notmuch_tags_move_to_next (tags))
\r
150 + const char *tag_str = notmuch_tags_get (tags);
\r
153 - fprintf (output, " ");
\r
154 + fputs (" ", output);
\r
156 - fprintf (output, "%s", notmuch_tags_get (tags));
\r
157 + if (output_format == DUMP_FORMAT_SUP) {
\r
158 + fputs (tag_str, output);
\r
160 + if (hex_encode (notmuch, tag_str,
\r
161 + &buffer, &buffer_size) != HEX_SUCCESS)
\r
164 + fputs (buffer, output);
\r
169 - fprintf (output, ")\n");
\r
170 + if (output_format == DUMP_FORMAT_SUP)
\r
171 + fputs (")\n", output);
\r
173 + fputs ("\n", output);
\r
175 notmuch_message_destroy (message);
\r