1 Return-Path: <amthrax@drake.mit.edu>
\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 A96FC429E29
\r
6 for <notmuch@notmuchmail.org>; Tue, 6 Mar 2012 10:48:55 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 1e7IRtpcixha for <notmuch@notmuchmail.org>;
\r
16 Tue, 6 Mar 2012 10:48:53 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 2CD28431FC9
\r
20 for <notmuch@notmuchmail.org>; Tue, 6 Mar 2012 10:48:52 -0800 (PST)
\r
21 X-AuditID: 1209190c-b7fad6d000000920-57-4f565c13c9aa
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id D1.1D.02336.31C565F4; Tue, 6 Mar 2012 13:48:51 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q26ImoRK016036;
\r
27 Tue, 6 Mar 2012 13:48:50 -0500
\r
28 Received: from drake.mit.edu (firewall.royalsociety.org [193.63.75.2])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q26Imm4N016463
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Tue, 6 Mar 2012 13:48:50 -0500 (EST)
\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amthrax@drake.mit.edu>)
\r
36 id 1S4zRI-0003pM-2D; Tue, 06 Mar 2012 18:48:48 +0000
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v2 3/8] show: Allow formatters to return errors
\r
40 Date: Tue, 6 Mar 2012 18:48:39 +0000
\r
41 Message-Id: <1331059724-14653-4-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.7.7.3
\r
43 In-Reply-To: <1331059724-14653-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1330752025-2542-1-git-send-email-amdragon@mit.edu>
\r
45 <1331059724-14653-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFtrJIsWRmVeSWpSXmKPExsUixCmqrCscE+ZvcHirusWefV4W12/OZHZg
\r
48 8rh7msvj2apbzAFMUVw2Kak5mWWpRfp2CVwZ65rWMhZs0K/omraaqYFxo0oXIyeHhICJxKZF
\r
49 P5ghbDGJC/fWs4HYQgL7GCX+fzDrYuQCstczStz5uZoZwjnIJDH9xFk2CGc+o8TMr/OYQFrY
\r
50 BDQktu1fzghiiwhIS+y8O5u1i5GDg1nASaKtzQvEFBawl5j7mQekgkVAVWLi6hVg1bwCDhJ9
\r
51 L/4xQRyhIHFu9Tl2EJtTwFFiz9NNjBAHlUlcunmBZQIj/wJGhlWMsim5Vbq5iZk5xanJusXJ
\r
52 iXl5qUW6hnq5mSV6qSmlmxjBISTJs4PxzUGlQ4wCHIxKPLwX9cP8hVgTy4orcw8xSnIwKYny
\r
53 5kQBhfiS8lMqMxKLM+KLSnNSiw8xSnAwK4nwfnsf6i/Em5JYWZValA+TkuZgURLnVdF65yck
\r
54 kJ5YkpqdmlqQWgSTleHgUJLgzYgGGipYlJqeWpGWmVOCkGbi4AQZzgM03Aikhre4IDG3ODMd
\r
55 In+KUVFKnNcPJCEAksgozYPrhcX4K0ZxoFeEeR1BqniA6QGu+xXQYCagwW3KwSCDSxIRUlIN
\r
56 jHHvHmTor1hvWHKpLjb3R+cG474u1t8vtjR7z8+79mdV5UnP6dxtanmC8/4eXjPbpmBRlvHv
\r
57 h2dvs29JmO8nLX/S9qStS7L/5G9SV5kqHKdyvb5x+vC5Xrlbi7zF2Z3nJAbz9Sj5mcx6oXl/
\r
58 0tLf0T/Xr37MwrD5/NQopqKK3DwVN8OGC/xiP5VYijMSDbWYi4oTAWcLH8nMAgAA
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Tue, 06 Mar 2012 18:48:56 -0000
\r
73 Formatter errors are propagated to the exit status of notmuch show.
\r
75 This isn't used by the JSON or text formatters, but it will be useful
\r
76 for the raw format, which is pickier.
\r
78 notmuch-client.h | 6 ++--
\r
79 notmuch-show.c | 71 +++++++++++++++++++++++++++++++++++-------------------
\r
80 2 files changed, 49 insertions(+), 28 deletions(-)
\r
82 diff --git a/notmuch-client.h b/notmuch-client.h
\r
83 index f4a62cc..a220fe4 100644
\r
84 --- a/notmuch-client.h
\r
85 +++ b/notmuch-client.h
\r
86 @@ -67,9 +67,9 @@ struct notmuch_show_params;
\r
88 typedef struct notmuch_show_format {
\r
89 const char *message_set_start;
\r
90 - void (*part) (const void *ctx,
\r
91 - struct mime_node *node, int indent,
\r
92 - const struct notmuch_show_params *params);
\r
93 + notmuch_status_t (*part) (const void *ctx,
\r
94 + struct mime_node *node, int indent,
\r
95 + const struct notmuch_show_params *params);
\r
96 const char *message_start;
\r
97 void (*message) (const void *ctx,
\r
98 notmuch_message_t *message,
\r
99 diff --git a/notmuch-show.c b/notmuch-show.c
\r
100 index 6a171a4..648f468 100644
\r
101 --- a/notmuch-show.c
\r
102 +++ b/notmuch-show.c
\r
105 format_headers_message_part_text (GMimeMessage *message);
\r
108 +static notmuch_status_t
\r
109 format_part_text (const void *ctx, mime_node_t *node,
\r
110 int indent, const notmuch_show_params_t *params);
\r
112 @@ -34,7 +34,7 @@ static const notmuch_show_format_t format_text = {
\r
113 .message_set_end = ""
\r
117 +static notmuch_status_t
\r
118 format_part_json_entry (const void *ctx, mime_node_t *node,
\r
119 int indent, const notmuch_show_params_t *params);
\r
121 @@ -562,7 +562,7 @@ format_part_content_raw (GMimeObject *part)
\r
122 g_object_unref(stream_stdout);
\r
126 +static notmuch_status_t
\r
127 format_part_text (const void *ctx, mime_node_t *node,
\r
128 int indent, const notmuch_show_params_t *params)
\r
130 @@ -650,6 +650,8 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
131 printf ("\fbody}\n");
\r
133 printf ("\f%s}\n", part_type);
\r
135 + return NOTMUCH_STATUS_SUCCESS;
\r
139 @@ -751,14 +753,16 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
140 printf ("%s}", terminator);
\r
144 +static notmuch_status_t
\r
145 format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),
\r
146 unused (const notmuch_show_params_t *params))
\r
148 format_part_json (ctx, node, TRUE);
\r
150 + return NOTMUCH_STATUS_SUCCESS;
\r
154 +static notmuch_status_t
\r
155 show_message (void *ctx,
\r
156 const notmuch_show_format_t *format,
\r
157 notmuch_message_t *message,
\r
158 @@ -768,14 +772,18 @@ show_message (void *ctx,
\r
159 if (format->part) {
\r
160 void *local = talloc_new (ctx);
\r
161 mime_node_t *root, *part;
\r
163 - if (mime_node_open (local, message, params->cryptoctx, params->decrypt,
\r
164 - &root) == NOTMUCH_STATUS_SUCCESS &&
\r
165 - (part = mime_node_seek_dfs (root, (params->part < 0 ?
\r
166 - 0 : params->part))))
\r
167 - format->part (local, part, indent, params);
\r
168 + notmuch_status_t status;
\r
170 + status = mime_node_open (local, message, params->cryptoctx,
\r
171 + params->decrypt, &root);
\r
174 + part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));
\r
176 + status = format->part (local, part, indent, params);
\r
178 talloc_free (local);
\r
183 if (params->part <= 0) {
\r
184 @@ -799,9 +807,11 @@ show_message (void *ctx,
\r
186 fputs (format->message_end, stdout);
\r
189 + return NOTMUCH_STATUS_SUCCESS;
\r
193 +static notmuch_status_t
\r
194 show_messages (void *ctx,
\r
195 const notmuch_show_format_t *format,
\r
196 notmuch_messages_t *messages,
\r
197 @@ -812,6 +822,7 @@ show_messages (void *ctx,
\r
198 notmuch_bool_t match;
\r
201 + notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
\r
203 fputs (format->message_set_start, stdout);
\r
205 @@ -832,17 +843,22 @@ show_messages (void *ctx,
\r
206 next_indent = indent;
\r
208 if (match || params->entire_thread) {
\r
209 - show_message (ctx, format, message, indent, params);
\r
210 + status = show_message (ctx, format, message, indent, params);
\r
211 + if (status && !res)
\r
213 next_indent = indent + 1;
\r
215 - fputs (format->message_set_sep, stdout);
\r
217 + fputs (format->message_set_sep, stdout);
\r
220 - show_messages (ctx,
\r
222 - notmuch_message_get_replies (message),
\r
225 + status = show_messages (ctx,
\r
227 + notmuch_message_get_replies (message),
\r
230 + if (status && !res)
\r
233 notmuch_message_destroy (message);
\r
235 @@ -850,6 +866,8 @@ show_messages (void *ctx,
\r
238 fputs (format->message_set_end, stdout);
\r
243 /* Formatted output of single message */
\r
244 @@ -914,13 +932,13 @@ do_show_single (void *ctx,
\r
252 - show_message (ctx, format, message, 0, params);
\r
253 + return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS;
\r
260 /* Formatted output of threads */
\r
261 @@ -934,6 +952,7 @@ do_show (void *ctx,
\r
262 notmuch_thread_t *thread;
\r
263 notmuch_messages_t *messages;
\r
264 int first_toplevel = 1;
\r
265 + notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
\r
267 fputs (format->message_set_start, stdout);
\r
269 @@ -953,7 +972,9 @@ do_show (void *ctx,
\r
270 fputs (format->message_set_sep, stdout);
\r
271 first_toplevel = 0;
\r
273 - show_messages (ctx, format, messages, 0, params);
\r
274 + status = show_messages (ctx, format, messages, 0, params);
\r
275 + if (status && !res)
\r
278 notmuch_thread_destroy (thread);
\r
280 @@ -961,7 +982,7 @@ do_show (void *ctx,
\r
282 fputs (format->message_set_end, stdout);
\r
285 + return res != NOTMUCH_STATUS_SUCCESS;
\r