[PATCH v2 08/14] cli/reply: reduce the reply format abstractions
authorJani Nikula <jani@nikula.org>
Sat, 13 Aug 2016 11:37:32 +0000 (14:37 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:22:25 +0000 (16:22 -0700)
71/1e1a8bab71cd05a30c5b86813e3624f3cb827d [new file with mode: 0644]

diff --git a/71/1e1a8bab71cd05a30c5b86813e3624f3cb827d b/71/1e1a8bab71cd05a30c5b86813e3624f3cb827d
new file mode 100644 (file)
index 0000000..54d56ca
--- /dev/null
@@ -0,0 +1,280 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id BAC2C6DE2D92\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:40:38 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.266\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.266 tagged_above=-999 required=5 tests=[AWL=0.986, \r
+ DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id no16u5ptnUoX for <notmuch@notmuchmail.org>;\r
+ Sat, 13 Aug 2016 04:40:30 -0700 (PDT)\r
+Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com\r
+ [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id 031126DE390F for\r
+ <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:16 -0700 (PDT)\r
+Received: by mail-wm0-f66.google.com with SMTP id i138so2004422wmf.3\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:15 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=nikula-org.20150623.gappssmtp.com; s=20150623;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references\r
+ :in-reply-to:references;\r
+ bh=qK/Sq8a9u1XpVLQESV5pNaTbGcGNCTZCBIEd//Ix38A=;\r
+ b=htlnE83+aAr53bHBjx7OtYwDtc5YcNbk+NIxrvCW80wSIEdpWUya8aPU0ioOGH408x\r
+ fF4elBuwXya3ebLEKH9Cca0lHlmkzbb9g9lp3BUfOX5T+VlVvSgEUU/3BTkkHtU/Uvfy\r
+ uIQ/NLk4LUjQsX2j4UwrZmwj3Rdg1+Suq4LanpeoP/SPuHtCX6YIvsrzP7WprBXA7E0e\r
+ /qKQnC1oviKypiwE8Pk4QzGtXMlH9biQTFnUsNYZjABF81LTLix0TcHxeNpdJas0VFIM\r
+ FXQoOuGT+Yqtu/Lg+Bq09lfiGSWEOjWeGYBD5Revvn53MQZKg8olUaWU0fexMpSqMipW\r
+ V9MQ==\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references:in-reply-to:references;\r
+ bh=qK/Sq8a9u1XpVLQESV5pNaTbGcGNCTZCBIEd//Ix38A=;\r
+ b=JOMpAavi5mC3mtUZ8uFinfGqtBfEGNVuzg1ZuFabXvk0uSdAas5rsM2+to92UbQ0+Y\r
+ tYd8m2brxLXb+NJpsN9xyJfHuZlUmwihaA+/K9pd5F9EkWvLgyTE0nynzI2B0em41BTI\r
+ IOyBcyLbE6RZQ33ntMJZPhzZU2c70l7Ze0SWWgNLGaeebx1vrl1b06l6kodI0WtfYZKG\r
+ 8ypuuzkn44MOa43882cqOAoyXc3rqfh5zzxZRnhJVrRxlTIab1T5jCkYBcimfN4I0FjA\r
+ znbV+OY9KKx6SfYrf0T/05yvQGNYcczUIyA61KefGZtHalK59DJ741aXYOrcnWY3MGu7\r
+ NZiA==\r
+X-Gm-Message-State:\r
+ AEkoousVtvX3PGZlVYAoTwI4PbUvtc6pz4rNRYF+ciEi6Tm2paGhHrQCIY0yzp9eQAahfA==\r
+X-Received: by 10.194.148.81 with SMTP id tq17mr19703366wjb.67.1471088354427; \r
+ Sat, 13 Aug 2016 04:39:14 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c368-70.dhcp.inet.fi.\r
+ [88.195.104.70])\r
+ by smtp.gmail.com with ESMTPSA id o4sm11781593wjd.15.2016.08.13.04.39.13\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 13 Aug 2016 04:39:14 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Cc: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,\r
+       jani@nikula.org\r
+Subject: [PATCH v2 08/14] cli/reply: reduce the reply format abstractions\r
+Date: Sat, 13 Aug 2016 14:37:32 +0300\r
+Message-Id:\r
+ <b72a0561fb90053ac39e5835e919f58ff457a33a.1471088022.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1471088022.git.jani@nikula.org>\r
+References: <cover.1471088022.git.jani@nikula.org>\r
+In-Reply-To: <cover.1471088022.git.jani@nikula.org>\r
+References: <cover.1471088022.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 13 Aug 2016 11:40:38 -0000\r
+\r
+Now that we've made the various reply formats quite similar to each\r
+other, there's no point in keeping the abstractions. They are now\r
+close enough to be put in one function.\r
+\r
+For now, a mime node will be uselessly created for the headers-only\r
+case, but this is insignificant, and may change in the future.\r
+---\r
+ notmuch-reply.c | 145 ++++++++++++++------------------------------------------\r
+ 1 file changed, 36 insertions(+), 109 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index daad453efb09..b380678e7204 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -599,92 +599,6 @@ create_reply_message(void *ctx,\r
+     return reply;\r
+ }\r
\r
+-static int\r
+-notmuch_reply_format_default(void *ctx,\r
+-                           notmuch_config_t *config,\r
+-                           notmuch_message_t *message,\r
+-                           notmuch_show_params_t *params,\r
+-                           notmuch_bool_t reply_all,\r
+-                           unused (sprinter_t *sp))\r
+-{\r
+-    GMimeMessage *reply;\r
+-    mime_node_t *node;\r
+-\r
+-    if (mime_node_open (ctx, message, &params->crypto, &node))\r
+-      return 1;\r
+-\r
+-    reply = create_reply_message (ctx, config, message, reply_all, FALSE);\r
+-    if (!reply)\r
+-      return 1;\r
+-\r
+-    show_reply_headers (reply);\r
+-    format_part_reply (node);\r
+-\r
+-    g_object_unref (G_OBJECT (reply));\r
+-    talloc_free (node);\r
+-\r
+-    return 0;\r
+-}\r
+-\r
+-static int\r
+-notmuch_reply_format_sprinter(void *ctx,\r
+-                            notmuch_config_t *config,\r
+-                            notmuch_message_t *message,\r
+-                            notmuch_show_params_t *params,\r
+-                            notmuch_bool_t reply_all,\r
+-                            sprinter_t *sp)\r
+-{\r
+-    GMimeMessage *reply;\r
+-    mime_node_t *node;\r
+-\r
+-    if (mime_node_open (ctx, message, &params->crypto, &node))\r
+-      return 1;\r
+-\r
+-    reply = create_reply_message (ctx, config, message, reply_all, FALSE);\r
+-    if (!reply)\r
+-      return 1;\r
+-\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_sprinter (sp, reply, TRUE);\r
+-\r
+-    /* Start the original */\r
+-    sp->map_key (sp, "original");\r
+-    format_part_sprinter (ctx, sp, node, TRUE, TRUE, FALSE);\r
+-\r
+-    /* End */\r
+-    sp->end (sp);\r
+-\r
+-    g_object_unref (G_OBJECT (reply));\r
+-    talloc_free (node);\r
+-\r
+-    return 0;\r
+-}\r
+-\r
+-/* This format is currently tuned for a git send-email --notmuch hook */\r
+-static int\r
+-notmuch_reply_format_headers_only(void *ctx,\r
+-                                notmuch_config_t *config,\r
+-                                notmuch_message_t *message,\r
+-                                unused (notmuch_show_params_t *params),\r
+-                                notmuch_bool_t reply_all,\r
+-                                unused (sprinter_t *sp))\r
+-{\r
+-    GMimeMessage *reply;\r
+-\r
+-    reply = create_reply_message (ctx, config, message, reply_all, TRUE);\r
+-    if (!reply)\r
+-      return 1;\r
+-\r
+-    show_reply_headers (reply);\r
+-\r
+-    g_object_unref (G_OBJECT (reply));\r
+-\r
+-    return 0;\r
+-}\r
+-\r
+ enum {\r
+     FORMAT_DEFAULT,\r
+     FORMAT_JSON,\r
+@@ -698,17 +612,12 @@ static int do_reply(notmuch_config_t *config,\r
+                   int format,\r
+                   notmuch_bool_t reply_all)\r
+ {\r
++    GMimeMessage *reply;\r
++    mime_node_t *node;\r
+     notmuch_messages_t *messages;\r
+     notmuch_message_t *message;\r
+     notmuch_status_t status;\r
+     struct sprinter *sp = NULL;\r
+-    int ret = 0;\r
+-    int (*reply_format_func) (void *ctx,\r
+-                            notmuch_config_t *config,\r
+-                            notmuch_message_t *message,\r
+-                            notmuch_show_params_t *params,\r
+-                            notmuch_bool_t reply_all,\r
+-                            struct sprinter *sp);\r
\r
+     if (format == FORMAT_JSON || format == FORMAT_SEXP) {\r
+       unsigned count;\r
+@@ -721,18 +630,11 @@ static int do_reply(notmuch_config_t *config,\r
+           fprintf (stderr, "Error: search term did not match precisely one message (matched %d messages).\n", count);\r
+           return 1;\r
+       }\r
+-    }\r
\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_sprinter;\r
+-      sp = sprinter_json_create (config, stdout);\r
+-    } else if (format == FORMAT_SEXP) {\r
+-      reply_format_func = notmuch_reply_format_sprinter;\r
+-      sp = sprinter_sexp_create (config, stdout);\r
+-    } else {\r
+-      reply_format_func = notmuch_reply_format_default;\r
++      if (format == FORMAT_JSON)\r
++          sp = sprinter_json_create (config, stdout);\r
++      else\r
++          sp = sprinter_sexp_create (config, stdout);\r
+     }\r
\r
+     status = notmuch_query_search_messages_st (query, &messages);\r
+@@ -745,15 +647,40 @@ static int do_reply(notmuch_config_t *config,\r
+     {\r
+       message = notmuch_messages_get (messages);\r
\r
+-      ret = reply_format_func(config, config, message, params, reply_all, sp);\r
++      if (mime_node_open (config, message, &params->crypto, &node))\r
++          return 1;\r
\r
+-      notmuch_message_destroy (message);\r
++      reply = create_reply_message (config, config, message, reply_all,\r
++                                    format == FORMAT_HEADERS_ONLY);\r
++      if (!reply)\r
++          return 1;\r
\r
+-      if (ret)\r
+-          break;\r
++      if (format == FORMAT_JSON || format == FORMAT_SEXP) {\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_sprinter (sp, reply, TRUE);\r
++\r
++          /* Start the original */\r
++          sp->map_key (sp, "original");\r
++          format_part_sprinter (config, sp, node, TRUE, TRUE, FALSE);\r
++\r
++          /* End */\r
++          sp->end (sp);\r
++      } else {\r
++          show_reply_headers (reply);\r
++          if (format == FORMAT_DEFAULT)\r
++              format_part_reply (node);\r
++      }\r
++\r
++      g_object_unref (G_OBJECT (reply));\r
++      talloc_free (node);\r
++\r
++      notmuch_message_destroy (message);\r
+     }\r
\r
+-    return ret;\r
++    return 0;\r
+ }\r
\r
+ int\r
+-- \r
+2.1.4\r
+\r