[PATCH v2 07/14] cli/reply: reuse create_reply_message() also for headers-only format
authorJani Nikula <jani@nikula.org>
Sat, 13 Aug 2016 11:37:31 +0000 (14:37 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:22:25 +0000 (16:22 -0700)
c9/394d6942e881100d6477e87a2763794090a207 [new file with mode: 0644]

diff --git a/c9/394d6942e881100d6477e87a2763794090a207 b/c9/394d6942e881100d6477e87a2763794090a207
new file mode 100644 (file)
index 0000000..7294f35
--- /dev/null
@@ -0,0 +1,182 @@
+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 D72186DE3A57\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:43 -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.574\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.574 tagged_above=-999 required=5 tests=[AWL=0.146,\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 4MD4dv6l_A22 for <notmuch@notmuchmail.org>;\r
+ Sat, 13 Aug 2016 04:39:36 -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 5575F6DE38DA for\r
+ <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:14 -0700 (PDT)\r
+Received: by mail-wm0-f66.google.com with SMTP id q128so2021111wma.1\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:14 -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=b7QIri2DRzrN84f47fMDjjHS9mXCicuyiHHSgXz6VoA=;\r
+ b=IJZLuaO+Amv1DR5W5YJoLF9Rdn4SvuxlXUHR4ejxeVn/s8FRstUG5m4Q/Agwjfgv0U\r
+ ooCWDHb0Ebmsw6UxHRIQGhLlLNa7sj/M88MR85egAFtA7CxEA0ep6RnQ4cxQNeN044nV\r
+ s+RBKMpqj74ZdyfyRPimvCpnnN6jfI4KofRgTZZdDAQsDGkBoFCi6VS2K2i9ze5LtUXQ\r
+ KJt310W+WPZqEufwx/MfMV/lOyO3noFgwQUsA4dCjAATcC9ecdidSWZr/dexkiaCZuSG\r
+ e7yVT4bfDcE7DbsYlzQLg1ql4yXSxyTYzn+Jm5FQN4H5y2/2Z/93hLBt4T1+1naDMEPL\r
+ +Kug==\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=b7QIri2DRzrN84f47fMDjjHS9mXCicuyiHHSgXz6VoA=;\r
+ b=CnuDcdrol9wx/hRAomK7rdnwhno6Fub5O2x4SDCRV9zaKuNesTfCCfbvU+8QCy4fhd\r
+ uLWOfvDmwir34Vjmg9mrT68WGjUvlMQ7GLa7FdaAuU5GKHzpjYIH8t2xp+yfmzgrPszA\r
+ t3LUwQ8fTgw148YlT7lwWCQhktcEhU97hxjAijxJ2NxuljgCiCouWkfNNUkTIRMB1YQq\r
+ 02DCUvTFLy0DxaDfdApfhCzE1ml3JIZacnZxQ+xwuJ3jzmuDXyfmnte6LKJ6F6MN7PO6\r
+ qI7r7wSvh7psdn+rtxTMoqKxAcqIoyuoeThZ081x7VjEz0dz8qpu0zpeLWDECcHyaq6X\r
+ DTvg==\r
+X-Gm-Message-State:\r
+ AEkooutix+7JQA8qIkopAJpJ1H69K7ClZYo1TBMMxwkaeVMPuoRaXi0amXydR4KMumgiwg==\r
+X-Received: by 10.194.35.42 with SMTP id e10mr20014626wjj.107.1471088352970;\r
+ Sat, 13 Aug 2016 04:39:12 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee63-250.dhcp.inet.fi.\r
+ [188.238.99.250])\r
+ by smtp.gmail.com with ESMTPSA id bw9sm11773689wjc.33.2016.08.13.04.39.12\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 13 Aug 2016 04:39:12 -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 07/14] cli/reply: reuse create_reply_message() also for\r
+ headers-only format\r
+Date: Sat, 13 Aug 2016 14:37:31 +0300\r
+Message-Id:\r
+ <f64a12b6237f86f4ab26d84a40408846ce9ff04c.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:39:43 -0000\r
+\r
+Add an option for "limited" headers for the (slightly misleadingly\r
+named) headers-only format. There should be no functional changes.\r
+---\r
+ notmuch-reply.c | 46 +++++++++++++++-------------------------------\r
+ 1 file changed, 15 insertions(+), 31 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index c2d7402d40ae..daad453efb09 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -520,13 +520,17 @@ static GMimeMessage *\r
+ create_reply_message(void *ctx,\r
+                    notmuch_config_t *config,\r
+                    notmuch_message_t *message,\r
+-                   notmuch_bool_t reply_all)\r
++                   notmuch_bool_t reply_all,\r
++                   notmuch_bool_t limited)\r
+ {\r
+     const char *subject, *from_addr = NULL;\r
+     const char *in_reply_to, *orig_references, *references;\r
\r
+-    /* The 1 means we want headers in a "pretty" order. */\r
+-    GMimeMessage *reply = g_mime_message_new (1);\r
++    /*\r
++     * Use the below header order for limited headers, "pretty" order\r
++     * otherwise.\r
++     */\r
++    GMimeMessage *reply = g_mime_message_new (limited ? 0 : 1);\r
+     if (reply == NULL) {\r
+       fprintf (stderr, "Out of memory\n");\r
+       return NULL;\r
+@@ -549,6 +553,10 @@ create_reply_message(void *ctx,\r
+     from_addr = add_recipients_from_message (reply, config,\r
+                                            message, reply_all);\r
\r
++    /* The above is all that is needed for limited headers. */\r
++    if (limited)\r
++      return reply;\r
++\r
+     /*\r
+      * Sadly, there is no standard way to find out to which email\r
+      * address a mail was delivered - what is in the headers depends\r
+@@ -605,7 +613,7 @@ notmuch_reply_format_default(void *ctx,\r
+     if (mime_node_open (ctx, message, &params->crypto, &node))\r
+       return 1;\r
\r
+-    reply = create_reply_message (ctx, config, message, reply_all);\r
++    reply = create_reply_message (ctx, config, message, reply_all, FALSE);\r
+     if (!reply)\r
+       return 1;\r
\r
+@@ -632,7 +640,7 @@ notmuch_reply_format_sprinter(void *ctx,\r
+     if (mime_node_open (ctx, message, &params->crypto, &node))\r
+       return 1;\r
\r
+-    reply = create_reply_message (ctx, config, message, reply_all);\r
++    reply = create_reply_message (ctx, config, message, reply_all, FALSE);\r
+     if (!reply)\r
+       return 1;\r
\r
+@@ -665,34 +673,10 @@ notmuch_reply_format_headers_only(void *ctx,\r
+                                 unused (sprinter_t *sp))\r
+ {\r
+     GMimeMessage *reply;\r
+-    const char *in_reply_to, *orig_references, *references;\r
\r
+-    /* The 0 means we do not want headers in a "pretty" order. */\r
+-    reply = g_mime_message_new (0);\r
+-    if (reply == NULL) {\r
+-      fprintf (stderr, "Out of memory\n");\r
++    reply = create_reply_message (ctx, config, message, reply_all, TRUE);\r
++    if (!reply)\r
+       return 1;\r
+-    }\r
+-\r
+-    in_reply_to = talloc_asprintf (ctx, "<%s>",\r
+-                                 notmuch_message_get_message_id (message));\r
+-\r
+-    g_mime_object_set_header (GMIME_OBJECT (reply), "In-Reply-To", in_reply_to);\r
+-\r
+-    orig_references = notmuch_message_get_header (message, "references");\r
+-\r
+-    /*\r
+-     * We print In-Reply-To followed by References because git\r
+-     * format-patch treats them specially. Git does not interpret the\r
+-     * other headers specially.\r
+-     */\r
+-    references = talloc_asprintf (ctx, "%s%s%s",\r
+-                                orig_references ? orig_references : "",\r
+-                                orig_references ? " " : "",\r
+-                                in_reply_to);\r
+-    g_mime_object_set_header (GMIME_OBJECT (reply), "References", references);\r
+-\r
+-    (void)add_recipients_from_message (reply, config, message, reply_all);\r
\r
+     show_reply_headers (reply);\r
\r
+-- \r
+2.1.4\r
+\r