From 61470cc20e30b42ffa8404b24a98d6960645ef36 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sun, 29 Jul 2012 00:29:11 +2000 Subject: [PATCH] [PATCH v2 10/13] show: Convert envelope format_part_json to use sprinter --- 34/6e3e810534d1b0b8e437c84a3f8a625b428418 | 175 ++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 34/6e3e810534d1b0b8e437c84a3f8a625b428418 diff --git a/34/6e3e810534d1b0b8e437c84a3f8a625b428418 b/34/6e3e810534d1b0b8e437c84a3f8a625b428418 new file mode 100644 index 000000000..c14145b57 --- /dev/null +++ b/34/6e3e810534d1b0b8e437c84a3f8a625b428418 @@ -0,0 +1,175 @@ +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 CC7D3431FBD + for ; Fri, 27 Jul 2012 21:29:44 -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 KEWmC6850hhj for ; + Fri, 27 Jul 2012 21:29:40 -0700 (PDT) +Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU + [18.7.68.37]) + by olra.theworths.org (Postfix) with ESMTP id 5519D431FCF + for ; Fri, 27 Jul 2012 21:29:28 -0700 (PDT) +X-AuditID: 12074425-b7f9b6d0000008c4-9c-50136aa720fd +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id 66.70.02244.7AA63105; Sat, 28 Jul 2012 00:29:28 -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 q6S4TRb4017264; + Sat, 28 Jul 2012 00:29:27 -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 q6S4TLxu027361 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 28 Jul 2012 00:29:22 -0400 (EDT) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1SuyeW-0002XA-RK; Sat, 28 Jul 2012 00:29:20 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 10/13] show: Convert envelope format_part_json to use + sprinter +Date: Sat, 28 Jul 2012 00:29:11 -0400 +Message-Id: <1343449754-9010-11-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10 +In-Reply-To: <1343449754-9010-1-git-send-email-amdragon@mit.edu> +References: <1343449754-9010-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFrrAIsWRmVeSWpSXmKPExsUixCmqrLsiSzjAYNZHVou9De2MFqvn8lhc + vzmT2eLNynmsDiweO2fdZfdYvGk/m8fhrwtZPJ6tusUcwBLFZZOSmpNZllqkb5fAlXFuwT/2 + gndSFeuPTWJqYFwo2sXIySEhYCKxc985ZghbTOLCvfVsXYxcHEIC+xglOm7/Y4JwNjBKzDh8 + ixHCecQk8WJaOwuEM5dRYsLJLUwg/WwCGhLb9i9nBLFFBKQldt6dzdrFyMHBLJAn8XitBEhY + WCBQ4t20t+wgNouAqsSrBdPAVvMKOEisv7OIHeIMeYmn9/vYQGxOoPjmlx/AaoQE7CV2T97A + OoGRfwEjwypG2ZTcKt3cxMyc4tRk3eLkxLy81CJdC73czBK91JTSTYyggGN3Ud3BOOGQ0iFG + AQ5GJR7eU1eEAoRYE8uKK3MPMUpyMCmJ8kaFCwcI8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuHd + KQiU401JrKxKLcqHSUlzsCiJ895IuekvJJCeWJKanZpakFoEk5Xh4FCS4N2eCdQoWJSanlqR + lplTgpBm4uAEGc4DNHwNSA1vcUFibnFmOkT+FKOilDjvJJCEAEgiozQPrheWEF4xigO9Isx7 + DaSKB5hM4LpfAQ1mAhpsES0EMrgkESEl1cDYtFPS+ti/KXwyt7Q3GCvx9KSuVlG5uOiynPW5 + khW7/qSs96rWf6rqcpfZuO65i5nthf1VTW7xoZHJSzq+7nvH9Lfm0/XUmiPl0bNcWFc6pi58 + vNzvzfMbDlb9yhOnVBf+PntxHfu5Vc+SFnv+2fL++6Gn++ZdP/40IP/HKyaBV7sPmDRdCn4Z + qMRSnJFoqMVcVJwIAPHw0u3jAgAA +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: Sat, 28 Jul 2012 04:29:45 -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 + -- 2.26.2