1 Return-Path: <bremner@tesseract.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 arlo.cworth.org (Postfix) with ESMTP id 558576DE0360
\r
6 for <notmuch@notmuchmail.org>; Tue, 2 Aug 2016 21:38:57 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id fOqQ3axHE4eS for <notmuch@notmuchmail.org>;
\r
17 Tue, 2 Aug 2016 21:38:49 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id 623116DE02AF
\r
20 for <notmuch@notmuchmail.org>; Tue, 2 Aug 2016 21:38:27 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2)
\r
22 (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
23 id 1bUnx5-0000Ge-Js; Wed, 03 Aug 2016 00:38:43 -0400
\r
24 Received: (nullmailer pid 12789 invoked by uid 1000);
\r
25 Wed, 03 Aug 2016 00:30:32 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH 6/8] CLI: refactor dumping of tags.
\r
29 Date: Wed, 3 Aug 2016 09:30:26 +0900
\r
30 Message-Id: <1470184228-12517-7-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.8.1
\r
32 In-Reply-To: <1470184228-12517-1-git-send-email-david@tethera.net>
\r
33 References: <1470184228-12517-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Wed, 03 Aug 2016 04:38:57 -0000
\r
48 This is mainly code movement, to make room in the loop over messages for
\r
51 notmuch-dump.c | 127 +++++++++++++++++++++++++++++++--------------------------
\r
52 1 file changed, 69 insertions(+), 58 deletions(-)
\r
54 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
55 index cae1db8..d80ed8b8 100644
\r
56 --- a/notmuch-dump.c
\r
57 +++ b/notmuch-dump.c
\r
58 @@ -78,13 +78,78 @@ print_dump_header (gzFile output, int output_format, int include)
\r
62 +dump_tags_message (void *ctx,
\r
63 + notmuch_message_t *message, int output_format,
\r
65 + char **buffer_p, size_t *size_p)
\r
68 + const char *message_id;
\r
70 + message_id = notmuch_message_get_message_id (message);
\r
72 + if (output_format == DUMP_FORMAT_BATCH_TAG &&
\r
73 + strchr (message_id, '\n')) {
\r
74 + /* This will produce a line break in the output, which
\r
75 + * would be difficult to handle in tools. However, it's
\r
76 + * also impossible to produce an email containing a line
\r
77 + * break in a message ID because of unfolding, so we can
\r
78 + * safely disallow it. */
\r
79 + fprintf (stderr, "Warning: skipping message id containing line break: \"%s\"\n", message_id);
\r
80 + return EXIT_SUCCESS;
\r
83 + if (output_format == DUMP_FORMAT_SUP) {
\r
84 + gzprintf (output, "%s (", message_id);
\r
87 + for (notmuch_tags_t *tags = notmuch_message_get_tags (message);
\r
88 + notmuch_tags_valid (tags);
\r
89 + notmuch_tags_move_to_next (tags)) {
\r
90 + const char *tag_str = notmuch_tags_get (tags);
\r
93 + gzputs (output, " ");
\r
97 + if (output_format == DUMP_FORMAT_SUP) {
\r
98 + gzputs (output, tag_str);
\r
100 + if (hex_encode (ctx, tag_str,
\r
101 + buffer_p, size_p) != HEX_SUCCESS) {
\r
102 + fprintf (stderr, "Error: failed to hex-encode tag %s\n",
\r
104 + return EXIT_FAILURE;
\r
106 + gzprintf (output, "+%s", *buffer_p);
\r
110 + if (output_format == DUMP_FORMAT_SUP) {
\r
111 + gzputs (output, ")\n");
\r
113 + if (make_boolean_term (ctx, "id", message_id,
\r
114 + buffer_p, size_p)) {
\r
115 + fprintf (stderr, "Error quoting message id %s: %s\n",
\r
116 + message_id, strerror (errno));
\r
117 + return EXIT_FAILURE;
\r
119 + gzprintf (output, " -- %s\n", *buffer_p);
\r
121 + return EXIT_SUCCESS;
\r
125 database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
126 const char *query_str, int output_format, int include)
\r
128 notmuch_query_t *query;
\r
129 notmuch_messages_t *messages;
\r
130 notmuch_message_t *message;
\r
131 - notmuch_tags_t *tags;
\r
132 + notmuch_status_t status;
\r
133 + char *buffer = NULL;
\r
134 + size_t buffer_size = 0;
\r
136 print_dump_header (output, output_format, include);
\r
138 @@ -110,10 +175,6 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
140 notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);
\r
142 - char *buffer = NULL;
\r
143 - size_t buffer_size = 0;
\r
144 - notmuch_status_t status;
\r
146 status = notmuch_query_search_messages_st (query, &messages);
\r
147 if (print_status_query ("notmuch dump", query, status))
\r
148 return EXIT_FAILURE;
\r
149 @@ -121,62 +182,12 @@ database_dump_file (notmuch_database_t *notmuch, gzFile output,
\r
151 notmuch_messages_valid (messages);
\r
152 notmuch_messages_move_to_next (messages)) {
\r
154 - const char *message_id;
\r
156 message = notmuch_messages_get (messages);
\r
157 - message_id = notmuch_message_get_message_id (message);
\r
159 - if (output_format == DUMP_FORMAT_BATCH_TAG &&
\r
160 - strchr (message_id, '\n')) {
\r
161 - /* This will produce a line break in the output, which
\r
162 - * would be difficult to handle in tools. However, it's
\r
163 - * also impossible to produce an email containing a line
\r
164 - * break in a message ID because of unfolding, so we can
\r
165 - * safely disallow it. */
\r
166 - fprintf (stderr, "Warning: skipping message id containing line break: \"%s\"\n", message_id);
\r
167 - notmuch_message_destroy (message);
\r
171 - if (output_format == DUMP_FORMAT_SUP) {
\r
172 - gzprintf (output, "%s (", message_id);
\r
175 - for (tags = notmuch_message_get_tags (message);
\r
176 - notmuch_tags_valid (tags);
\r
177 - notmuch_tags_move_to_next (tags)) {
\r
178 - const char *tag_str = notmuch_tags_get (tags);
\r
181 - gzputs (output, " ");
\r
185 - if (output_format == DUMP_FORMAT_SUP) {
\r
186 - gzputs (output, tag_str);
\r
188 - if (hex_encode (notmuch, tag_str,
\r
189 - &buffer, &buffer_size) != HEX_SUCCESS) {
\r
190 - fprintf (stderr, "Error: failed to hex-encode tag %s\n",
\r
192 - return EXIT_FAILURE;
\r
194 - gzprintf (output, "+%s", buffer);
\r
198 - if (output_format == DUMP_FORMAT_SUP) {
\r
199 - gzputs (output, ")\n");
\r
201 - if (make_boolean_term (notmuch, "id", message_id,
\r
202 - &buffer, &buffer_size)) {
\r
203 - fprintf (stderr, "Error quoting message id %s: %s\n",
\r
204 - message_id, strerror (errno));
\r
205 - return EXIT_FAILURE;
\r
207 - gzprintf (output, " -- %s\n", buffer);
\r
209 + if (dump_tags_message (notmuch, message, output_format, output,
\r
210 + &buffer, &buffer_size))
\r
211 + return EXIT_FAILURE;
\r
213 notmuch_message_destroy (message);
\r