Re: [PATCH v2 2/5] Rename the -json printer functions in notmuch-reply and notmuch...
authorAustin Clements <aclements@csail.mit.edu>
Tue, 4 Dec 2012 19:18:00 +0000 (14:18 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:28 +0000 (09:51 -0800)
21/da139cf1f1c0083f746bb16a66fb5b2f8b1249 [new file with mode: 0644]

diff --git a/21/da139cf1f1c0083f746bb16a66fb5b2f8b1249 b/21/da139cf1f1c0083f746bb16a66fb5b2f8b1249
new file mode 100644 (file)
index 0000000..4d004e3
--- /dev/null
@@ -0,0 +1,359 @@
+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 C93B1431FB6\r
+       for <notmuch@notmuchmail.org>; Tue,  4 Dec 2012 11:18:09 -0800 (PST)\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 XH8z6S97+GxA for <notmuch@notmuchmail.org>;\r
+       Tue,  4 Dec 2012 11:18:06 -0800 (PST)\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 3FB7E431FAE\r
+       for <notmuch@notmuchmail.org>; Tue,  4 Dec 2012 11:18:05 -0800 (PST)\r
+X-AuditID: 12074425-b7f606d0000008ea-75-50be4c6c3502\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 54.04.02282.C6C4EB05; Tue,  4 Dec 2012 14:18:04 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qB4JI3xE026149; \r
+       Tue, 4 Dec 2012 14:18:04 -0500\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 qB4JI1cu008423\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+       Tue, 4 Dec 2012 14:18:02 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Tfy0G-0001lr-RU; Tue, 04 Dec 2012 14:18:00 -0500\r
+From: Austin Clements <aclements@csail.mit.edu>\r
+To: Peter Feigl <craven@gmx.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 2/5] Rename the -json printer functions in\r
+       notmuch-reply and notmuch-show to generic -sprinter functions.\r
+In-Reply-To: <1354632382-15609-3-git-send-email-craven@gmx.net>\r
+References: <1354632382-15609-1-git-send-email-craven@gmx.net>\r
+       <1354632382-15609-3-git-send-email-craven@gmx.net>\r
+User-Agent: Notmuch/0.14+100~gcb9b0b0 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i486-pc-linux-gnu)\r
+Date: Tue, 04 Dec 2012 14:18:00 -0500\r
+Message-ID: <87fw3ly6c7.fsf@awakening.csail.mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrLIsWRmVeSWpSXmKPExsUixCmqrZvjsy/A4OtrIYu9De2MFtdvzmR2\r
+       YPJYvGk/m8ezVbeYA5iiuGxSUnMyy1KL9O0SuDI+7U8reB5SMe3JE5YGxr1OXYycHBICJhLT\r
+       15xkhbDFJC7cW8/WxcjFISSwj1Gi7+YldghnPaPE3hV72UGqhAQuMEk8n5ADYS9hlJhzJwDE\r
+       ZhPQl1ixdhLYJBEBS4mpXy6xgdjCAg2MEh3ftLsYOTg4BewlJrSKQbQWSvx4P4kNJCwqEC9x\r
+       eakCSJhFQBXonicsIDYv0G19U1cwQ9iCEidnQsSZBbQkbvx7yTSBUWAWktQsJKkFjEyrGGVT\r
+       cqt0cxMzc4pTk3WLkxPz8lKLdC30cjNL9FJTSjcxgkKR3UV1B+OEQ0qHGAU4GJV4eCWM9wUI\r
+       sSaWFVfmHmKU5GBSEuX95wkU4kvKT6nMSCzOiC8qzUktPsQowcGsJML7zw4ox5uSWFmVWpQP\r
+       k5LmYFES572RctNfSCA9sSQ1OzW1ILUIJivDwaEkwbvYG6hRsCg1PbUiLTOnBCHNxMEJMpwH\r
+       aHiDF8jw4oLE3OLMdIj8KUZFKXHeoyDNAiCJjNI8uF5YqnjFKA70ijCvNEgVDzDNwHW/AhrM\r
+       BDT4hdBukMEliQgpqQZGpRPLktbPUFp6OpZ5w7l9AmmRryV3JP+SnxvfmelQvSO3X2qvzjer\r
+       zjlfN0y3j0w/XMF+6F//crc5J2MOzC+bKmCyJKR6Sm1m+Z25uTYqzAZX05Z91t4k5PB9tpyE\r
+       g4rgxRlNsWenru43Fpk1qSMrOX7hzXnlL2X0j/gHFvO7aiaKJFuc+H9AiaU4I9FQi7moOBEA\r
+       6zlH0fACAAA=\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: Tue, 04 Dec 2012 19:18:09 -0000\r
+\r
+On Tue, 04 Dec 2012, Peter Feigl <craven@gmx.net> wrote:\r
+> All the structured output functions in notmuch-reply and notmuch-show\r
+> are renamed to a generic name (as they do not contain any json-specific\r
+> code anyway). This patch is a preparation to actually using the new\r
+> S-Expression sprinter in notmuch-reply and notmuch-show.\r
+> ---\r
+>  notmuch-client.h |  8 ++++----\r
+>  notmuch-reply.c  | 38 +++++++++++++++++++++-----------------\r
+>  notmuch-show.c   | 30 +++++++++++++++---------------\r
+>  3 files changed, 40 insertions(+), 36 deletions(-)\r
+>\r
+> diff --git a/notmuch-client.h b/notmuch-client.h\r
+> index ae9344b..1c336dc 100644\r
+> --- a/notmuch-client.h\r
+> +++ b/notmuch-client.h\r
+> @@ -175,12 +175,12 @@ notmuch_status_t\r
+>  show_one_part (const char *filename, int part);\r
+>  \r
+>  void\r
+> -format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node,\r
+> -              notmuch_bool_t first, notmuch_bool_t output_body);\r
+> +format_part_sprinter (const void *ctx, struct sprinter *sp, mime_node_t *node,\r
+> +                  notmuch_bool_t first, notmuch_bool_t output_body);\r
+>  \r
+>  void\r
+> -format_headers_json (struct sprinter *sp, GMimeMessage *message,\r
+> -                 notmuch_bool_t reply);\r
+> +format_headers_sprinter (struct sprinter *sp, GMimeMessage *message,\r
+> +                     notmuch_bool_t reply);\r
+>  \r
+>  typedef enum {\r
+>      NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,\r
+> diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+> index e60a264..53aefa7 100644\r
+> --- a/notmuch-reply.c\r
+> +++ b/notmuch-reply.c\r
+> @@ -548,7 +548,8 @@ notmuch_reply_format_default(void *ctx,\r
+>                           notmuch_config_t *config,\r
+>                           notmuch_query_t *query,\r
+>                           notmuch_show_params_t *params,\r
+> -                         notmuch_bool_t reply_all)\r
+> +                         notmuch_bool_t reply_all,\r
+> +                         unused (sprinter_t *sp))\r
+>  {\r
+>      GMimeMessage *reply;\r
+>      notmuch_messages_t *messages;\r
+> @@ -587,17 +588,17 @@ notmuch_reply_format_default(void *ctx,\r
+>  }\r
+>  \r
+>  static int\r
+> -notmuch_reply_format_json(void *ctx,\r
+> -                      notmuch_config_t *config,\r
+> -                      notmuch_query_t *query,\r
+> -                      notmuch_show_params_t *params,\r
+> -                      notmuch_bool_t reply_all)\r
+> +notmuch_reply_format_sprinter(void *ctx,\r
+> +                          notmuch_config_t *config,\r
+> +                          notmuch_query_t *query,\r
+> +                          notmuch_show_params_t *params,\r
+> +                          notmuch_bool_t reply_all,\r
+> +                          sprinter_t *sp)\r
+>  {\r
+>      GMimeMessage *reply;\r
+>      notmuch_messages_t *messages;\r
+>      notmuch_message_t *message;\r
+>      mime_node_t *node;\r
+> -    sprinter_t *sp;\r
+>  \r
+>      if (notmuch_query_count_messages (query) != 1) {\r
+>      fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
+> @@ -613,18 +614,17 @@ notmuch_reply_format_json(void *ctx,\r
+>      if (!reply)\r
+>      return 1;\r
+>  \r
+> -    sp = sprinter_json_create (ctx, stdout);\r
+>      sp->begin_map (sp);\r
+>  \r
+>      /* The headers of the reply message we've created */\r
+>      sp->map_key (sp, "reply-headers");\r
+> -    format_headers_json (sp, reply, TRUE);\r
+> +    format_headers_sprinter (sp, reply, TRUE);\r
+>      g_object_unref (G_OBJECT (reply));\r
+>      reply = NULL;\r
+>  \r
+>      /* Start the original */\r
+>      sp->map_key (sp, "original");\r
+> -    format_part_json (ctx, sp, node, TRUE, TRUE);\r
+> +    format_part_sprinter (ctx, sp, node, TRUE, TRUE);\r
+>  \r
+>      /* End */\r
+>      sp->end (sp);\r
+> @@ -639,7 +639,8 @@ notmuch_reply_format_headers_only(void *ctx,\r
+>                                notmuch_config_t *config,\r
+>                                notmuch_query_t *query,\r
+>                                unused (notmuch_show_params_t *params),\r
+> -                              notmuch_bool_t reply_all)\r
+> +                              notmuch_bool_t reply_all,\r
+> +                              unused (sprinter_t *sp))\r
+>  {\r
+>      GMimeMessage *reply;\r
+>      notmuch_messages_t *messages;\r
+> @@ -707,7 +708,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+>      notmuch_query_t *query;\r
+>      char *query_string;\r
+>      int opt_index, ret = 0;\r
+> -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
+> +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all, struct sprinter *sp);\r
+\r
+Yikes.  This could use some line wrapping.\r
+\r
+This patch LGTM other than this.\r
+\r
+>      notmuch_show_params_t params = {\r
+>      .part = -1,\r
+>      .crypto = {\r
+> @@ -717,6 +718,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+>      };\r
+>      int format = FORMAT_DEFAULT;\r
+>      int reply_all = TRUE;\r
+> +    struct sprinter *sp = NULL;\r
+>  \r
+>      notmuch_opt_desc_t options[] = {\r
+>      { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
+> @@ -738,12 +740,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+>      return 1;\r
+>      }\r
+>  \r
+> -    if (format == FORMAT_HEADERS_ONLY)\r
+> +    if (format == FORMAT_HEADERS_ONLY) {\r
+>      reply_format_func = notmuch_reply_format_headers_only;\r
+> -    else if (format == FORMAT_JSON)\r
+> -    reply_format_func = notmuch_reply_format_json;\r
+> -    else\r
+> +    } else if (format == FORMAT_JSON) {\r
+> +    reply_format_func = notmuch_reply_format_sprinter;\r
+> +    sp = sprinter_json_create (ctx, stdout);\r
+> +    } else {\r
+>      reply_format_func = notmuch_reply_format_default;\r
+> +    }\r
+>  \r
+>      config = notmuch_config_open (ctx, NULL, NULL);\r
+>      if (config == NULL)\r
+> @@ -770,7 +774,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+>      return 1;\r
+>      }\r
+>  \r
+> -    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
+> +    if (reply_format_func (ctx, config, query, &params, reply_all, sp) != 0)\r
+>      return 1;\r
+>  \r
+>      notmuch_crypto_cleanup (&params.crypto);\r
+> diff --git a/notmuch-show.c b/notmuch-show.c\r
+> index 2fa2292..38c621f 100644\r
+> --- a/notmuch-show.c\r
+> +++ b/notmuch-show.c\r
+> @@ -32,12 +32,12 @@ static const notmuch_show_format_t format_text = {\r
+>  };\r
+>  \r
+>  static notmuch_status_t\r
+> -format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+> +format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>                      int indent, const notmuch_show_params_t *params);\r
+>  \r
+>  static const notmuch_show_format_t format_json = {\r
+>      .new_sprinter = sprinter_json_create,\r
+> -    .part = format_part_json_entry,\r
+> +    .part = format_part_sprinter_entry,\r
+>  };\r
+>  \r
+>  static notmuch_status_t\r
+> @@ -108,7 +108,7 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)\r
+>  /* Emit a sequence of key/value pairs for the metadata of message.\r
+>   * The caller should begin a map before calling this. */\r
+>  static void\r
+> -format_message_json (sprinter_t *sp, notmuch_message_t *message)\r
+> +format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)\r
+>  {\r
+>      /* Any changes to the JSON format should be reflected in the file\r
+>       * devel/schemata. */\r
+> @@ -208,7 +208,7 @@ _is_from_line (const char *line)\r
+>  }\r
+>  \r
+>  void\r
+> -format_headers_json (sprinter_t *sp, GMimeMessage *message,\r
+> +format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,\r
+>                   notmuch_bool_t reply)\r
+>  {\r
+>      /* Any changes to the JSON format should be reflected in the file\r
+> @@ -363,7 +363,7 @@ signer_status_to_string (GMimeSignerStatus x)\r
+>  \r
+>  #ifdef GMIME_ATLEAST_26\r
+>  static void\r
+> -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
+> +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)\r
+>  {\r
+>      /* Any changes to the JSON format should be reflected in the file\r
+>       * devel/schemata. */\r
+> @@ -438,7 +438,7 @@ format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
+>  }\r
+>  #else\r
+>  static void\r
+> -format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
+> +format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)\r
+>  {\r
+>      const GMimeSignatureValidity* validity = node->sig_validity;\r
+>  \r
+> @@ -595,7 +595,7 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>  }\r
+>  \r
+>  void\r
+> -format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+> +format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>                notmuch_bool_t first, notmuch_bool_t output_body)\r
+>  {\r
+>      /* Any changes to the JSON format should be reflected in the file\r
+> @@ -603,15 +603,15 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>  \r
+>      if (node->envelope_file) {\r
+>      sp->begin_map (sp);\r
+> -    format_message_json (sp, node->envelope_file);\r
+> +    format_message_sprinter (sp, node->envelope_file);\r
+>  \r
+>      sp->map_key (sp, "headers");\r
+> -    format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
+> +    format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);\r
+>  \r
+>      if (output_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
+> +        format_part_sprinter (ctx, sp, mime_node_child (node, 0), first, TRUE);\r
+>          sp->end (sp);\r
+>      }\r
+>      sp->end (sp);\r
+> @@ -646,7 +646,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>  \r
+>      if (node->verify_attempted) {\r
+>      sp->map_key (sp, "sigstatus");\r
+> -    format_part_sigstatus_json (sp, node);\r
+> +    format_part_sigstatus_sprinter (sp, node);\r
+>      }\r
+>  \r
+>      sp->map_key (sp, "content-type");\r
+> @@ -698,7 +698,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>      sp->begin_map (sp);\r
+>  \r
+>      sp->map_key (sp, "headers");\r
+> -    format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);\r
+> +    format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);\r
+>  \r
+>      sp->map_key (sp, "body");\r
+>      sp->begin_list (sp);\r
+> @@ -706,7 +706,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>      }\r
+>  \r
+>      for (i = 0; i < node->nchildren; i++)\r
+> -    format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);\r
+> +    format_part_sprinter (ctx, sp, mime_node_child (node, i), i == 0, TRUE);\r
+>  \r
+>      /* Close content structures */\r
+>      for (i = 0; i < nclose; i++)\r
+> @@ -716,11 +716,11 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+>  }\r
+>  \r
+>  static notmuch_status_t\r
+> -format_part_json_entry (const void *ctx, sprinter_t *sp,\r
+> +format_part_sprinter_entry (const void *ctx, sprinter_t *sp,\r
+>                      mime_node_t *node, unused (int indent),\r
+>                      const notmuch_show_params_t *params)\r
+>  {\r
+> -    format_part_json (ctx, sp, node, TRUE, params->output_body);\r
+> +    format_part_sprinter (ctx, sp, node, TRUE, params->output_body);\r
+>  \r
+>      return NOTMUCH_STATUS_SUCCESS;\r
+>  }\r
+> -- \r
+> 1.8.0\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r