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 50825431FAF
\r
6 for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 00:35:13 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5
\r
12 tests=[FREEMAIL_FROM=0.001] 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 GciJoh2Oo4EN for <notmuch@notmuchmail.org>;
\r
16 Fri, 30 Nov 2012 00:35:11 -0800 (PST)
\r
17 Received: from mail.nexoid.at (www.nexoid.at [178.79.130.240])
\r
18 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 045B4431FC0
\r
21 for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 00:35:10 -0800 (PST)
\r
22 Received: by mail.nexoid.at (Postfix, from userid 1000)
\r
23 id A927F11C0D2; Fri, 30 Nov 2012 09:29:18 +0100 (CET)
\r
24 From: Peter Feigl <craven@gmx.net>
\r
25 To: notmuch@notmuchmail.org
\r
26 Subject: [PATCH 3/3] Use the S-Expression structured printer in notmuch show
\r
28 Date: Fri, 30 Nov 2012 09:29:03 +0100
\r
29 Message-Id: <1354264143-30173-3-git-send-email-craven@gmx.net>
\r
30 X-Mailer: git-send-email 1.8.0
\r
31 In-Reply-To: <1354264143-30173-1-git-send-email-craven@gmx.net>
\r
32 References: <1354264143-30173-1-git-send-email-craven@gmx.net>
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.13
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Fri, 30 Nov 2012 08:35:13 -0000
\r
47 This commit changes the json printer (which doesn't do anything
\r
48 json-specific anyway but just uses the structured printers) to generic
\r
49 sprinters, and adds support for the printer defined in sprinter-sexp.c.
\r
51 notmuch-client.h | 8 ++++----
\r
52 notmuch-reply.c | 40 ++++++++++++++++++++++++----------------
\r
53 notmuch-show.c | 48 +++++++++++++++++++++++++++++-------------------
\r
54 3 files changed, 57 insertions(+), 39 deletions(-)
\r
56 diff --git a/notmuch-client.h b/notmuch-client.h
\r
57 index ae9344b..1c336dc 100644
\r
58 --- a/notmuch-client.h
\r
59 +++ b/notmuch-client.h
\r
60 @@ -175,12 +175,12 @@ notmuch_status_t
\r
61 show_one_part (const char *filename, int part);
\r
64 -format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node,
\r
65 - notmuch_bool_t first, notmuch_bool_t output_body);
\r
66 +format_part_sprinter (const void *ctx, struct sprinter *sp, mime_node_t *node,
\r
67 + notmuch_bool_t first, notmuch_bool_t output_body);
\r
70 -format_headers_json (struct sprinter *sp, GMimeMessage *message,
\r
71 - notmuch_bool_t reply);
\r
72 +format_headers_sprinter (struct sprinter *sp, GMimeMessage *message,
\r
73 + notmuch_bool_t reply);
\r
76 NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,
\r
77 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
78 index e60a264..a7469a2 100644
\r
79 --- a/notmuch-reply.c
\r
80 +++ b/notmuch-reply.c
\r
81 @@ -548,7 +548,8 @@ notmuch_reply_format_default(void *ctx,
\r
82 notmuch_config_t *config,
\r
83 notmuch_query_t *query,
\r
84 notmuch_show_params_t *params,
\r
85 - notmuch_bool_t reply_all)
\r
86 + notmuch_bool_t reply_all,
\r
87 + unused (sprinter_t *sp))
\r
89 GMimeMessage *reply;
\r
90 notmuch_messages_t *messages;
\r
91 @@ -587,17 +588,17 @@ notmuch_reply_format_default(void *ctx,
\r
95 -notmuch_reply_format_json(void *ctx,
\r
96 - notmuch_config_t *config,
\r
97 - notmuch_query_t *query,
\r
98 - notmuch_show_params_t *params,
\r
99 - notmuch_bool_t reply_all)
\r
100 +notmuch_reply_format_sprinter(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
107 GMimeMessage *reply;
\r
108 notmuch_messages_t *messages;
\r
109 notmuch_message_t *message;
\r
113 if (notmuch_query_count_messages (query) != 1) {
\r
114 fprintf (stderr, "Error: search term did not match precisely one message.\n");
\r
115 @@ -613,18 +614,17 @@ notmuch_reply_format_json(void *ctx,
\r
119 - sp = sprinter_json_create (ctx, stdout);
\r
120 sp->begin_map (sp);
\r
122 /* The headers of the reply message we've created */
\r
123 sp->map_key (sp, "reply-headers");
\r
124 - format_headers_json (sp, reply, TRUE);
\r
125 + format_headers_sprinter (sp, reply, TRUE);
\r
126 g_object_unref (G_OBJECT (reply));
\r
129 /* Start the original */
\r
130 sp->map_key (sp, "original");
\r
131 - format_part_json (ctx, sp, node, TRUE, TRUE);
\r
132 + format_part_sprinter (ctx, sp, node, TRUE, TRUE);
\r
136 @@ -639,7 +639,8 @@ notmuch_reply_format_headers_only(void *ctx,
\r
137 notmuch_config_t *config,
\r
138 notmuch_query_t *query,
\r
139 unused (notmuch_show_params_t *params),
\r
140 - notmuch_bool_t reply_all)
\r
141 + notmuch_bool_t reply_all,
\r
142 + unused (sprinter_t *sp))
\r
144 GMimeMessage *reply;
\r
145 notmuch_messages_t *messages;
\r
146 @@ -696,6 +697,7 @@ notmuch_reply_format_headers_only(void *ctx,
\r
151 FORMAT_HEADERS_ONLY,
\r
154 @@ -707,7 +709,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
155 notmuch_query_t *query;
\r
156 char *query_string;
\r
157 int opt_index, ret = 0;
\r
158 - 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
159 + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all, struct sprinter *sp);
\r
160 notmuch_show_params_t params = {
\r
163 @@ -717,11 +719,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
165 int format = FORMAT_DEFAULT;
\r
166 int reply_all = TRUE;
\r
167 + struct sprinter *sp = NULL;
\r
169 notmuch_opt_desc_t options[] = {
\r
170 { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
\r
171 (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
\r
172 { "json", FORMAT_JSON },
\r
173 + { "sexp", FORMAT_SEXP },
\r
174 { "headers-only", FORMAT_HEADERS_ONLY },
\r
176 { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',
\r
177 @@ -740,9 +744,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
179 if (format == FORMAT_HEADERS_ONLY)
\r
180 reply_format_func = notmuch_reply_format_headers_only;
\r
181 - else if (format == FORMAT_JSON)
\r
182 - reply_format_func = notmuch_reply_format_json;
\r
184 + else if (format == FORMAT_JSON) {
\r
185 + reply_format_func = notmuch_reply_format_sprinter;
\r
186 + sp = sprinter_json_create(ctx, stdout);
\r
187 + } else if (format == FORMAT_SEXP) {
\r
188 + reply_format_func = notmuch_reply_format_sprinter;
\r
189 + sp = sprinter_sexp_create(ctx, stdout);
\r
191 reply_format_func = notmuch_reply_format_default;
\r
193 config = notmuch_config_open (ctx, NULL, NULL);
\r
194 @@ -770,7 +778,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
198 - if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0)
\r
199 + if (reply_format_func (ctx, config, query, ¶ms, reply_all, sp) != 0)
\r
202 notmuch_crypto_cleanup (¶ms.crypto);
\r
203 diff --git a/notmuch-show.c b/notmuch-show.c
\r
204 index 2fa2292..e6da2ff 100644
\r
205 --- a/notmuch-show.c
\r
206 +++ b/notmuch-show.c
\r
207 @@ -32,12 +32,17 @@ static const notmuch_show_format_t format_text = {
\r
210 static notmuch_status_t
\r
211 -format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
212 +format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
213 int indent, const notmuch_show_params_t *params);
\r
215 static const notmuch_show_format_t format_json = {
\r
216 .new_sprinter = sprinter_json_create,
\r
217 - .part = format_part_json_entry,
\r
218 + .part = format_part_sprinter_entry,
\r
221 +static const notmuch_show_format_t format_sexp = {
\r
222 + .new_sprinter = sprinter_sexp_create,
\r
223 + .part = format_part_sprinter_entry,
\r
226 static notmuch_status_t
\r
227 @@ -108,9 +113,9 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)
\r
228 /* Emit a sequence of key/value pairs for the metadata of message.
\r
229 * The caller should begin a map before calling this. */
\r
231 -format_message_json (sprinter_t *sp, notmuch_message_t *message)
\r
232 +format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)
\r
234 - /* Any changes to the JSON format should be reflected in the file
\r
235 + /* Any changes to the JSON or S-Expression format should be reflected in the file
\r
236 * devel/schemata. */
\r
238 void *local = talloc_new (NULL);
\r
239 @@ -208,7 +213,7 @@ _is_from_line (const char *line)
\r
243 -format_headers_json (sprinter_t *sp, GMimeMessage *message,
\r
244 +format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
\r
245 notmuch_bool_t reply)
\r
247 /* Any changes to the JSON format should be reflected in the file
\r
248 @@ -363,7 +368,7 @@ signer_status_to_string (GMimeSignerStatus x)
\r
250 #ifdef GMIME_ATLEAST_26
\r
252 -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
\r
253 +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
\r
255 /* Any changes to the JSON format should be reflected in the file
\r
256 * devel/schemata. */
\r
257 @@ -438,7 +443,7 @@ format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
\r
261 -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
\r
262 +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
\r
264 const GMimeSignatureValidity* validity = node->sig_validity;
\r
266 @@ -595,7 +600,7 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
270 -format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
271 +format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
272 notmuch_bool_t first, notmuch_bool_t output_body)
\r
274 /* Any changes to the JSON format should be reflected in the file
\r
275 @@ -603,15 +608,15 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
277 if (node->envelope_file) {
\r
278 sp->begin_map (sp);
\r
279 - format_message_json (sp, node->envelope_file);
\r
280 + format_message_sprinter (sp, node->envelope_file);
\r
282 sp->map_key (sp, "headers");
\r
283 - format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
\r
284 + format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);
\r
287 sp->map_key (sp, "body");
\r
288 sp->begin_list (sp);
\r
289 - format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);
\r
290 + format_part_sprinter (ctx, sp, mime_node_child (node, 0), first, TRUE);
\r
294 @@ -646,7 +651,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
296 if (node->verify_attempted) {
\r
297 sp->map_key (sp, "sigstatus");
\r
298 - format_part_sigstatus_json (sp, node);
\r
299 + format_part_sigstatus_sprinter (sp, node);
\r
302 sp->map_key (sp, "content-type");
\r
303 @@ -698,7 +703,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
304 sp->begin_map (sp);
\r
306 sp->map_key (sp, "headers");
\r
307 - format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
\r
308 + format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);
\r
310 sp->map_key (sp, "body");
\r
311 sp->begin_list (sp);
\r
312 @@ -706,7 +711,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
315 for (i = 0; i < node->nchildren; i++)
\r
316 - format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
\r
317 + format_part_sprinter (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
\r
319 /* Close content structures */
\r
320 for (i = 0; i < nclose; i++)
\r
321 @@ -716,11 +721,11 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
\r
324 static notmuch_status_t
\r
325 -format_part_json_entry (const void *ctx, sprinter_t *sp,
\r
326 +format_part_sprinter_entry (const void *ctx, sprinter_t *sp,
\r
327 mime_node_t *node, unused (int indent),
\r
328 const notmuch_show_params_t *params)
\r
330 - format_part_json (ctx, sp, node, TRUE, params->output_body);
\r
331 + format_part_sprinter (ctx, sp, node, TRUE, params->output_body);
\r
333 return NOTMUCH_STATUS_SUCCESS;
\r
335 @@ -1012,6 +1017,7 @@ do_show (void *ctx,
\r
337 NOTMUCH_FORMAT_NOT_SPECIFIED,
\r
338 NOTMUCH_FORMAT_JSON,
\r
339 + NOTMUCH_FORMAT_SEXP,
\r
340 NOTMUCH_FORMAT_TEXT,
\r
341 NOTMUCH_FORMAT_MBOX,
\r
343 @@ -1056,6 +1062,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
344 { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
\r
345 (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
\r
346 { "text", NOTMUCH_FORMAT_TEXT },
\r
347 + { "sexp", NOTMUCH_FORMAT_SEXP },
\r
348 { "mbox", NOTMUCH_FORMAT_MBOX },
\r
349 { "raw", NOTMUCH_FORMAT_RAW },
\r
351 @@ -1100,6 +1107,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
352 case NOTMUCH_FORMAT_TEXT:
\r
353 format = &format_text;
\r
355 + case NOTMUCH_FORMAT_SEXP:
\r
356 + format = &format_sexp;
\r
358 case NOTMUCH_FORMAT_MBOX:
\r
359 if (params.part > 0) {
\r
360 fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");
\r
361 @@ -1120,7 +1130,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
363 /* Default is entire-thread = FALSE except for format=json. */
\r
364 if (entire_thread == ENTIRE_THREAD_DEFAULT) {
\r
365 - if (format == &format_json)
\r
366 + if (format == &format_json || format == &format_sexp)
\r
367 entire_thread = ENTIRE_THREAD_TRUE;
\r
369 entire_thread = ENTIRE_THREAD_FALSE;
\r
370 @@ -1131,8 +1141,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
371 fprintf (stderr, "Warning: --body=false is incompatible with --part > 0. Disabling.\n");
\r
372 params.output_body = TRUE;
\r
374 - if (format != &format_json)
\r
375 - fprintf (stderr, "Warning: --body=false only implemented for format=json\n");
\r
376 + if (format != &format_json && format != &format_sexp)
\r
377 + fprintf (stderr, "Warning: --body=false only implemented for format=json or format=sexp\n");
\r