Re: [PATCH 10/13] show: Convert envelope format_part_json to use sprinter
authorAustin Clements <amdragon@MIT.EDU>
Fri, 27 Jul 2012 21:35:37 +0000 (17:35 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:37 +0000 (09:48 -0800)
4b/f42f61bf9280c2e538ab3c49b661ff987a541c [new file with mode: 0644]

diff --git a/4b/f42f61bf9280c2e538ab3c49b661ff987a541c b/4b/f42f61bf9280c2e538ab3c49b661ff987a541c
new file mode 100644 (file)
index 0000000..f65af3e
--- /dev/null
@@ -0,0 +1,199 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id D48F4431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 27 Jul 2012 14:35:43 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id J6gubSLZ3Led for <notmuch@notmuchmail.org>;\r
+       Fri, 27 Jul 2012 14:35:39 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
+       [18.7.68.37])\r
+       by olra.theworths.org (Postfix) with ESMTP id B5C76431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 27 Jul 2012 14:35:39 -0700 (PDT)\r
+X-AuditID: 12074425-b7f9b6d0000008c4-98-501309abe11f\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 5E.4A.02244.BA903105; Fri, 27 Jul 2012 17:35:39 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q6RLZcCQ018364; \r
+       Fri, 27 Jul 2012 17:35:39 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6RLZbF5029580\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Fri, 27 Jul 2012 17:35:38 -0400 (EDT)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SusC9-00012s-Ko; Fri, 27 Jul 2012 17:35:37 -0400\r
+Date: Fri, 27 Jul 2012 17:35:37 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH 10/13] show: Convert envelope format_part_json to use\r
+       sprinter\r
+Message-ID: <20120727213537.GD8502@mit.edu>\r
+References: <1343183693-17134-1-git-send-email-amdragon@mit.edu>\r
+       <1343183693-17134-11-git-send-email-amdragon@mit.edu>\r
+       <874novirxv.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <874novirxv.fsf@qmul.ac.uk>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT113NKRxg8HMLu8XquTwW12/OZHZg\r
+       8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mn49aWYqeKRcsfz8XMYGxpXSXYycHBICJhLH\r
+       1x1kgrDFJC7cW8/WxcjFISSwj1Gi4+wVJghnA6PE1xUnoTInmSQ6Vt6EyixhlHh37jw7SD+L\r
+       gKrEr51bWEBsNgENiW37lzOC2CICOhK3Dy0Aq2EWkJb49rsZbJ+wQIjE+xszwOp5BbQlpjVf\r
+       BopzAA2dxijRnAwRFpQ4OfMJC0SrlsSNfy/BSkDGLP/HARLmBNp0cMkvsBJRARWJKSe3sU1g\r
+       FJqFpHsWku5ZCN0LGJlXMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Vro5WaW6KWmlG5iBAe1i+oO\r
+       xgmHlA4xCnAwKvHwnroiFCDEmlhWXJl7iFGSg0lJlPcMh3CAEF9SfkplRmJxRnxRaU5q8SFG\r
+       CQ5mJRFemx1A5bwpiZVVqUX5MClpDhYlcd4bKTf9hQTSE0tSs1NTC1KLYLIyHBxKErxXQIYK\r
+       FqWmp1akZeaUIKSZODhBhvMADX8IUsNbXJCYW5yZDpE/xagoJc77BCQhAJLIKM2D64UlnVeM\r
+       4kCvCPMyAFOQEA8wYcF1vwIazAQ02CIa5OrikkSElFQD4xSlzrx2gW+qAXf6F6855vM578gq\r
+       i2/erwvnveJe+NKq/uDhh2usIm+uZ3yc/FbheMBd4/IPdVIrc7ie31tZUKdZYnyOz9FuC6/F\r
+       J9k7fvtVxGtm6CjG7GdS7jhj9TD786+GeNlJ7RMFup9/iHNdXpNgmucXenf6DtEy7U1Mq760\r
+       crkZfvZUUGIpzkg01GIuKk4EAAKO2pIVAwAA\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 27 Jul 2012 21:35:44 -0000\r
+\r
+Quoth Mark Walters on Jul 25 at  8:03 pm:\r
+> On Wed, 25 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> > ---\r
+> >  notmuch-show.c |   57 +++++++++++++++++++++++++++++++++-----------------------\r
+> >  1 file changed, 34 insertions(+), 23 deletions(-)\r
+> >\r
+> > diff --git a/notmuch-show.c b/notmuch-show.c\r
+> > index afbd9d0..fa1e6e9 100644\r
+> > --- a/notmuch-show.c\r
+> > +++ b/notmuch-show.c\r
+> > @@ -110,34 +110,44 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)\r
+> >  }\r
+> >  \r
+> >  static void\r
+> > -format_message_json (const void *ctx, notmuch_message_t *message)\r
+> > +format_message_json (sprinter_t *sp, notmuch_message_t *message)\r
+> >  {\r
+> \r
+> It might be nice to have a comment for this function (and other\r
+> similar ones) saying what it prints: is it a sequence of key: value\r
+> pairs, or a map or an array etc. On the other hand it might be that\r
+> it is best as it is where you just read the code to see.\r
+\r
+Ah, good point.  I don't think this is so necessary for the other\r
+functions, but this one is weird because it requires the caller to\r
+begin the map (every other function simply emits a value, so it\r
+doesn't depend on the caller's context).\r
+\r
+> > +    void *local = talloc_new (NULL);\r
+> >      notmuch_tags_t *tags;\r
+> > -    int first = 1;\r
+> > -    void *ctx_quote = talloc_new (ctx);\r
+> >      time_t date;\r
+> >      const char *relative_date;\r
+> >  \r
+> >      date = notmuch_message_get_date (message);\r
+> > -    relative_date = notmuch_time_relative_date (ctx, date);\r
+> > +    relative_date = notmuch_time_relative_date (local, date);\r
+> \r
+> This makes the diff very easy to read but it might be nicer to have\r
+> these two assignments further down where they are used.\r
+\r
+Done, and it is nicer.  (Apparently I had the 'date' assignment both\r
+here and below!)\r
+\r
+> Best wishes\r
+> \r
+> Mark\r
+> \r
+> > +\r
+> > +    sp->map_key (sp, "id");\r
+> > +    sp->string (sp, notmuch_message_get_message_id (message));\r
+> > +\r
+> > +    sp->map_key (sp, "match");\r
+> > +    sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH));\r
+> > +\r
+> > +    sp->map_key (sp, "excluded");\r
+> > +    sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED));\r
+> > +\r
+> > +    sp->map_key (sp, "filename");\r
+> > +    sp->string (sp, notmuch_message_get_filename (message));\r
+> > +\r
+> > +    sp->map_key (sp, "timestamp");\r
+> > +    date = notmuch_message_get_date (message);\r
+> > +    sp->integer (sp, date);\r
+> >  \r
+> > -    printf ("\"id\": %s, \"match\": %s, \"excluded\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [",\r
+> > -      json_quote_str (ctx_quote, notmuch_message_get_message_id (message)),\r
+> > -      notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? "true" : "false",\r
+> > -      notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? "true" : "false",\r
+> > -      json_quote_str (ctx_quote, notmuch_message_get_filename (message)),\r
+> > -      date, relative_date);\r
+> > +    sp->map_key (sp, "date_relative");\r
+> > +    sp->string (sp, relative_date);\r
+> >  \r
+> > +    sp->map_key (sp, "tags");\r
+> > +    sp->begin_list (sp);\r
+> >      for (tags = notmuch_message_get_tags (message);\r
+> >     notmuch_tags_valid (tags);\r
+> >     notmuch_tags_move_to_next (tags))\r
+> > -    {\r
+> > -         printf("%s%s", first ? "" : ",",\r
+> > -               json_quote_str (ctx_quote, notmuch_tags_get (tags)));\r
+> > -         first = 0;\r
+> > -    }\r
+> > -    printf("], ");\r
+> > -    talloc_free (ctx_quote);\r
+> > +  sp->string (sp, notmuch_tags_get (tags));\r
+> > +    sp->end (sp);\r
+> > +\r
+> > +    talloc_free (local);\r
+> >  }\r
+> >  \r
+> >  /* Extract just the email address from the contents of a From:\r
+> > @@ -573,18 +583,19 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+> >       * devel/schemata. */\r
+> >  \r
+> >      if (node->envelope_file) {\r
+> > -  printf ("{");\r
+> > -  format_message_json (ctx, node->envelope_file);\r
+> > +  sp->begin_map (sp);\r
+> > +  format_message_json (sp, node->envelope_file);\r
+> >  \r
+> > -  printf ("\"headers\": ");\r
+> > +  sp->map_key (sp, "headers");\r
+> >    format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
+> >  \r
+> >    if (output_body) {\r
+> > -      printf (", \"body\": [");\r
+> > +      sp->map_key (sp, "body");\r
+> > +      sp->begin_list (sp);\r
+> >        format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
+> > -      printf ("]");\r
+> > +      sp->end (sp);\r
+> >    }\r
+> > -  printf ("}");\r
+> > +  sp->end (sp);\r
+> >    return;\r
+> >      }\r
+> >  \r