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 A8E89429E26 for ; Thu, 2 Aug 2012 18:15:17 -0700 (PDT) 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 M6YOMiHoGwKt for ; Thu, 2 Aug 2012 18:15:16 -0700 (PDT) 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 10452429E37 for ; Thu, 2 Aug 2012 18:15:09 -0700 (PDT) X-AuditID: 12074424-b7fa06d0000008c2-c8-501b261bab39 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP id E5.5C.02242.B162B105; Thu, 2 Aug 2012 21:15:07 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q731F6eq008873; Thu, 2 Aug 2012 21:15:06 -0400 Received: from drake.dyndns.org (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 q731F4Eg002792 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 2 Aug 2012 21:15:05 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1Sx6To-0003wU-Dm; Thu, 02 Aug 2012 21:15:04 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 09/13] show: Convert non-envelope format_part_json to use sprinter Date: Thu, 2 Aug 2012 21:14:55 -0400 Message-Id: <1343956499-14543-10-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1343956499-14543-1-git-send-email-amdragon@mit.edu> References: <1343956499-14543-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsUixG6nriutJh1g0NhvarF6Lo/F9ZszmS3e rJzH6sDssXPWXXaPw18Xsng8W3WLOYA5issmJTUnsyy1SN8ugSvj1JvHLAUblSqa/55iamCc KN3FyMkhIWAi8eXxQmYIW0ziwr31bF2MXBxCAvsYJSaffMQI4axnlLj5/gOU85BJ4v+F26wQ zlxGiUkrJzKC9LMJaEhs278czBYRkJbYeXc2K4jNLBAnsWXKf7C4sECoxKTF/8D2sQioShx4 /w6shlfAUWLhtStQd8hLPL3fxwZicwLFX799BdYrJOAgsbytm3UCI/8CRoZVjLIpuVW6uYmZ OcWpybrFyYl5ealFuuZ6uZkleqkppZsYweHlorKDsfmQ0iFGAQ5GJR5eI0npACHWxLLiytxD jJIcTEqivMxKQCG+pPyUyozE4oz4otKc1OJDjBIczEoivFVLpAKEeFMSK6tSi/JhUtIcLEri vNdTbvoLCaQnlqRmp6YWpBbBZGU4OJQkeINVgYYKFqWmp1akZeaUIKSZODhBhvMADbcHqeEt LkjMLc5Mh8ifYlSUEudNB0kIgCQySvPgemHx/4pRHOgVYV4vkCoeYOqA634FNJgJaLCdGcjV xSWJCCmpBsayRpvM3rC9nIwaC54U33yuF5MQ5dFutmfroftHNLIE9l3KPNd8LsV1/aN6A+tr NmJcr+6yJJ1byPzR6MO979MkBeYulLFZPm3BMeku+WVHq26FVJqk5a8v/NW9y26R03x+NzER 9i8quzameyrMbfxg47C5ytvs8GeduawKDFLPLljFrgro26XEUpyRaKjFXFScCADd37zY2gIA AA== Cc: tomi.ollila@iki.fi 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: Fri, 03 Aug 2012 01:15:18 -0000 --- notmuch-show.c | 74 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/notmuch-show.c b/notmuch-show.c index 3ff32df..afbd9d0 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -588,7 +588,6 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, return; } - void *local = talloc_new (ctx); /* The disposition and content-type metadata are associated with * the envelope for message parts */ GMimeObject *meta = node->envelope_part ? @@ -597,31 +596,41 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, const char *cid = g_mime_object_get_content_id (meta); const char *filename = GMIME_IS_PART (node->part) ? g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; - const char *terminator = ""; + int nclose = 0; int i; - if (!first) - printf (", "); + sp->begin_map (sp); - printf ("{\"id\": %d", node->part_num); + sp->map_key (sp, "id"); + sp->integer (sp, node->part_num); - if (node->decrypt_attempted) - printf (", \"encstatus\": [{\"status\": \"%s\"}]", - node->decrypt_success ? "good" : "bad"); + if (node->decrypt_attempted) { + sp->map_key (sp, "encstatus"); + sp->begin_list (sp); + sp->begin_map (sp); + sp->map_key (sp, "status"); + sp->string (sp, node->decrypt_success ? "good" : "bad"); + sp->end (sp); + sp->end (sp); + } if (node->verify_attempted) { - printf (", \"sigstatus\": "); + sp->map_key (sp, "sigstatus"); format_part_sigstatus_json (sp, node); } - printf (", \"content-type\": %s", - json_quote_str (local, g_mime_content_type_to_string (content_type))); + sp->map_key (sp, "content-type"); + sp->string (sp, g_mime_content_type_to_string (content_type)); - if (cid) - printf (", \"content-id\": %s", json_quote_str (local, cid)); + if (cid) { + sp->map_key (sp, "content-id"); + sp->string (sp, cid); + } - if (filename) - printf (", \"filename\": %s", json_quote_str (local, filename)); + if (filename) { + sp->map_key (sp, "filename"); + sp->string (sp, filename); + } if (GMIME_IS_PART (node->part)) { /* For non-HTML text parts, we include the content in the @@ -636,35 +645,44 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, if (g_mime_content_type_is_type (content_type, "text", "html")) { const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset"); - if (content_charset != NULL) - printf (", \"content-charset\": %s", json_quote_str (local, content_charset)); + if (content_charset != NULL) { + sp->map_key (sp, "content-charset"); + sp->string (sp, content_charset); + } } else if (g_mime_content_type_is_type (content_type, "text", "*")) { GMimeStream *stream_memory = g_mime_stream_mem_new (); GByteArray *part_content; show_text_part_content (node->part, stream_memory, 0); part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory)); - - printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len)); + sp->map_key (sp, "content"); + sp->string_len (sp, (char *) part_content->data, part_content->len); g_object_unref (stream_memory); } } else if (GMIME_IS_MULTIPART (node->part)) { - printf (", \"content\": ["); - terminator = "]"; + sp->map_key (sp, "content"); + sp->begin_list (sp); + nclose = 1; } else if (GMIME_IS_MESSAGE (node->part)) { - printf (", \"content\": [{"); - printf ("\"headers\": "); + sp->map_key (sp, "content"); + sp->begin_list (sp); + sp->begin_map (sp); + + sp->map_key (sp, "headers"); format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE); - printf (", \"body\": ["); - terminator = "]}]"; + sp->map_key (sp, "body"); + sp->begin_list (sp); + nclose = 3; } - talloc_free (local); - for (i = 0; i < node->nchildren; i++) format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE); - printf ("%s}", terminator); + /* Close content structures */ + for (i = 0; i < nclose; i++) + sp->end (sp); + /* Close part map */ + sp->end (sp); } static notmuch_status_t -- 1.7.10