From e5d309ff19bb5fa02f62b71edc26a59e206613a9 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sun, 19 Jun 2016 00:31:33 +0300 Subject: [PATCH] [PATCH 7/7] cli/reply: reduce the reply format abstractions --- a0/6a365d5a729d473a12c156c58701aa31574e39 | 280 ++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 a0/6a365d5a729d473a12c156c58701aa31574e39 diff --git a/a0/6a365d5a729d473a12c156c58701aa31574e39 b/a0/6a365d5a729d473a12c156c58701aa31574e39 new file mode 100644 index 000000000..417437107 --- /dev/null +++ b/a0/6a365d5a729d473a12c156c58701aa31574e39 @@ -0,0 +1,280 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id A5DB86DE02D5 + for ; Sat, 18 Jun 2016 14:33:34 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.563 +X-Spam-Level: +X-Spam-Status: No, score=-0.563 tagged_above=-999 required=5 tests=[AWL=0.157, + DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, + RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id GEBj5CuFE9NX for ; + Sat, 18 Jun 2016 14:33:26 -0700 (PDT) +Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com + [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 13FDB6DE00DF for + ; Sat, 18 Jun 2016 14:33:10 -0700 (PDT) +Received: by mail-wm0-f65.google.com with SMTP id r201so5510207wme.0 + for ; Sat, 18 Jun 2016 14:33:09 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=nikula-org.20150623.gappssmtp.com; s=20150623; + h=from:to:cc:subject:date:message-id:in-reply-to:references + :in-reply-to:references; + bh=qK/Sq8a9u1XpVLQESV5pNaTbGcGNCTZCBIEd//Ix38A=; + b=k5FrzhXDGhQGHCaUqVjk3xpJ3Ud0FUQU0/KOv2MSFxS+xELLcLSg+gO2JMunwnJSGL + 2aBHxw6FnzeDvZ0rWeWSoe77pk9t6zDzk5lQR+nqML9UYpmzkqMqh1tRRMO+1UvTZX9v + dKaZFIZjDklwMi0WueJZqtfFb5Gk8eBkDt9+mVGuKa8psih+ueHBTsmdcBDBierfOved + GhNd5+OHODFiyM5kNus+fQO0vib5ZJZQj7WVcz+atLI6xjcZCgx+stEkx3cq/JAWGx4e + CujzjOm90nF4Hi26JLml4PmDCdtcpPVxc3kvKxV3BiSswPGVAg5LLvyO6ZkBb9WWhr2B + N48Q== +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=qK/Sq8a9u1XpVLQESV5pNaTbGcGNCTZCBIEd//Ix38A=; + b=CxJwW3gHeiWjdRo0IjK4StIVXZJI9zYV0rjpv0XEV4R+FUB4fGogn5B2WCu9lCrPBH + LabQMCD0tWS9guZYBi2Fkw6zi98Z9IvbK2qzHr0p0lEMzTltywv0zfFakrxhRf+ilg4l + apD3VxWPhXeTKVQiGktl42O8ApWUYUOr2MIqTE5MJNo1pOSiZvMtnEhO2QjLkDRd7Nvs + Wwey/Mf/bX3ZCKFGofgFO2RTEifX2cqW9GoGKnN5jRroEC3pnN9eo040FGCsBSOXvtZw + b3npBkawsaVzMpAzjF/69eoS5s+fprTR7lQk7vHLIRgVRWFkuP91aZqcANLe2ju4Csjh + 0kig== +X-Gm-Message-State: + ALyK8tInCjuaIvxZ2wOt2MlsoyiWY8ShHUhoyM2wYFj8CQ3A0g250fmW4CuMEERvaviZpw== +X-Received: by 10.194.172.36 with SMTP id az4mr8874120wjc.114.1466285588658; + Sat, 18 Jun 2016 14:33:08 -0700 (PDT) +Received: from localhost (mobile-access-bcee4e-81.dhcp.inet.fi. + [188.238.78.81]) + by smtp.gmail.com with ESMTPSA id a84sm5510049wma.0.2016.06.18.14.33.07 + (version=TLSv1/SSLv3 cipher=OTHER); + Sat, 18 Jun 2016 14:33:08 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Cc: jani@nikula.org, + Daniel Kahn Gillmor +Subject: [PATCH 7/7] cli/reply: reduce the reply format abstractions +Date: Sun, 19 Jun 2016 00:31:33 +0300 +Message-Id: + <877365e0fb4a3b0da33db2ce72aa51b16fccbe9a.1466284726.git.jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +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: Sat, 18 Jun 2016 21:33:34 -0000 + +Now that we've made the various reply formats quite similar to each +other, there's no point in keeping the abstractions. They are now +close enough to be put in one function. + +For now, a mime node will be uselessly created for the headers-only +case, but this is insignificant, and may change in the future. +--- + notmuch-reply.c | 145 ++++++++++++++------------------------------------------ + 1 file changed, 36 insertions(+), 109 deletions(-) + +diff --git a/notmuch-reply.c b/notmuch-reply.c +index daad453efb09..b380678e7204 100644 +--- a/notmuch-reply.c ++++ b/notmuch-reply.c +@@ -599,92 +599,6 @@ create_reply_message(void *ctx, + return reply; + } + +-static int +-notmuch_reply_format_default(void *ctx, +- notmuch_config_t *config, +- notmuch_message_t *message, +- notmuch_show_params_t *params, +- notmuch_bool_t reply_all, +- unused (sprinter_t *sp)) +-{ +- GMimeMessage *reply; +- mime_node_t *node; +- +- if (mime_node_open (ctx, message, ¶ms->crypto, &node)) +- return 1; +- +- reply = create_reply_message (ctx, config, message, reply_all, FALSE); +- if (!reply) +- return 1; +- +- show_reply_headers (reply); +- format_part_reply (node); +- +- g_object_unref (G_OBJECT (reply)); +- talloc_free (node); +- +- return 0; +-} +- +-static int +-notmuch_reply_format_sprinter(void *ctx, +- notmuch_config_t *config, +- notmuch_message_t *message, +- notmuch_show_params_t *params, +- notmuch_bool_t reply_all, +- sprinter_t *sp) +-{ +- GMimeMessage *reply; +- mime_node_t *node; +- +- if (mime_node_open (ctx, message, ¶ms->crypto, &node)) +- return 1; +- +- reply = create_reply_message (ctx, config, message, reply_all, FALSE); +- if (!reply) +- return 1; +- +- sp->begin_map (sp); +- +- /* The headers of the reply message we've created */ +- sp->map_key (sp, "reply-headers"); +- format_headers_sprinter (sp, reply, TRUE); +- +- /* Start the original */ +- sp->map_key (sp, "original"); +- format_part_sprinter (ctx, sp, node, TRUE, TRUE, FALSE); +- +- /* End */ +- sp->end (sp); +- +- g_object_unref (G_OBJECT (reply)); +- talloc_free (node); +- +- return 0; +-} +- +-/* This format is currently tuned for a git send-email --notmuch hook */ +-static int +-notmuch_reply_format_headers_only(void *ctx, +- notmuch_config_t *config, +- notmuch_message_t *message, +- unused (notmuch_show_params_t *params), +- notmuch_bool_t reply_all, +- unused (sprinter_t *sp)) +-{ +- GMimeMessage *reply; +- +- reply = create_reply_message (ctx, config, message, reply_all, TRUE); +- if (!reply) +- return 1; +- +- show_reply_headers (reply); +- +- g_object_unref (G_OBJECT (reply)); +- +- return 0; +-} +- + enum { + FORMAT_DEFAULT, + FORMAT_JSON, +@@ -698,17 +612,12 @@ static int do_reply(notmuch_config_t *config, + int format, + notmuch_bool_t reply_all) + { ++ GMimeMessage *reply; ++ mime_node_t *node; + notmuch_messages_t *messages; + notmuch_message_t *message; + notmuch_status_t status; + struct sprinter *sp = NULL; +- int ret = 0; +- int (*reply_format_func) (void *ctx, +- notmuch_config_t *config, +- notmuch_message_t *message, +- notmuch_show_params_t *params, +- notmuch_bool_t reply_all, +- struct sprinter *sp); + + if (format == FORMAT_JSON || format == FORMAT_SEXP) { + unsigned count; +@@ -721,18 +630,11 @@ static int do_reply(notmuch_config_t *config, + fprintf (stderr, "Error: search term did not match precisely one message (matched %d messages).\n", count); + return 1; + } +- } + +- if (format == FORMAT_HEADERS_ONLY) { +- reply_format_func = notmuch_reply_format_headers_only; +- } else if (format == FORMAT_JSON) { +- reply_format_func = notmuch_reply_format_sprinter; +- sp = sprinter_json_create (config, stdout); +- } else if (format == FORMAT_SEXP) { +- reply_format_func = notmuch_reply_format_sprinter; +- sp = sprinter_sexp_create (config, stdout); +- } else { +- reply_format_func = notmuch_reply_format_default; ++ if (format == FORMAT_JSON) ++ sp = sprinter_json_create (config, stdout); ++ else ++ sp = sprinter_sexp_create (config, stdout); + } + + status = notmuch_query_search_messages_st (query, &messages); +@@ -745,15 +647,40 @@ static int do_reply(notmuch_config_t *config, + { + message = notmuch_messages_get (messages); + +- ret = reply_format_func(config, config, message, params, reply_all, sp); ++ if (mime_node_open (config, message, ¶ms->crypto, &node)) ++ return 1; + +- notmuch_message_destroy (message); ++ reply = create_reply_message (config, config, message, reply_all, ++ format == FORMAT_HEADERS_ONLY); ++ if (!reply) ++ return 1; + +- if (ret) +- break; ++ if (format == FORMAT_JSON || format == FORMAT_SEXP) { ++ sp->begin_map (sp); ++ ++ /* The headers of the reply message we've created */ ++ sp->map_key (sp, "reply-headers"); ++ format_headers_sprinter (sp, reply, TRUE); ++ ++ /* Start the original */ ++ sp->map_key (sp, "original"); ++ format_part_sprinter (config, sp, node, TRUE, TRUE, FALSE); ++ ++ /* End */ ++ sp->end (sp); ++ } else { ++ show_reply_headers (reply); ++ if (format == FORMAT_DEFAULT) ++ format_part_reply (node); ++ } ++ ++ g_object_unref (G_OBJECT (reply)); ++ talloc_free (node); ++ ++ notmuch_message_destroy (message); + } + +- return ret; ++ return 0; + } + + int +-- +2.1.4 + -- 2.26.2