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 04A09429E36 for ; Thu, 2 Aug 2012 18:15:09 -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 R0YazFFrYvgF for ; Thu, 2 Aug 2012 18:15:08 -0700 (PDT) Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU [18.9.25.13]) by olra.theworths.org (Postfix) with ESMTP id DEFBC431FAF for ; Thu, 2 Aug 2012 18:15:07 -0700 (PDT) X-AuditID: 1209190d-b7fd56d000000933-d2-501b261be0a9 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP id 69.7E.02355.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-1.mit.edu (8.13.8/8.9.2) with ESMTP id q731F6d3012767; 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 q731F42H002793 (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-0003wX-FS; Thu, 02 Aug 2012 21:15:04 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 10/13] show: Convert envelope format_part_json to use sprinter Date: Thu, 2 Aug 2012 21:14:56 -0400 Message-Id: <1343956499-14543-11-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+NgFjrGIsWRmVeSWpSXmKPExsUixCmqrCutJh1g0H9a3mL1XB6L6zdnMlu8 WTmP1YHZY+esu+weh78uZPF4tuoWcwBzFJdNSmpOZllqkb5dAlfGuQX/2AveSVWsPzaJqYFx oWgXIyeHhICJxKwfJxkhbDGJC/fWs3UxcnEICexjlPg6cSsrhLOeUeL49E1QmYdMEi8mzGCG cOYySjTP7GEF6WcT0JDYtn852CwRAWmJnXdng8WZBeIktkz5DxYXFgiU2PbhBZjNIqAqMf/G IqCpHBy8Ao4S905FQpwhL/H0fh8biM0JFH799hVYuZCAg8Tytm7WCYz8CxgZVjHKpuRW6eYm ZuYUpybrFicn5uWlFuka6eVmluilppRuYgQHlyTvDsZ3B5UOMQpwMCrx8JpISgcIsSaWFVfm HmKU5GBSEuVlVgIK8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuGtWiIVIMSbklhZlVqUD5OS5mBR Eue9knLTX0ggPbEkNTs1tSC1CCYrw8GhJMEbrAo0VLAoNT21Ii0zpwQhzcTBCTKcB2i4PUgN b3FBYm5xZjpE/hSjopQ4bzpIQgAkkVGaB9cLi/5XjOJArwjzeoFU8QATB1z3K6DBTECD7cxA ri4uSURISTUwiqpMCrv5m8f2z/YEBXtLtkcPL7yYNG3G4dbAgolib3KNHrs833B9vWbQEfFn J95+E7dVuyw4QXd6kuWpWWbn5Y+JZPxZ/DVZ9KHL3nCZEu548SyrJ65pwj9iOUqNbry+sPXw f+l1YaceeWe0Lfmz4/gj8zuXjnkJJS5t2bHa5VtwmUFZrKS6rxJLcUaioRZzUXEiADNrQvbZ AgAA 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:09 -0000 --- notmuch-show.c | 57 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/notmuch-show.c b/notmuch-show.c index afbd9d0..b9d9f5d 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -109,35 +109,45 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) from, relative_date, tags); } +/* Emit a sequence of key/value pairs for the metadata of message. + * The caller should begin a map before calling this. */ 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; + 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); - relative_date = notmuch_time_relative_date (ctx, date); + 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"); + relative_date = notmuch_time_relative_date (local, date); + 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