From f95a07df2a06ac432ec9184b1d270de3194c0768 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 28 Jul 2012 17:35:37 +2000 Subject: [PATCH] Re: [PATCH 10/13] show: Convert envelope format_part_json to use sprinter --- 4b/f42f61bf9280c2e538ab3c49b661ff987a541c | 199 ++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 4b/f42f61bf9280c2e538ab3c49b661ff987a541c diff --git a/4b/f42f61bf9280c2e538ab3c49b661ff987a541c b/4b/f42f61bf9280c2e538ab3c49b661ff987a541c new file mode 100644 index 000000000..f65af3edb --- /dev/null +++ b/4b/f42f61bf9280c2e538ab3c49b661ff987a541c @@ -0,0 +1,199 @@ +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 D48F4431FB6 + for ; Fri, 27 Jul 2012 14:35:43 -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 J6gubSLZ3Led for ; + Fri, 27 Jul 2012 14:35:39 -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 B5C76431FAE + for ; Fri, 27 Jul 2012 14:35:39 -0700 (PDT) +X-AuditID: 12074425-b7f9b6d0000008c4-98-501309abe11f +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id 5E.4A.02244.BA903105; Fri, 27 Jul 2012 17:35:39 -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 q6RLZcCQ018364; + Fri, 27 Jul 2012 17:35:39 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6RLZbF5029580 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Fri, 27 Jul 2012 17:35:38 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SusC9-00012s-Ko; Fri, 27 Jul 2012 17:35:37 -0400 +Date: Fri, 27 Jul 2012 17:35:37 -0400 +From: Austin Clements +To: Mark Walters +Subject: Re: [PATCH 10/13] show: Convert envelope format_part_json to use + sprinter +Message-ID: <20120727213537.GD8502@mit.edu> +References: <1343183693-17134-1-git-send-email-amdragon@mit.edu> + <1343183693-17134-11-git-send-email-amdragon@mit.edu> + <874novirxv.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <874novirxv.fsf@qmul.ac.uk> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT113NKRxg8HMLu8XquTwW12/OZHZg + 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mn49aWYqeKRcsfz8XMYGxpXSXYycHBICJhLH + 1x1kgrDFJC7cW8/WxcjFISSwj1Gi4+wVJghnA6PE1xUnoTInmSQ6Vt6EyixhlHh37jw7SD+L + gKrEr51bWEBsNgENiW37lzOC2CICOhK3Dy0Aq2EWkJb49rsZbJ+wQIjE+xszwOp5BbQlpjVf + BopzAA2dxijRnAwRFpQ4OfMJC0SrlsSNfy/BSkDGLP/HARLmBNp0cMkvsBJRARWJKSe3sU1g + FJqFpHsWku5ZCN0LGJlXMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Vro5WaW6KWmlG5iBAe1i+oO + xgmHlA4xCnAwKvHwnroiFCDEmlhWXJl7iFGSg0lJlPcMh3CAEF9SfkplRmJxRnxRaU5q8SFG + CQ5mJRFemx1A5bwpiZVVqUX5MClpDhYlcd4bKTf9hQTSE0tSs1NTC1KLYLIyHBxKErxXQIYK + FqWmp1akZeaUIKSZODhBhvMADX8IUsNbXJCYW5yZDpE/xagoJc77BCQhAJLIKM2D64UlnVeM + 4kCvCPMyAFOQEA8wYcF1vwIazAQ02CIa5OrikkSElFQD4xSlzrx2gW+qAXf6F6855vM578gq + i2/erwvnveJe+NKq/uDhh2usIm+uZ3yc/FbheMBd4/IPdVIrc7ie31tZUKdZYnyOz9FuC6/F + J9k7fvtVxGtm6CjG7GdS7jhj9TD786+GeNlJ7RMFup9/iHNdXpNgmucXenf6DtEy7U1Mq760 + crkZfvZUUGIpzkg01GIuKk4EAAKO2pIVAwAA +Cc: notmuch@notmuchmail.org +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, 27 Jul 2012 21:35:44 -0000 + +Quoth Mark Walters on Jul 25 at 8:03 pm: +> On Wed, 25 Jul 2012, Austin Clements wrote: +> > --- +> > 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) +> > { +> +> It might be nice to have a comment for this function (and other +> similar ones) saying what it prints: is it a sequence of key: value +> pairs, or a map or an array etc. On the other hand it might be that +> it is best as it is where you just read the code to see. + +Ah, good point. I don't think this is so necessary for the other +functions, but this one is weird because it requires the caller to +begin the map (every other function simply emits a value, so it +doesn't depend on the caller's context). + +> > + 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); +> +> This makes the diff very easy to read but it might be nicer to have +> these two assignments further down where they are used. + +Done, and it is nicer. (Apparently I had the 'date' assignment both +here and below!) + +> Best wishes +> +> Mark +> +> > + +> > + 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; +> > } +> > -- 2.26.2