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 5AE4A431FC0
\r
6 for <notmuch@notmuchmail.org>; Fri, 2 Mar 2012 21:20:32 -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 5hfOXLgIylXw for <notmuch@notmuchmail.org>;
\r
16 Fri, 2 Mar 2012 21:20:31 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 6CB59431FAE
\r
20 for <notmuch@notmuchmail.org>; Fri, 2 Mar 2012 21:20:31 -0800 (PST)
\r
21 X-AuditID: 12074424-b7fae6d000000906-54-4f51aa1ea17b
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id F2.BE.02310.E1AA15F4; Sat, 3 Mar 2012 00:20:30 -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 q235KT7I013524;
\r
27 Sat, 3 Mar 2012 00:20:29 -0500
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q235KSgv022241
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Sat, 3 Mar 2012 00:20:29 -0500 (EST)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1S3hOO-0000gv-Mk; Sat, 03 Mar 2012 00:20:28 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 1/5] show: Allow formatters to return errors
\r
41 Date: Sat, 3 Mar 2012 00:20:21 -0500
\r
42 Message-Id: <1330752025-2542-2-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.7.3
\r
44 In-Reply-To: <1330752025-2542-1-git-send-email-amdragon@mit.edu>
\r
45 References: <1330752025-2542-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrCu3KtDfYMN1S4vrN2cyOzB6PFt1
\r
48 izmAMYrLJiU1J7MstUjfLoEr4+20E2wFa/QrVlw8xNjAuE6li5GTQ0LARGLm5J3MELaYxIV7
\r
49 69lAbCGBfYwSP3/zdDFyAdnrGSUePn3IDpG4xyTx63YMRGI+o8TJh4eYQBJsAhoS2/YvZwSx
\r
50 RQSkJXbenc3axcjBwSygJvGnC2yZsICNRM+Wn2DlLAKqEit2fABbxitgLzF5dRc7xBEKEudW
\r
51 nwOzOQUcJFqOH2OF2Gsv8aO/k2UCI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFuuZ6uZkl
\r
52 eqkppZsYQSHD7qKyg7H5kNIhRgEORiUe3osvA/yFWBPLiitzDzFKcjApifKWLw/0F+JLyk+p
\r
53 zEgszogvKs1JLT7EKMHBrCTCu8wTKMebklhZlVqUD5OS5mBREufV0HrnJySQnliSmp2aWpBa
\r
54 BJOV4eBQkuCdthKoUbAoNT21Ii0zpwQhzcTBCTKcB2h4K0gNb3FBYm5xZjpE/hSjopQ4by5I
\r
55 QgAkkVGaB9cLi+lXjOJArwjz9oNU8QDTAVz3K6DBTECDF1/2AxlckoiQkmpgFBLcl+hbP/2e
\r
56 +02hB6K3D8m9+rtgY1XefcbP7zQUnrLeZvjxKlLGqyhvj/R6870Jhi/4LkW8yprC9d8x/cMz
\r
57 f03/HSK/OjQs5kw3uWcl7/tCu2bNhOly8S0NJbzrTsxKa4m1iWcvFJ1XuO3m8VebXsZYPBMO
\r
58 4ggV7/vn7NNnfO9vk9RRnyOblFiKMxINtZiLihMBcvYVqsQCAAA=
\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: Sat, 03 Mar 2012 05:20:32 -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 | 69 +++++++++++++++++++++++++++++++++++------------------
\r
80 2 files changed, 48 insertions(+), 27 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
162 + notmuch_status_t status;
\r
164 - if (mime_node_open (local, message, params->cryptoctx, params->decrypt,
\r
165 - &root) == NOTMUCH_STATUS_SUCCESS &&
\r
166 - (part = mime_node_seek_dfs (root, (params->part < 0 ?
\r
167 - 0 : params->part))))
\r
168 - format->part (local, part, indent, params);
\r
169 + status = mime_node_open (local, message, params->cryptoctx,
\r
170 + params->decrypt, &root);
\r
173 + part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));
\r
175 + status = format->part (local, part, indent, params);
\r
177 talloc_free (local);
\r
182 if (params->part <= 0) {
\r
183 @@ -799,9 +807,11 @@ show_message (void *ctx,
\r
185 fputs (format->message_end, stdout);
\r
188 + return NOTMUCH_STATUS_SUCCESS;
\r
192 +static notmuch_status_t
\r
193 show_messages (void *ctx,
\r
194 const notmuch_show_format_t *format,
\r
195 notmuch_messages_t *messages,
\r
196 @@ -812,6 +822,7 @@ show_messages (void *ctx,
\r
197 notmuch_bool_t match;
\r
200 + notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
\r
202 fputs (format->message_set_start, stdout);
\r
204 @@ -832,17 +843,22 @@ show_messages (void *ctx,
\r
205 next_indent = indent;
\r
207 if (match || params->entire_thread) {
\r
208 - show_message (ctx, format, message, indent, params);
\r
209 + status = show_message (ctx, format, message, indent, params);
\r
210 + if (status && !res)
\r
212 next_indent = indent + 1;
\r
214 - fputs (format->message_set_sep, stdout);
\r
216 + fputs (format->message_set_sep, stdout);
\r
219 - show_messages (ctx,
\r
221 - notmuch_message_get_replies (message),
\r
224 + status = show_messages (ctx,
\r
226 + notmuch_message_get_replies (message),
\r
229 + if (status && !res)
\r
232 notmuch_message_destroy (message);
\r
234 @@ -850,6 +866,8 @@ show_messages (void *ctx,
\r
237 fputs (format->message_set_end, stdout);
\r
242 /* Formatted output of single message */
\r
243 @@ -914,13 +932,13 @@ do_show_single (void *ctx,
\r
251 - show_message (ctx, format, message, 0, params);
\r
252 + return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS;
\r
259 /* Formatted output of threads */
\r
260 @@ -934,6 +952,7 @@ do_show (void *ctx,
\r
261 notmuch_thread_t *thread;
\r
262 notmuch_messages_t *messages;
\r
263 int first_toplevel = 1;
\r
264 + notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
\r
266 fputs (format->message_set_start, stdout);
\r
268 @@ -953,7 +972,9 @@ do_show (void *ctx,
\r
269 fputs (format->message_set_sep, stdout);
\r
270 first_toplevel = 0;
\r
272 - show_messages (ctx, format, messages, 0, params);
\r
273 + status = show_messages (ctx, format, messages, 0, params);
\r
274 + if (status && !res)
\r
277 notmuch_thread_destroy (thread);
\r
279 @@ -961,7 +982,7 @@ do_show (void *ctx,
\r
281 fputs (format->message_set_end, stdout);
\r
284 + return res != NOTMUCH_STATUS_SUCCESS;
\r