--- /dev/null
+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 04A09429E36\r
+ for <notmuch@notmuchmail.org>; Thu, 2 Aug 2012 18:15:09 -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 R0YazFFrYvgF for <notmuch@notmuchmail.org>;\r
+ Thu, 2 Aug 2012 18:15:08 -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 DEFBC431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 2 Aug 2012 18:15:07 -0700 (PDT)\r
+X-AuditID: 1209190d-b7fd56d000000933-d2-501b261be0a9\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 69.7E.02355.B162B105; Thu, 2 Aug 2012 21:15:07 -0400 (EDT)\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 q731F6d3012767; \r
+ Thu, 2 Aug 2012 21:15:06 -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 q731F42H002793\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Thu, 2 Aug 2012 21:15:05 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Sx6To-0003wX-FS; Thu, 02 Aug 2012 21:15:04 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 10/13] show: Convert envelope format_part_json to use\r
+ sprinter\r
+Date: Thu, 2 Aug 2012 21:14:56 -0400\r
+Message-Id: <1343956499-14543-11-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1343956499-14543-1-git-send-email-amdragon@mit.edu>\r
+References: <1343956499-14543-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixCmqrCutJh1g0H9a3mL1XB6L6zdnMlu8\r
+ WTmP1YHZY+esu+weh78uZPF4tuoWcwBzFJdNSmpOZllqkb5dAlfGuQX/2AveSVWsPzaJqYFx\r
+ oWgXIyeHhICJxKwfJxkhbDGJC/fWs3UxcnEICexjlPg6cSsrhLOeUeL49E1QmYdMEi8mzGCG\r
+ cOYySjTP7GEF6WcT0JDYtn852CwRAWmJnXdng8WZBeIktkz5DxYXFgiU2PbhBZjNIqAqMf/G\r
+ IqCpHBy8Ao4S905FQpwhL/H0fh8biM0JFH799hVYuZCAg8Tytm7WCYz8CxgZVjHKpuRW6eYm\r
+ ZuYUpybrFicn5uWlFuka6eVmluilppRuYgQHlyTvDsZ3B5UOMQpwMCrx8JpISgcIsSaWFVfm\r
+ HmKU5GBSEuVlVgIK8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuGtWiIVIMSbklhZlVqUD5OS5mBR\r
+ Eue9knLTX0ggPbEkNTs1tSC1CCYrw8GhJMEbrAo0VLAoNT21Ii0zpwQhzcTBCTKcB2i4PUgN\r
+ b3FBYm5xZjpE/hSjopQ4bzpIQgAkkVGaB9cLi/5XjOJArwjzeoFU8QATB1z3K6DBTECD7cxA\r
+ ri4uSURISTUwiqpMCrv5m8f2z/YEBXtLtkcPL7yYNG3G4dbAgolib3KNHrs833B9vWbQEfFn\r
+ J95+E7dVuyw4QXd6kuWpWWbn5Y+JZPxZ/DVZ9KHL3nCZEu548SyrJ65pwj9iOUqNbry+sPXw\r
+ f+l1YaceeWe0Lfmz4/gj8zuXjnkJJS5t2bHa5VtwmUFZrKS6rxJLcUaioRZzUXEiADNrQvbZ AgAA\r
+Cc: tomi.ollila@iki.fi\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: Fri, 03 Aug 2012 01:15:09 -0000\r
+\r
+---\r
+ notmuch-show.c | 57 +++++++++++++++++++++++++++++++++-----------------------\r
+ 1 file changed, 34 insertions(+), 23 deletions(-)\r
+\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index afbd9d0..b9d9f5d 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -109,35 +109,45 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)\r
+ from, relative_date, tags);\r
+ }\r
+ \r
++/* Emit a sequence of key/value pairs for the metadata of message.\r
++ * The caller should begin a map before calling this. */\r
+ static void\r
+-format_message_json (const void *ctx, notmuch_message_t *message)\r
++format_message_json (sprinter_t *sp, notmuch_message_t *message)\r
+ {\r
++ void *local = talloc_new (NULL);\r
+ notmuch_tags_t *tags;\r
+- int first = 1;\r
+- void *ctx_quote = talloc_new (ctx);\r
+ time_t date;\r
+ const char *relative_date;\r
+ \r
++ sp->map_key (sp, "id");\r
++ sp->string (sp, notmuch_message_get_message_id (message));\r
++\r
++ sp->map_key (sp, "match");\r
++ sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH));\r
++\r
++ sp->map_key (sp, "excluded");\r
++ sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED));\r
++\r
++ sp->map_key (sp, "filename");\r
++ sp->string (sp, notmuch_message_get_filename (message));\r
++\r
++ sp->map_key (sp, "timestamp");\r
+ date = notmuch_message_get_date (message);\r
+- relative_date = notmuch_time_relative_date (ctx, date);\r
++ sp->integer (sp, date);\r
+ \r
+- printf ("\"id\": %s, \"match\": %s, \"excluded\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [",\r
+- json_quote_str (ctx_quote, notmuch_message_get_message_id (message)),\r
+- notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? "true" : "false",\r
+- notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? "true" : "false",\r
+- json_quote_str (ctx_quote, notmuch_message_get_filename (message)),\r
+- date, relative_date);\r
++ sp->map_key (sp, "date_relative");\r
++ relative_date = notmuch_time_relative_date (local, date);\r
++ sp->string (sp, relative_date);\r
+ \r
++ sp->map_key (sp, "tags");\r
++ sp->begin_list (sp);\r
+ for (tags = notmuch_message_get_tags (message);\r
+ notmuch_tags_valid (tags);\r
+ notmuch_tags_move_to_next (tags))\r
+- {\r
+- printf("%s%s", first ? "" : ",",\r
+- json_quote_str (ctx_quote, notmuch_tags_get (tags)));\r
+- first = 0;\r
+- }\r
+- printf("], ");\r
+- talloc_free (ctx_quote);\r
++ sp->string (sp, notmuch_tags_get (tags));\r
++ sp->end (sp);\r
++\r
++ talloc_free (local);\r
+ }\r
+ \r
+ /* Extract just the email address from the contents of a From:\r
+@@ -573,18 +583,19 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+ * devel/schemata. */\r
+ \r
+ if (node->envelope_file) {\r
+- printf ("{");\r
+- format_message_json (ctx, node->envelope_file);\r
++ sp->begin_map (sp);\r
++ format_message_json (sp, node->envelope_file);\r
+ \r
+- printf ("\"headers\": ");\r
++ sp->map_key (sp, "headers");\r
+ format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
+ \r
+ if (output_body) {\r
+- printf (", \"body\": [");\r
++ sp->map_key (sp, "body");\r
++ sp->begin_list (sp);\r
+ format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
+- printf ("]");\r
++ sp->end (sp);\r
+ }\r
+- printf ("}");\r
++ sp->end (sp);\r
+ return;\r
+ }\r
+ \r
+-- \r
+1.7.10\r
+\r