--- /dev/null
+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 09CD56DE092A\r
+ for <notmuch@notmuchmail.org>; Sat, 18 Jun 2016 14:33:25 -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.505\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.505 tagged_above=-999 required=5 tests=[AWL=1.225, \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 8HV_uJGfYNBP for <notmuch@notmuchmail.org>;\r
+ Sat, 18 Jun 2016 14:33:17 -0700 (PDT)\r
+Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com\r
+ [74.125.82.68]) by arlo.cworth.org (Postfix) with ESMTPS id 3D6BE6DE028C for\r
+ <notmuch@notmuchmail.org>; Sat, 18 Jun 2016 14:33:05 -0700 (PDT)\r
+Received: by mail-wm0-f68.google.com with SMTP id r201so5510009wme.0\r
+ for <notmuch@notmuchmail.org>; Sat, 18 Jun 2016 14:33:05 -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=fbeShvw4M66SrxkIEgtBhkFxVPPUGacbY8QcRCVt1P8=;\r
+ b=TuT63OI69vQWCgyoYinWpBLsWhLPf89uKOBeP0/497r7W/8SGwkpezKJZg+o6d09tY\r
+ o1x1JFB3UcEsLRt5KEYTqLyY/ozgffjSTldK5Xw9XMvKs+IB8saI/PTeMO+XlO3cjq1B\r
+ WAwVRudJp4A1lTM6eJUSff62hhfY/Rl1mZGA3ki3fqUzLmiZrWrbCo5k/e5QkUT8BKLY\r
+ IMylLqjzM/+O0QDhjfimP1LYdWdl5bzwQcZ7a2GWFZF9S2KcTv3uzxm8QvtmsOt/6Phm\r
+ hiZpIAJRgMWhA0AS8wwSE9r+F9m1a2iOenEU9FSe2QugWOB8AzbmRgUYndJ0Lc0n+LR9\r
+ +kSA==\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=fbeShvw4M66SrxkIEgtBhkFxVPPUGacbY8QcRCVt1P8=;\r
+ b=eXJX2QJbSYdentWTtakc5lE3Z98ONp95alzqJ3MoP5s4zxUfpDbnkTJETe5E5H6B75\r
+ ZHddAbBE7izwLiDXlwcnP/X6dSf1z5pT2Yweqo+788Bu5Vrx6GbomS4ea4I9SeAJtNYG\r
+ 4x4PTOFx/wjJZxEAcHZPqMB2O+zXKO6l+Tyt8/NEvGzNJE5Vtl70s69l5CXy6eHqF7bO\r
+ NGHTxinpnmeKfuKzFNipWPkPCC2+uEasCTMPdGVaQigx9gVluT/WEzzggyC3EwmmGmaq\r
+ kpxcbIc4DPodITRqPSO0yLLlHvBs4rbkwNwBtbGTIreRyO4bl9fYs110uYTSJHQGuaqn\r
+ EAhg==\r
+X-Gm-Message-State:\r
+ ALyK8tLGDtwiFEGvyotgCsNzh+OIOxRZkfCBcC0/IgGlH/RrRWHe3qg68rE61sYrsZZ7hA==\r
+X-Received: by 10.28.26.4 with SMTP id a4mr4124855wma.92.1466285583959;\r
+ Sat, 18 Jun 2016 14:33:03 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c37a-44.dhcp.inet.fi.\r
+ [88.195.122.44])\r
+ by smtp.gmail.com with ESMTPSA id r130sm1676834wmf.20.2016.06.18.14.33.03\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sat, 18 Jun 2016 14:33:03 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Cc: jani@nikula.org,\r
+ Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+Subject: [PATCH 4/7] cli/reply: reorganize create_reply_message()\r
+Date: Sun, 19 Jun 2016 00:31:30 +0300\r
+Message-Id:\r
+ <50d4410b1d865fbf1618febfae2f54c5173243ae.1466284726.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1466284726.git.jani@nikula.org>\r
+References: <cover.1466284726.git.jani@nikula.org>\r
+In-Reply-To: <cover.1466284726.git.jani@nikula.org>\r
+References: <cover.1466284726.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, 18 Jun 2016 21:33:25 -0000\r
+\r
+Again, in preparation for later unification, reorganize\r
+create_reply_message() to be more similar to the open coded version in\r
+the headers-only format reply code. Due to "pretty" header ordering,\r
+there should be no change in output. There should be no functional\r
+changes.\r
+---\r
+ notmuch-reply.c | 45 +++++++++++++++++++++------------------------\r
+ 1 file changed, 21 insertions(+), 24 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 4b97ffa4f096..eb07405591fd 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -532,12 +532,20 @@ create_reply_message(void *ctx,\r
+ return NULL;\r
+ }\r
+ \r
+- subject = notmuch_message_get_header (message, "subject");\r
+- if (subject) {\r
+- if (strncasecmp (subject, "Re:", 3))\r
+- subject = talloc_asprintf (ctx, "Re: %s", subject);\r
+- g_mime_message_set_subject (reply, subject);\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
++ if (!orig_references)\r
++ /* Treat errors like missing References headers. */\r
++ orig_references = "";\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
+ from_addr = add_recipients_from_message (reply, config,\r
+ message, reply_all);\r
+@@ -572,25 +580,14 @@ create_reply_message(void *ctx,\r
+ from_addr = talloc_asprintf (ctx, "%s <%s>",\r
+ notmuch_config_get_user_name (config),\r
+ from_addr);\r
+- g_mime_object_set_header (GMIME_OBJECT (reply),\r
+- "From", from_addr);\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),\r
+- "In-Reply-To", in_reply_to);\r
++ g_mime_object_set_header (GMIME_OBJECT (reply), "From", from_addr);\r
+ \r
+- orig_references = notmuch_message_get_header (message, "references");\r
+- if (!orig_references)\r
+- /* Treat errors like missing References headers. */\r
+- orig_references = "";\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),\r
+- "References", references);\r
++ subject = notmuch_message_get_header (message, "subject");\r
++ if (subject) {\r
++ if (strncasecmp (subject, "Re:", 3))\r
++ subject = talloc_asprintf (ctx, "Re: %s", subject);\r
++ g_mime_message_set_subject (reply, subject);\r
++ }\r
+ \r
+ return reply;\r
+ }\r
+-- \r
+2.1.4\r
+\r