From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 5AE4A431FC0 for ; Fri, 2 Mar 2012 21:20:32 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5hfOXLgIylXw for ; Fri, 2 Mar 2012 21:20:31 -0800 (PST) Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU [18.7.68.36]) by olra.theworths.org (Postfix) with ESMTP id 6CB59431FAE for ; Fri, 2 Mar 2012 21:20:31 -0800 (PST) X-AuditID: 12074424-b7fae6d000000906-54-4f51aa1ea17b Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id F2.BE.02310.E1AA15F4; Sat, 3 Mar 2012 00:20:30 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q235KT7I013524; Sat, 3 Mar 2012 00:20:29 -0500 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q235KSgv022241 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 3 Mar 2012 00:20:29 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1S3hOO-0000gv-Mk; Sat, 03 Mar 2012 00:20:28 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 1/5] show: Allow formatters to return errors Date: Sat, 3 Mar 2012 00:20:21 -0500 Message-Id: <1330752025-2542-2-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1330752025-2542-1-git-send-email-amdragon@mit.edu> References: <1330752025-2542-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrCu3KtDfYMN1S4vrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEr4+20E2wFa/QrVlw8xNjAuE6li5GTQ0LARGLm5J3MELaYxIV7 69lAbCGBfYwSP3/zdDFyAdnrGSUePn3IDpG4xyTx63YMRGI+o8TJh4eYQBJsAhoS2/YvZwSx RQSkJXbenc3axcjBwSygJvGnC2yZsICNRM+Wn2DlLAKqEit2fABbxitgLzF5dRc7xBEKEudW nwOzOQUcJFqOH2OF2Gsv8aO/k2UCI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFuuZ6uZkl eqkppZsYQSHD7qKyg7H5kNIhRgEORiUe3osvA/yFWBPLiitzDzFKcjApifKWLw/0F+JLyk+p zEgszogvKs1JLT7EKMHBrCTCu8wTKMebklhZlVqUD5OS5mBREufV0HrnJySQnliSmp2aWpBa BJOV4eBQkuCdthKoUbAoNT21Ii0zpwQhzcTBCTKcB2h4K0gNb3FBYm5xZjpE/hSjopQ4by5I QgAkkVGaB9cLi+lXjOJArwjz9oNU8QDTAVz3K6DBTECDF1/2AxlckoiQkmpgFBLcl+hbP/2e +02hB6K3D8m9+rtgY1XefcbP7zQUnrLeZvjxKlLGqyhvj/R6870Jhi/4LkW8yprC9d8x/cMz f03/HSK/OjQs5kw3uWcl7/tCu2bNhOly8S0NJbzrTsxKa4m1iWcvFJ1XuO3m8VebXsZYPBMO 4ggV7/vn7NNnfO9vk9RRnyOblFiKMxINtZiLihMBcvYVqsQCAAA= X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Mar 2012 05:20:32 -0000 Formatter errors are propagated to the exit status of notmuch show. This isn't used by the JSON or text formatters, but it will be useful for the raw format, which is pickier. --- notmuch-client.h | 6 ++-- notmuch-show.c | 69 +++++++++++++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index f4a62cc..a220fe4 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -67,9 +67,9 @@ struct notmuch_show_params; typedef struct notmuch_show_format { const char *message_set_start; - void (*part) (const void *ctx, - struct mime_node *node, int indent, - const struct notmuch_show_params *params); + notmuch_status_t (*part) (const void *ctx, + struct mime_node *node, int indent, + const struct notmuch_show_params *params); const char *message_start; void (*message) (const void *ctx, notmuch_message_t *message, diff --git a/notmuch-show.c b/notmuch-show.c index 6a171a4..648f468 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -23,7 +23,7 @@ static void format_headers_message_part_text (GMimeMessage *message); -static void +static notmuch_status_t format_part_text (const void *ctx, mime_node_t *node, int indent, const notmuch_show_params_t *params); @@ -34,7 +34,7 @@ static const notmuch_show_format_t format_text = { .message_set_end = "" }; -static void +static notmuch_status_t format_part_json_entry (const void *ctx, mime_node_t *node, int indent, const notmuch_show_params_t *params); @@ -562,7 +562,7 @@ format_part_content_raw (GMimeObject *part) g_object_unref(stream_stdout); } -static void +static notmuch_status_t format_part_text (const void *ctx, mime_node_t *node, int indent, const notmuch_show_params_t *params) { @@ -650,6 +650,8 @@ format_part_text (const void *ctx, mime_node_t *node, printf ("\fbody}\n"); printf ("\f%s}\n", part_type); + + return NOTMUCH_STATUS_SUCCESS; } static void @@ -751,14 +753,16 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) printf ("%s}", terminator); } -static void +static notmuch_status_t format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent), unused (const notmuch_show_params_t *params)) { format_part_json (ctx, node, TRUE); + + return NOTMUCH_STATUS_SUCCESS; } -static void +static notmuch_status_t show_message (void *ctx, const notmuch_show_format_t *format, notmuch_message_t *message, @@ -768,14 +772,18 @@ show_message (void *ctx, if (format->part) { void *local = talloc_new (ctx); mime_node_t *root, *part; + notmuch_status_t status; - if (mime_node_open (local, message, params->cryptoctx, params->decrypt, - &root) == NOTMUCH_STATUS_SUCCESS && - (part = mime_node_seek_dfs (root, (params->part < 0 ? - 0 : params->part)))) - format->part (local, part, indent, params); + status = mime_node_open (local, message, params->cryptoctx, + params->decrypt, &root); + if (status) + goto DONE; + part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part)); + if (part) + status = format->part (local, part, indent, params); + DONE: talloc_free (local); - return; + return status; } if (params->part <= 0) { @@ -799,9 +807,11 @@ show_message (void *ctx, fputs (format->message_end, stdout); } + + return NOTMUCH_STATUS_SUCCESS; } -static void +static notmuch_status_t show_messages (void *ctx, const notmuch_show_format_t *format, notmuch_messages_t *messages, @@ -812,6 +822,7 @@ show_messages (void *ctx, notmuch_bool_t match; int first_set = 1; int next_indent; + notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; fputs (format->message_set_start, stdout); @@ -832,17 +843,22 @@ show_messages (void *ctx, next_indent = indent; if (match || params->entire_thread) { - show_message (ctx, format, message, indent, params); + status = show_message (ctx, format, message, indent, params); + if (status && !res) + res = status; next_indent = indent + 1; - fputs (format->message_set_sep, stdout); + if (!status) + fputs (format->message_set_sep, stdout); } - show_messages (ctx, - format, - notmuch_message_get_replies (message), - next_indent, - params); + status = show_messages (ctx, + format, + notmuch_message_get_replies (message), + next_indent, + params); + if (status && !res) + res = status; notmuch_message_destroy (message); @@ -850,6 +866,8 @@ show_messages (void *ctx, } fputs (format->message_set_end, stdout); + + return res; } /* Formatted output of single message */ @@ -914,13 +932,13 @@ do_show_single (void *ctx, fclose (file); + return 0; + } else { - show_message (ctx, format, message, 0, params); + return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS; } - - return 0; } /* Formatted output of threads */ @@ -934,6 +952,7 @@ do_show (void *ctx, notmuch_thread_t *thread; notmuch_messages_t *messages; int first_toplevel = 1; + notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; fputs (format->message_set_start, stdout); @@ -953,7 +972,9 @@ do_show (void *ctx, fputs (format->message_set_sep, stdout); first_toplevel = 0; - show_messages (ctx, format, messages, 0, params); + status = show_messages (ctx, format, messages, 0, params); + if (status && !res) + res = status; notmuch_thread_destroy (thread); @@ -961,7 +982,7 @@ do_show (void *ctx, fputs (format->message_set_end, stdout); - return 0; + return res != NOTMUCH_STATUS_SUCCESS; } enum { -- 1.7.7.3