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 BAC2C6DE2D92 for ; Sat, 13 Aug 2016 04:40:38 -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.266 X-Spam-Level: X-Spam-Status: No, score=0.266 tagged_above=-999 required=5 tests=[AWL=0.986, 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 no16u5ptnUoX for ; Sat, 13 Aug 2016 04:40:30 -0700 (PDT) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id 031126DE390F for ; Sat, 13 Aug 2016 04:39:16 -0700 (PDT) Received: by mail-wm0-f66.google.com with SMTP id i138so2004422wmf.3 for ; Sat, 13 Aug 2016 04:39:15 -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=htlnE83+aAr53bHBjx7OtYwDtc5YcNbk+NIxrvCW80wSIEdpWUya8aPU0ioOGH408x fF4elBuwXya3ebLEKH9Cca0lHlmkzbb9g9lp3BUfOX5T+VlVvSgEUU/3BTkkHtU/Uvfy uIQ/NLk4LUjQsX2j4UwrZmwj3Rdg1+Suq4LanpeoP/SPuHtCX6YIvsrzP7WprBXA7E0e /qKQnC1oviKypiwE8Pk4QzGtXMlH9biQTFnUsNYZjABF81LTLix0TcHxeNpdJas0VFIM FXQoOuGT+Yqtu/Lg+Bq09lfiGSWEOjWeGYBD5Revvn53MQZKg8olUaWU0fexMpSqMipW V9MQ== 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=JOMpAavi5mC3mtUZ8uFinfGqtBfEGNVuzg1ZuFabXvk0uSdAas5rsM2+to92UbQ0+Y tYd8m2brxLXb+NJpsN9xyJfHuZlUmwihaA+/K9pd5F9EkWvLgyTE0nynzI2B0em41BTI IOyBcyLbE6RZQ33ntMJZPhzZU2c70l7Ze0SWWgNLGaeebx1vrl1b06l6kodI0WtfYZKG 8ypuuzkn44MOa43882cqOAoyXc3rqfh5zzxZRnhJVrRxlTIab1T5jCkYBcimfN4I0FjA znbV+OY9KKx6SfYrf0T/05yvQGNYcczUIyA61KefGZtHalK59DJ741aXYOrcnWY3MGu7 NZiA== X-Gm-Message-State: AEkoousVtvX3PGZlVYAoTwI4PbUvtc6pz4rNRYF+ciEi6Tm2paGhHrQCIY0yzp9eQAahfA== X-Received: by 10.194.148.81 with SMTP id tq17mr19703366wjb.67.1471088354427; Sat, 13 Aug 2016 04:39:14 -0700 (PDT) Received: from localhost (dsl-hkibrasgw2-58c368-70.dhcp.inet.fi. [88.195.104.70]) by smtp.gmail.com with ESMTPSA id o4sm11781593wjd.15.2016.08.13.04.39.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Aug 2016 04:39:14 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Cc: Daniel Kahn Gillmor , jani@nikula.org Subject: [PATCH v2 08/14] cli/reply: reduce the reply format abstractions Date: Sat, 13 Aug 2016 14:37:32 +0300 Message-Id: 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, 13 Aug 2016 11:40:38 -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