Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id AFB2A431FBD for ; Tue, 24 Jul 2012 19:35:13 -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 beZ0ccuKiqAn for ; Tue, 24 Jul 2012 19:35:12 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id 8B07F431FAE for ; Tue, 24 Jul 2012 19:35:06 -0700 (PDT) X-AuditID: 1209190c-b7f806d000006b87-dc-500f5b59f872 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id E1.C8.27527.95B5F005; Tue, 24 Jul 2012 22:35:05 -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 q6P2Z5nj008579; Tue, 24 Jul 2012 22:35:05 -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 q6P2Z24c025129 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Tue, 24 Jul 2012 22:35:04 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1StrRG-0004a5-OC; Tue, 24 Jul 2012 22:35:02 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 10/13] show: Convert envelope format_part_json to use sprinter Date: Tue, 24 Jul 2012 22:34:50 -0400 Message-Id: <1343183693-17134-11-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1343183693-17134-1-git-send-email-amdragon@mit.edu> References: <1343183693-17134-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixG6nrhsZzR9gcGernsXehnZGi+s3ZzI7 MHks3rSfzePZqlvMAUxRXDYpqTmZZalF+nYJXBk3vl5lLPgrWXG+v4G9gfG0SBcjJ4eEgInE zR/dLBC2mMSFe+vZuhi5OIQE9jFKHHw/ixXC2cAocenlS2aQKiGBR0wSVxp0IRJzGSWWP13D DpJgE9CQ2LZ/OSOILSIgLbHz7mxWEJtZwExi7s+JbCC2sICfRPuCm2A2i4CqxNTDx8HqeQUc JX6s2wd1hrzE0/t9YDWcQPHzSxYyQix2kOhZfI19AiP/AkaGVYyyKblVurmJmTnFqcm6xcmJ eXmpRbqGermZJXqpKaWbGEGhxCnJs4PxzUGlQ4wCHIxKPLy/n/AFCLEmlhVX5h5ilORgUhLl rQjmDxDiS8pPqcxILM6ILyrNSS0+xCjBwawkwlsUBpTjTUmsrEotyodJSXOwKInzXk656S8k kJ5YkpqdmlqQWgSTleHgUJLg3R8F1ChYlJqeWpGWmVOCkGbi4AQZzgM0fDdIDW9xQWJucWY6 RP4Uo6KUOK82SEIAJJFRmgfXC4v1V4ziQK8IQ7TzANMEXPcroMFMQIOfh/GBDC5JREhJNTDW qk8PfP4ksX7mrrVLQ9vctweJ9EosmWS5b6mzmLOroV7KCq5dwm/fX1D/v+my0bJHRhbT4n9f WyIyWfHT/HuSckWyrMEBAhKz1rIF966KuBt8Y9Ncpge93X/MbkW4XfQqtDb49+WIm+KcWbO2 evzZVPx93z1//y3ZU8y3rHq95/N3PqPHDSv3K7EUZyQaajEXFScCADxbndzQAgAA 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: Wed, 25 Jul 2012 02:35:14 -0000 --- notmuch-show.c | 57 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/notmuch-show.c b/notmuch-show.c index afbd9d0..fa1e6e9 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -110,34 +110,44 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) } static void -format_message_json (const void *ctx, notmuch_message_t *message) +format_message_json (sprinter_t *sp, notmuch_message_t *message) { + void *local = talloc_new (NULL); notmuch_tags_t *tags; - int first = 1; - void *ctx_quote = talloc_new (ctx); time_t date; const char *relative_date; date = notmuch_message_get_date (message); - relative_date = notmuch_time_relative_date (ctx, date); + relative_date = notmuch_time_relative_date (local, date); + + sp->map_key (sp, "id"); + sp->string (sp, notmuch_message_get_message_id (message)); + + sp->map_key (sp, "match"); + sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH)); + + sp->map_key (sp, "excluded"); + sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED)); + + sp->map_key (sp, "filename"); + sp->string (sp, notmuch_message_get_filename (message)); + + sp->map_key (sp, "timestamp"); + date = notmuch_message_get_date (message); + sp->integer (sp, date); - printf ("\"id\": %s, \"match\": %s, \"excluded\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [", - json_quote_str (ctx_quote, notmuch_message_get_message_id (message)), - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? "true" : "false", - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? "true" : "false", - json_quote_str (ctx_quote, notmuch_message_get_filename (message)), - date, relative_date); + sp->map_key (sp, "date_relative"); + sp->string (sp, relative_date); + sp->map_key (sp, "tags"); + sp->begin_list (sp); for (tags = notmuch_message_get_tags (message); notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) - { - printf("%s%s", first ? "" : ",", - json_quote_str (ctx_quote, notmuch_tags_get (tags))); - first = 0; - } - printf("], "); - talloc_free (ctx_quote); + sp->string (sp, notmuch_tags_get (tags)); + sp->end (sp); + + talloc_free (local); } /* Extract just the email address from the contents of a From: @@ -573,18 +583,19 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, * devel/schemata. */ if (node->envelope_file) { - printf ("{"); - format_message_json (ctx, node->envelope_file); + sp->begin_map (sp); + format_message_json (sp, node->envelope_file); - printf ("\"headers\": "); + sp->map_key (sp, "headers"); format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE); if (output_body) { - printf (", \"body\": ["); + sp->map_key (sp, "body"); + sp->begin_list (sp); format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE); - printf ("]"); + sp->end (sp); } - printf ("}"); + sp->end (sp); return; } -- 1.7.10