[PATCH 06/13] show: Feed the sprinter down to part formatters
authorAustin Clements <amdragon@MIT.EDU>
Wed, 25 Jul 2012 02:34:46 +0000 (22:34 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:33 +0000 (09:48 -0800)
6e/87789c2f9fbf600ad010452a9a9e9914996482 [new file with mode: 0644]

diff --git a/6e/87789c2f9fbf600ad010452a9a9e9914996482 b/6e/87789c2f9fbf600ad010452a9a9e9914996482
new file mode 100644 (file)
index 0000000..767afc5
--- /dev/null
@@ -0,0 +1,335 @@
+Return-Path: <amdragon@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 71507431FAE\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Jul 2012 19:35:16 -0700 (PDT)\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 BtzVWpzIRCyh for <notmuch@notmuchmail.org>;\r
+       Tue, 24 Jul 2012 19:35:13 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+       [18.9.25.13])\r
+       by olra.theworths.org (Postfix) with ESMTP id 94D84431FDC\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Jul 2012 19:35:06 -0700 (PDT)\r
+X-AuditID: 1209190d-b7fd56d000000933-56-500f5b5993d5\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id A3.A4.02355.95B5F005; Tue, 24 Jul 2012 22:35:05 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6P2Z50n002601; \r
+       Tue, 24 Jul 2012 22:35:05 -0400\r
+Received: from drake.dyndns.org\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (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 q6P2Z2RQ025125\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 24 Jul 2012 22:35:04 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1StrRG-0004Zs-Gw; Tue, 24 Jul 2012 22:35:02 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 06/13] show: Feed the sprinter down to part formatters\r
+Date: Tue, 24 Jul 2012 22:34:46 -0400\r
+Message-Id: <1343183693-17134-7-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1343183693-17134-1-git-send-email-amdragon@mit.edu>\r
+References: <1343183693-17134-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsUixCmqrRsZzR9gcHa/msXehnZGi+s3ZzI7\r
+       MHks3rSfzePZqlvMAUxRXDYpqTmZZalF+nYJXBlXlj9gKXjhU3F0x2a2BsZ1tl2MnBwSAiYS\r
+       uw5eZYKwxSQu3FvP1sXIxSEksI9R4uTTu0wQzgZGiVmv17FAOI+YJJ7M/QyVmcsoMffEWlaQ\r
+       fjYBDYlt+5czgtgiAtISO+/OBoszC5hJzP05kQ3EFhZwk2jcOBdsH4uAqkTb8t8sIDavgIPE\r
+       vbn7oe6Ql3h6vw+snlPAUeL8koVgM4WAanoWX2OfwMi/gJFhFaNsSm6Vbm5iZk5xarJucXJi\r
+       Xl5qka6RXm5miV5qSukmRnAwSfLuYHx3UOkQowAHoxIP7+8nfAFCrIllxZW5hxglOZiURHkr\r
+       gvkDhPiS8lMqMxKLM+KLSnNSiw8xSnAwK4nwFoUB5XhTEiurUovyYVLSHCxK4rxXUm76Cwmk\r
+       J5akZqemFqQWwWRlODiUJHj3RwE1ChalpqdWpGXmlCCkmTg4QYbzAA3fDVLDW1yQmFucmQ6R\r
+       P8WoKCXOOxckIQCSyCjNg+uFRfsrRnGgV4Qh2nmAiQKu+xXQYCagwc/D+EAGlyQipKQaGE2O\r
+       pr+rXbMgnM/cTkG7oPCaJPO8giCW4EN/k+LN7LT+1SZeeqwiUeisym1rOesl/9SVeSZGW69N\r
+       0UovLbrcphQ/X83+3wMl1rDwvEnP7KqTPNVPtvsLthvfve32vLqysWxRdajmxjXLCgNK1Zv+\r
+       57NoWUX/mft6T5K217yZaoxeU9/2KrUosRRnJBpqMRcVJwIAh0GyItECAAA=\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: Wed, 25 Jul 2012 02:35:16 -0000\r
+\r
+There are several levels of function calls between where we create the\r
+sprinter and the call to the part formatter in show_message. This\r
+feeds the sprinter through all of them and into the part formatters.\r
+---\r
+ notmuch-client.h |    5 +++--\r
+ notmuch-reply.c  |    2 +-\r
+ notmuch-show.c   |   50 +++++++++++++++++++++++++++++---------------------\r
+ 3 files changed, 33 insertions(+), 24 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index e4172a2..8eeedf7 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -72,7 +72,7 @@ struct notmuch_show_params;\r
+ typedef struct notmuch_show_format {\r
+     sprinter_t *(*new_sprinter) (const void *ctx, FILE *stream);\r
+     const char *message_set_start;\r
+-    notmuch_status_t (*part) (const void *ctx,\r
++    notmuch_status_t (*part) (const void *ctx, sprinter_t *sprinter,\r
+                             struct mime_node *node, int indent,\r
+                             const struct notmuch_show_params *params);\r
+     const char *message_set_sep;\r
+@@ -179,7 +179,8 @@ notmuch_status_t\r
+ show_one_part (const char *filename, int part);\r
+ \r
+ void\r
+-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t output_body);\r
++format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
++                notmuch_bool_t first, notmuch_bool_t output_body);\r
+ \r
+ void\r
+ format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index e42ba79..07d4452 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -624,7 +624,7 @@ notmuch_reply_format_json(void *ctx,\r
+     /* Start the original */\r
+     printf (", \"original\": ");\r
+ \r
+-    format_part_json (ctx, node, TRUE, TRUE);\r
++    format_part_json (ctx, sp, node, TRUE, TRUE);\r
+ \r
+     /* End */\r
+     printf ("}\n");\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index d04943f..b258f65 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -23,7 +23,7 @@\r
+ #include "sprinter.h"\r
+ \r
+ static notmuch_status_t\r
+-format_part_text (const void *ctx, mime_node_t *node,\r
++format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+                 int indent, const notmuch_show_params_t *params);\r
+ \r
+ static const notmuch_show_format_t format_text = {\r
+@@ -32,7 +32,7 @@ static const notmuch_show_format_t format_text = {\r
+ };\r
+ \r
+ static notmuch_status_t\r
+-format_part_json_entry (const void *ctx, mime_node_t *node,\r
++format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+                       int indent, const notmuch_show_params_t *params);\r
+ \r
+ static const notmuch_show_format_t format_json = {\r
+@@ -45,7 +45,7 @@ static const notmuch_show_format_t format_json = {\r
+ };\r
+ \r
+ static notmuch_status_t\r
+-format_part_mbox (const void *ctx, mime_node_t *node,\r
++format_part_mbox (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+                 int indent, const notmuch_show_params_t *params);\r
+ \r
+ static const notmuch_show_format_t format_mbox = {\r
+@@ -54,7 +54,7 @@ static const notmuch_show_format_t format_mbox = {\r
+ };\r
+ \r
+ static notmuch_status_t\r
+-format_part_raw (unused (const void *ctx), mime_node_t *node,\r
++format_part_raw (unused (const void *ctx), sprinter_t *sp, mime_node_t *node,\r
+                unused (int indent),\r
+                unused (const notmuch_show_params_t *params));\r
+ \r
+@@ -471,7 +471,7 @@ format_part_sigstatus_json (mime_node_t *node)\r
+ #endif\r
+ \r
+ static notmuch_status_t\r
+-format_part_text (const void *ctx, mime_node_t *node,\r
++format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+                 int indent, const notmuch_show_params_t *params)\r
+ {\r
+     /* The disposition and content-type metadata are associated with\r
+@@ -553,7 +553,7 @@ format_part_text (const void *ctx, mime_node_t *node,\r
+     }\r
+ \r
+     for (i = 0; i < node->nchildren; i++)\r
+-      format_part_text (ctx, mime_node_child (node, i), indent, params);\r
++      format_part_text (ctx, sp, mime_node_child (node, i), indent, params);\r
+ \r
+     if (GMIME_IS_MESSAGE (node->part))\r
+       printf ("\fbody}\n");\r
+@@ -564,7 +564,8 @@ format_part_text (const void *ctx, mime_node_t *node,\r
+ }\r
+ \r
+ void\r
+-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t output_body)\r
++format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
++                notmuch_bool_t first, notmuch_bool_t output_body)\r
+ {\r
+     /* Any changes to the JSON format should be reflected in the file\r
+      * devel/schemata. */\r
+@@ -578,7 +579,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notm\r
+ \r
+       if (output_body) {\r
+           printf (", \"body\": [");\r
+-          format_part_json (ctx, mime_node_child (node, 0), first, TRUE);\r
++          format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
+           printf ("]");\r
+       }\r
+       printf ("}");\r
+@@ -659,16 +660,17 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notm\r
+     talloc_free (local);\r
+ \r
+     for (i = 0; i < node->nchildren; i++)\r
+-      format_part_json (ctx, mime_node_child (node, i), i == 0, TRUE);\r
++      format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);\r
+ \r
+     printf ("%s}", terminator);\r
+ }\r
+ \r
+ static notmuch_status_t\r
+-format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),\r
++format_part_json_entry (const void *ctx, sprinter_t *sp,\r
++                      mime_node_t *node, unused (int indent),\r
+                       const notmuch_show_params_t *params)\r
+ {\r
+-    format_part_json (ctx, node, TRUE, params->output_body);\r
++    format_part_json (ctx, sp, node, TRUE, params->output_body);\r
+ \r
+     return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
+@@ -679,7 +681,8 @@ format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),\r
+  * http://qmail.org/qmail-manual-html/man5/mbox.html\r
+  */\r
+ static notmuch_status_t\r
+-format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent),\r
++format_part_mbox (const void *ctx, unused (sprinter_t *sp), mime_node_t *node,\r
++                unused (int indent),\r
+                 unused (const notmuch_show_params_t *params))\r
+ {\r
+     notmuch_message_t *message = node->envelope_file;\r
+@@ -730,8 +733,8 @@ format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent),\r
+ }\r
+ \r
+ static notmuch_status_t\r
+-format_part_raw (unused (const void *ctx), mime_node_t *node,\r
+-               unused (int indent),\r
++format_part_raw (unused (const void *ctx), unused (sprinter_t *sp),\r
++               mime_node_t *node, unused (int indent),\r
+                unused (const notmuch_show_params_t *params))\r
+ {\r
+     if (node->envelope_file) {\r
+@@ -819,6 +822,7 @@ show_null_message (const notmuch_show_format_t *format)\r
+ static notmuch_status_t\r
+ show_message (void *ctx,\r
+             const notmuch_show_format_t *format,\r
++            sprinter_t *sp,\r
+             notmuch_message_t *message,\r
+             int indent,\r
+             notmuch_show_params_t *params)\r
+@@ -832,7 +836,7 @@ show_message (void *ctx,\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
++      status = format->part (local, sp, part, indent, params);\r
+   DONE:\r
+     talloc_free (local);\r
+     return status;\r
+@@ -841,6 +845,7 @@ show_message (void *ctx,\r
+ static notmuch_status_t\r
+ show_messages (void *ctx,\r
+              const notmuch_show_format_t *format,\r
++             sprinter_t *sp,\r
+              notmuch_messages_t *messages,\r
+              int indent,\r
+              notmuch_show_params_t *params)\r
+@@ -874,7 +879,7 @@ show_messages (void *ctx,\r
+       next_indent = indent;\r
+ \r
+       if ((match && (!excluded || !params->omit_excluded)) || params->entire_thread) {\r
+-          status = show_message (ctx, format, message, indent, params);\r
++          status = show_message (ctx, format, sp, message, indent, params);\r
+           if (status && !res)\r
+               res = status;\r
+           next_indent = indent + 1;\r
+@@ -886,7 +891,7 @@ show_messages (void *ctx,\r
+           fputs (format->message_set_sep, stdout);\r
+ \r
+       status = show_messages (ctx,\r
+-                              format,\r
++                              format, sp,\r
+                               notmuch_message_get_replies (message),\r
+                               next_indent,\r
+                               params);\r
+@@ -910,6 +915,7 @@ static int\r
+ do_show_single (void *ctx,\r
+               notmuch_query_t *query,\r
+               const notmuch_show_format_t *format,\r
++              sprinter_t *sp,\r
+               notmuch_show_params_t *params)\r
+ {\r
+     notmuch_messages_t *messages;\r
+@@ -930,7 +936,8 @@ do_show_single (void *ctx,\r
+ \r
+     notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH, 1);\r
+ \r
+-    return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS;\r
++    return show_message (ctx, format, sp, message, 0, params)\r
++      != NOTMUCH_STATUS_SUCCESS;\r
+ }\r
+ \r
+ /* Formatted output of threads */\r
+@@ -938,6 +945,7 @@ static int\r
+ do_show (void *ctx,\r
+        notmuch_query_t *query,\r
+        const notmuch_show_format_t *format,\r
++       sprinter_t *sp,\r
+        notmuch_show_params_t *params)\r
+ {\r
+     notmuch_threads_t *threads;\r
+@@ -965,7 +973,7 @@ do_show (void *ctx,\r
+           fputs (format->message_set_sep, stdout);\r
+       first_toplevel = 0;\r
+ \r
+-      status = show_messages (ctx, format, messages, 0, params);\r
++      status = show_messages (ctx, format, sp, messages, 0, params);\r
+       if (status && !res)\r
+           res = status;\r
+ \r
+@@ -1141,7 +1149,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ \r
+     /* If a single message is requested we do not use search_excludes. */\r
+     if (params.part >= 0)\r
+-      ret = do_show_single (ctx, query, format, &params);\r
++      ret = do_show_single (ctx, query, format, sprinter, &params);\r
+     else {\r
+       /* We always apply set the exclude flag. The\r
+        * exclude=true|false option controls whether or not we return\r
+@@ -1160,7 +1168,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+           params.omit_excluded = FALSE;\r
+       }\r
+ \r
+-      ret = do_show (ctx, query, format, &params);\r
++      ret = do_show (ctx, query, format, sprinter, &params);\r
+     }\r
+ \r
+     notmuch_crypto_cleanup (&params.crypto);\r
+-- \r
+1.7.10\r
+\r