Re: [PATCH 10/13] show: Convert envelope format_part_json to use sprinter
authorMark Walters <markwalters1009@gmail.com>
Wed, 25 Jul 2012 19:03:40 +0000 (20:03 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:37 +0000 (09:48 -0800)
10/de5693c534ae729a5172ea6bb0b8c958adeb6e [new file with mode: 0644]

diff --git a/10/de5693c534ae729a5172ea6bb0b8c958adeb6e b/10/de5693c534ae729a5172ea6bb0b8c958adeb6e
new file mode 100644 (file)
index 0000000..80334a6
--- /dev/null
@@ -0,0 +1,195 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 32E27431FAF\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 12:03:43 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 SkHYyThtQhSI for <notmuch@notmuchmail.org>;\r
+       Wed, 25 Jul 2012 12:03:42 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 1AF19431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 12:03:42 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Su6s0-0003km-DV; Wed, 25 Jul 2012 20:03:40 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Su6s0-0001j5-1X; Wed, 25 Jul 2012 20:03:40 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 10/13] show: Convert envelope format_part_json to use\r
+       sprinter\r
+In-Reply-To: <1343183693-17134-11-git-send-email-amdragon@mit.edu>\r
+References: <1343183693-17134-1-git-send-email-amdragon@mit.edu>\r
+       <1343183693-17134-11-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.13.2+93~gf33b188 (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Wed, 25 Jul 2012 20:03:40 +0100\r
+Message-ID: <874novirxv.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: ded7eccf8ef343a5cf8db2bb05f40a95 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Wed, 25 Jul 2012 19:03:43 -0000\r
+\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 similar ones) saying\r
+what it prints: is it a sequence of key: value pairs, or a map or an\r
+array etc. On the other hand it might be that it is best as it is where\r
+you just read the code to see.\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
+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
+> -- \r
+> 1.7.10\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r