1 Return-Path: <nex@nexoid.at>
\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 A8C4F431FC0
\r
6 for <notmuch@notmuchmail.org>; Thu, 6 Dec 2012 03:45:28 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5
\r
13 tests=[FREEMAIL_FROM=0.001] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id bHle1ysCkMOY for <notmuch@notmuchmail.org>;
\r
17 Thu, 6 Dec 2012 03:45:25 -0800 (PST)
\r
18 Received: from mail.nexoid.at (www.nexoid.at [178.79.130.240])
\r
19 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id A6E8F431FB6
\r
22 for <notmuch@notmuchmail.org>; Thu, 6 Dec 2012 03:45:21 -0800 (PST)
\r
23 Received: by mail.nexoid.at (Postfix, from userid 1000)
\r
24 id 4770711C10E; Thu, 6 Dec 2012 12:45:14 +0100 (CET)
\r
25 From: Peter Feigl <craven@gmx.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [PATCH v4 2/5] Rename the -json printer functions in notmuch-reply
\r
28 and notmuch-show to generic -sprinter functions.
\r
29 Date: Thu, 6 Dec 2012 12:44:56 +0100
\r
31 <785c9f89c35c861fbbe3ead3fe7289b65d31e216.1354794428.git.craven@gmx.net>
\r
32 X-Mailer: git-send-email 1.8.0
\r
33 In-Reply-To: <cover.1354794428.git.craven@gmx.net>
\r
34 References: <cover.1354794428.git.craven@gmx.net>
\r
35 In-Reply-To: <cover.1354794428.git.craven@gmx.net>
\r
36 References: <cover.1354794428.git.craven@gmx.net>
\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: Thu, 06 Dec 2012 11:45:29 -0000
\r
51 All the structured output functions in notmuch-reply and notmuch-show
\r
52 are renamed to a generic name (as they do not contain any json-specific
\r
53 code anyway). This patch is a preparation to actually using the new
\r
54 S-Expression sprinter in notmuch-reply and notmuch-show.
\r
56 notmuch-client.h | 8 ++++----
\r
57 notmuch-reply.c | 43 ++++++++++++++++++++++++++-----------------
\r
58 notmuch-show.c | 30 +++++++++++++++---------------
\r
59 3 files changed, 45 insertions(+), 36 deletions(-)
\r
61 diff --git a/notmuch-client.h b/notmuch-client.h
\r
62 index ae9344b..1c336dc 100644
\r
63 --- a/notmuch-client.h
\r
64 +++ b/notmuch-client.h
\r
65 @@ -175,12 +175,12 @@ notmuch_status_t
\r
66 show_one_part (const char *filename, int part);
\r
69 -format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node,
\r
70 - notmuch_bool_t first, notmuch_bool_t output_body);
\r
71 +format_part_sprinter (const void *ctx, struct sprinter *sp, mime_node_t *node,
\r
72 + notmuch_bool_t first, notmuch_bool_t output_body);
\r
75 -format_headers_json (struct sprinter *sp, GMimeMessage *message,
\r
76 - notmuch_bool_t reply);
\r
77 +format_headers_sprinter (struct sprinter *sp, GMimeMessage *message,
\r
78 + notmuch_bool_t reply);
\r
81 NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,
\r
82 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
83 index e60a264..6103d6e 100644
\r
84 --- a/notmuch-reply.c
\r
85 +++ b/notmuch-reply.c
\r
86 @@ -548,7 +548,8 @@ notmuch_reply_format_default(void *ctx,
\r
87 notmuch_config_t *config,
\r
88 notmuch_query_t *query,
\r
89 notmuch_show_params_t *params,
\r
90 - notmuch_bool_t reply_all)
\r
91 + notmuch_bool_t reply_all,
\r
92 + unused (sprinter_t *sp))
\r
94 GMimeMessage *reply;
\r
95 notmuch_messages_t *messages;
\r
96 @@ -587,17 +588,17 @@ notmuch_reply_format_default(void *ctx,
\r
100 -notmuch_reply_format_json(void *ctx,
\r
101 - notmuch_config_t *config,
\r
102 - notmuch_query_t *query,
\r
103 - notmuch_show_params_t *params,
\r
104 - notmuch_bool_t reply_all)
\r
105 +notmuch_reply_format_sprinter(void *ctx,
\r
106 + notmuch_config_t *config,
\r
107 + notmuch_query_t *query,
\r
108 + notmuch_show_params_t *params,
\r
109 + notmuch_bool_t reply_all,
\r
112 GMimeMessage *reply;
\r
113 notmuch_messages_t *messages;
\r
114 notmuch_message_t *message;
\r
118 if (notmuch_query_count_messages (query) != 1) {
\r
119 fprintf (stderr, "Error: search term did not match precisely one message.\n");
\r
120 @@ -613,18 +614,17 @@ notmuch_reply_format_json(void *ctx,
\r
124 - sp = sprinter_json_create (ctx, stdout);
\r
125 sp->begin_map (sp);
\r
127 /* The headers of the reply message we've created */
\r
128 sp->map_key (sp, "reply-headers");
\r
129 - format_headers_json (sp, reply, TRUE);
\r
130 + format_headers_sprinter (sp, reply, TRUE);
\r
131 g_object_unref (G_OBJECT (reply));
\r
134 /* Start the original */
\r
135 sp->map_key (sp, "original");
\r
136 - format_part_json (ctx, sp, node, TRUE, TRUE);
\r
137 + format_part_sprinter (ctx, sp, node, TRUE, TRUE);
\r
141 @@ -639,7 +639,8 @@ notmuch_reply_format_headers_only(void *ctx,
\r
142 notmuch_config_t *config,
\r
143 notmuch_query_t *query,
\r
144 unused (notmuch_show_params_t *params),
\r
145 - notmuch_bool_t reply_all)
\r
146 + notmuch_bool_t reply_all,
\r
147 + unused (sprinter_t *sp))
\r
149 GMimeMessage *reply;
\r
150 notmuch_messages_t *messages;
\r
151 @@ -707,7 +708,12 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
152 notmuch_query_t *query;
\r
153 char *query_string;
\r
154 int opt_index, ret = 0;
\r
155 - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);
\r
156 + int (*reply_format_func)(void *ctx,
\r
157 + notmuch_config_t *config,
\r
158 + notmuch_query_t *query,
\r
159 + notmuch_show_params_t *params,
\r
160 + notmuch_bool_t reply_all,
\r
161 + struct sprinter *sp);
\r
162 notmuch_show_params_t params = {
\r
165 @@ -717,6 +723,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
167 int format = FORMAT_DEFAULT;
\r
168 int reply_all = TRUE;
\r
169 + struct sprinter *sp = NULL;
\r
171 notmuch_opt_desc_t options[] = {
\r
172 { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
\r
173 @@ -738,12 +745,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
177 - if (format == FORMAT_HEADERS_ONLY)
\r
178 + if (format == FORMAT_HEADERS_ONLY) {
\r
179 reply_format_func = notmuch_reply_format_headers_only;
\r
180 - else if (format == FORMAT_JSON)
\r
181 - reply_format_func = notmuch_reply_format_json;
\r
183 + } else if (format == FORMAT_JSON) {
\r
184 + reply_format_func = notmuch_reply_format_sprinter;
\r
185 + sp = sprinter_json_create (ctx, stdout);
\r
187 reply_format_func = notmuch_reply_format_default;
\r
190 config = notmuch_config_open (ctx, NULL, NULL);
\r
191 if (config == NULL)
\r
192 @@ -770,7 +779,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
196 - if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0)
\r
197 + if (reply_format_func (ctx, config, query, ¶ms, reply_all, sp) != 0)
\r
200 notmuch_crypto_cleanup (¶ms.crypto);
\r
201 diff --git a/notmuch-show.c b/notmuch-show.c
\r
202 index 2fa2292..38c621f 100644
\r
203 --- a/notmuch-show.c
\r
204 +++ b/notmuch-show.c
\r
205 @@ -32,12 +32,12 @@ static const notmuch_show_format_t format_text = {
\r
208 static notmuch_status_t
\r
209 -format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
210 +format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
211 int indent, const notmuch_show_params_t *params);
\r
213 static const notmuch_show_format_t format_json = {
\r
214 .new_sprinter = sprinter_json_create,
\r
215 - .part = format_part_json_entry,
\r
216 + .part = format_part_sprinter_entry,
\r
219 static notmuch_status_t
\r
220 @@ -108,7 +108,7 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)
\r
221 /* Emit a sequence of key/value pairs for the metadata of message.
\r
222 * The caller should begin a map before calling this. */
\r
224 -format_message_json (sprinter_t *sp, notmuch_message_t *message)
\r
225 +format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)
\r
227 /* Any changes to the JSON format should be reflected in the file
\r
228 * devel/schemata. */
\r
229 @@ -208,7 +208,7 @@ _is_from_line (const char *line)
\r
233 -format_headers_json (sprinter_t *sp, GMimeMessage *message,
\r
234 +format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
\r
235 notmuch_bool_t reply)
\r
237 /* Any changes to the JSON format should be reflected in the file
\r
238 @@ -363,7 +363,7 @@ signer_status_to_string (GMimeSignerStatus x)
\r
240 #ifdef GMIME_ATLEAST_26
\r
242 -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
\r
243 +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
\r
245 /* Any changes to the JSON format should be reflected in the file
\r
246 * devel/schemata. */
\r
247 @@ -438,7 +438,7 @@ format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
\r
251 -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
\r
252 +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
\r
254 const GMimeSignatureValidity* validity = node->sig_validity;
\r
256 @@ -595,7 +595,7 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
260 -format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
261 +format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
262 notmuch_bool_t first, notmuch_bool_t output_body)
\r
264 /* Any changes to the JSON format should be reflected in the file
\r
265 @@ -603,15 +603,15 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
267 if (node->envelope_file) {
\r
268 sp->begin_map (sp);
\r
269 - format_message_json (sp, node->envelope_file);
\r
270 + format_message_sprinter (sp, node->envelope_file);
\r
272 sp->map_key (sp, "headers");
\r
273 - format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
\r
274 + format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);
\r
277 sp->map_key (sp, "body");
\r
278 sp->begin_list (sp);
\r
279 - format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);
\r
280 + format_part_sprinter (ctx, sp, mime_node_child (node, 0), first, TRUE);
\r
284 @@ -646,7 +646,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
286 if (node->verify_attempted) {
\r
287 sp->map_key (sp, "sigstatus");
\r
288 - format_part_sigstatus_json (sp, node);
\r
289 + format_part_sigstatus_sprinter (sp, node);
\r
292 sp->map_key (sp, "content-type");
\r
293 @@ -698,7 +698,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
294 sp->begin_map (sp);
\r
296 sp->map_key (sp, "headers");
\r
297 - format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
\r
298 + format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);
\r
300 sp->map_key (sp, "body");
\r
301 sp->begin_list (sp);
\r
302 @@ -706,7 +706,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
305 for (i = 0; i < node->nchildren; i++)
\r
306 - format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
\r
307 + format_part_sprinter (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
\r
309 /* Close content structures */
\r
310 for (i = 0; i < nclose; i++)
\r
311 @@ -716,11 +716,11 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
314 static notmuch_status_t
\r
315 -format_part_json_entry (const void *ctx, sprinter_t *sp,
\r
316 +format_part_sprinter_entry (const void *ctx, sprinter_t *sp,
\r
317 mime_node_t *node, unused (int indent),
\r
318 const notmuch_show_params_t *params)
\r
320 - format_part_json (ctx, sp, node, TRUE, params->output_body);
\r
321 + format_part_sprinter (ctx, sp, node, TRUE, params->output_body);
\r
323 return NOTMUCH_STATUS_SUCCESS;
\r