[PATCH v2 3/8] show: Allow formatters to return errors
authorAustin Clements <amdragon@MIT.EDU>
Tue, 6 Mar 2012 18:48:39 +0000 (18:48 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:16 +0000 (09:45 -0800)
4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0 [new file with mode: 0644]

diff --git a/4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0 b/4e/9b7a4b5a4e8414edb9dc182c900d7808345aa0
new file mode 100644 (file)
index 0000000..e26f3bb
--- /dev/null
@@ -0,0 +1,291 @@
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A96FC429E29\r
+       for <notmuch@notmuchmail.org>; Tue,  6 Mar 2012 10:48:55 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 1e7IRtpcixha for <notmuch@notmuchmail.org>;\r
+       Tue,  6 Mar 2012 10:48:53 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+       [18.9.25.12])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2CD28431FC9\r
+       for <notmuch@notmuchmail.org>; Tue,  6 Mar 2012 10:48:52 -0800 (PST)\r
+X-AuditID: 1209190c-b7fad6d000000920-57-4f565c13c9aa\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id D1.1D.02336.31C565F4; Tue,  6 Mar 2012 13:48:51 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q26ImoRK016036; \r
+       Tue, 6 Mar 2012 13:48:50 -0500\r
+Received: from drake.mit.edu (firewall.royalsociety.org [193.63.75.2])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q26Imm4N016463\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 6 Mar 2012 13:48:50 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1S4zRI-0003pM-2D; Tue, 06 Mar 2012 18:48:48 +0000\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 3/8] show: Allow formatters to return errors\r
+Date: Tue,  6 Mar 2012 18:48:39 +0000\r
+Message-Id: <1331059724-14653-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1331059724-14653-1-git-send-email-amdragon@mit.edu>\r
+References: <1330752025-2542-1-git-send-email-amdragon@mit.edu>\r
+       <1331059724-14653-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrJIsWRmVeSWpSXmKPExsUixCmqrCscE+ZvcHirusWefV4W12/OZHZg\r
+       8rh7msvj2apbzAFMUVw2Kak5mWWpRfp2CVwZ65rWMhZs0K/omraaqYFxo0oXIyeHhICJxKZF\r
+       P5ghbDGJC/fWs4HYQgL7GCX+fzDrYuQCstczStz5uZoZwjnIJDH9xFk2CGc+o8TMr/OYQFrY\r
+       BDQktu1fzghiiwhIS+y8O5u1i5GDg1nASaKtzQvEFBawl5j7mQekgkVAVWLi6hVg1bwCDhJ9\r
+       L/4xQRyhIHFu9Tl2EJtTwFFiz9NNjBAHlUlcunmBZQIj/wJGhlWMsim5Vbq5iZk5xanJusXJ\r
+       iXl5qUW6hnq5mSV6qSmlmxjBISTJs4PxzUGlQ4wCHIxKPLwX9cP8hVgTy4orcw8xSnIwKYny\r
+       5kQBhfiS8lMqMxKLM+KLSnNSiw8xSnAwK4nwfnsf6i/Em5JYWZValA+TkuZgURLnVdF65yck\r
+       kJ5YkpqdmlqQWgSTleHgUJLgzYgGGipYlJqeWpGWmVOCkGbi4AQZzgM03Aikhre4IDG3ODMd\r
+       In+KUVFKnNcPJCEAksgozYPrhcX4K0ZxoFeEeR1BqniA6QGu+xXQYCagwW3KwSCDSxIRUlIN\r
+       jHHvHmTor1hvWHKpLjb3R+cG474u1t8vtjR7z8+79mdV5UnP6dxtanmC8/4eXjPbpmBRlvHv\r
+       h2dvs29JmO8nLX/S9qStS7L/5G9SV5kqHKdyvb5x+vC5Xrlbi7zF2Z3nJAbz9Sj5mcx6oXl/\r
+       0tLf0T/Xr37MwrD5/NQopqKK3DwVN8OGC/xiP5VYijMSDbWYi4oTAWcLH8nMAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 06 Mar 2012 18:48:56 -0000\r
+\r
+Formatter errors are propagated to the exit status of notmuch show.\r
+\r
+This isn't used by the JSON or text formatters, but it will be useful\r
+for the raw format, which is pickier.\r
+---\r
+ notmuch-client.h |    6 ++--\r
+ notmuch-show.c   |   71 +++++++++++++++++++++++++++++++++++-------------------\r
+ 2 files changed, 49 insertions(+), 28 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index f4a62cc..a220fe4 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -67,9 +67,9 @@ struct notmuch_show_params;\r
\r
+ typedef struct notmuch_show_format {\r
+     const char *message_set_start;\r
+-    void (*part) (const void *ctx,\r
+-                struct mime_node *node, int indent,\r
+-                const struct notmuch_show_params *params);\r
++    notmuch_status_t (*part) (const void *ctx,\r
++                            struct mime_node *node, int indent,\r
++                            const struct notmuch_show_params *params);\r
+     const char *message_start;\r
+     void (*message) (const void *ctx,\r
+                    notmuch_message_t *message,\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 6a171a4..648f468 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -23,7 +23,7 @@\r
+ static void\r
+ format_headers_message_part_text (GMimeMessage *message);\r
\r
+-static void\r
++static notmuch_status_t\r
+ format_part_text (const void *ctx, mime_node_t *node,\r
+                 int indent, const notmuch_show_params_t *params);\r
\r
+@@ -34,7 +34,7 @@ static const notmuch_show_format_t format_text = {\r
+     .message_set_end = ""\r
+ };\r
\r
+-static void\r
++static notmuch_status_t\r
+ format_part_json_entry (const void *ctx, mime_node_t *node,\r
+                       int indent, const notmuch_show_params_t *params);\r
\r
+@@ -562,7 +562,7 @@ format_part_content_raw (GMimeObject *part)\r
+       g_object_unref(stream_stdout);\r
+ }\r
\r
+-static void\r
++static notmuch_status_t\r
+ format_part_text (const void *ctx, mime_node_t *node,\r
+                 int indent, const notmuch_show_params_t *params)\r
+ {\r
+@@ -650,6 +650,8 @@ format_part_text (const void *ctx, mime_node_t *node,\r
+       printf ("\fbody}\n");\r
\r
+     printf ("\f%s}\n", part_type);\r
++\r
++    return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
\r
+ static void\r
+@@ -751,14 +753,16 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
+     printf ("%s}", terminator);\r
+ }\r
\r
+-static void\r
++static notmuch_status_t\r
+ format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),\r
+                       unused (const notmuch_show_params_t *params))\r
+ {\r
+     format_part_json (ctx, node, TRUE);\r
++\r
++    return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
\r
+-static void\r
++static notmuch_status_t\r
+ show_message (void *ctx,\r
+             const notmuch_show_format_t *format,\r
+             notmuch_message_t *message,\r
+@@ -768,14 +772,18 @@ show_message (void *ctx,\r
+     if (format->part) {\r
+       void *local = talloc_new (ctx);\r
+       mime_node_t *root, *part;\r
+-\r
+-      if (mime_node_open (local, message, params->cryptoctx, params->decrypt,\r
+-                          &root) == NOTMUCH_STATUS_SUCCESS &&\r
+-          (part = mime_node_seek_dfs (root, (params->part < 0 ?\r
+-                                             0 : params->part))))\r
+-          format->part (local, part, indent, params);\r
++      notmuch_status_t status;\r
++\r
++      status = mime_node_open (local, message, params->cryptoctx,\r
++                               params->decrypt, &root);\r
++      if (status)\r
++          goto DONE;\r
++      part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));\r
++      if (part)\r
++          status = format->part (local, part, indent, params);\r
++      DONE:\r
+       talloc_free (local);\r
+-      return;\r
++      return status;\r
+     }\r
\r
+     if (params->part <= 0) {\r
+@@ -799,9 +807,11 @@ show_message (void *ctx,\r
\r
+       fputs (format->message_end, stdout);\r
+     }\r
++\r
++    return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
\r
+-static void\r
++static notmuch_status_t\r
+ show_messages (void *ctx,\r
+              const notmuch_show_format_t *format,\r
+              notmuch_messages_t *messages,\r
+@@ -812,6 +822,7 @@ show_messages (void *ctx,\r
+     notmuch_bool_t match;\r
+     int first_set = 1;\r
+     int next_indent;\r
++    notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;\r
\r
+     fputs (format->message_set_start, stdout);\r
\r
+@@ -832,17 +843,22 @@ show_messages (void *ctx,\r
+       next_indent = indent;\r
\r
+       if (match || params->entire_thread) {\r
+-          show_message (ctx, format, message, indent, params);\r
++          status = show_message (ctx, format, message, indent, params);\r
++          if (status && !res)\r
++              res = status;\r
+           next_indent = indent + 1;\r
\r
+-          fputs (format->message_set_sep, stdout);\r
++          if (!status)\r
++              fputs (format->message_set_sep, stdout);\r
+       }\r
\r
+-      show_messages (ctx,\r
+-                     format,\r
+-                     notmuch_message_get_replies (message),\r
+-                     next_indent,\r
+-                     params);\r
++      status = show_messages (ctx,\r
++                              format,\r
++                              notmuch_message_get_replies (message),\r
++                              next_indent,\r
++                              params);\r
++      if (status && !res)\r
++          res = status;\r
\r
+       notmuch_message_destroy (message);\r
\r
+@@ -850,6 +866,8 @@ show_messages (void *ctx,\r
+     }\r
\r
+     fputs (format->message_set_end, stdout);\r
++\r
++    return res;\r
+ }\r
\r
+ /* Formatted output of single message */\r
+@@ -914,13 +932,13 @@ do_show_single (void *ctx,\r
\r
+       fclose (file);\r
\r
++      return 0;\r
++\r
+     } else {\r
\r
+-      show_message (ctx, format, message, 0, params);\r
++      return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS;\r
\r
+     }\r
+-\r
+-    return 0;\r
+ }\r
\r
+ /* Formatted output of threads */\r
+@@ -934,6 +952,7 @@ do_show (void *ctx,\r
+     notmuch_thread_t *thread;\r
+     notmuch_messages_t *messages;\r
+     int first_toplevel = 1;\r
++    notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;\r
\r
+     fputs (format->message_set_start, stdout);\r
\r
+@@ -953,7 +972,9 @@ do_show (void *ctx,\r
+           fputs (format->message_set_sep, stdout);\r
+       first_toplevel = 0;\r
\r
+-      show_messages (ctx, format, messages, 0, params);\r
++      status = show_messages (ctx, format, messages, 0, params);\r
++      if (status && !res)\r
++          res = status;\r
\r
+       notmuch_thread_destroy (thread);\r
\r
+@@ -961,7 +982,7 @@ do_show (void *ctx,\r
\r
+     fputs (format->message_set_end, stdout);\r
\r
+-    return 0;\r
++    return res != NOTMUCH_STATUS_SUCCESS;\r
+ }\r
\r
+ enum {\r
+-- \r
+1.7.7.3\r
+\r