--- /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 179C16DE0360\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:13 -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.568\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.568 tagged_above=-999 required=5 tests=[AWL=0.152,\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 YqqYV9wV4n3x for <notmuch@notmuchmail.org>;\r
+ Sun, 19 Jun 2016 13:17:04 -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 DAD7E6DE0188 for\r
+ <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:03 -0700 (PDT)\r
+Received: by mail-wm0-f66.google.com with SMTP id 187so9592334wmz.1\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:03 -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=pcw6+Tq9er4sa7ROzNemL06kbs8q3+z/oOQXlztCE88=;\r
+ b=cDLOVrZyeD+vr4nxuuQ7tUd18SX8Omhjeqibq1jeQqzCsuisVJgw4TQB22qTU/0JZ/\r
+ H5+xVJsYEwtZuB0KDr8rlFB6W5TaSuVoWJ6QPCZCioA1SnB7aX+Pb6tCGStyDszHU9XT\r
+ 0pNwA1mtSlhQTas4TGyqjaGOox6MHDWWu0bWizJRi6ssAabw9WyTSrwQ1S0jNTYSiCVO\r
+ yb3DsMQ5g+s81GlAqkuQwPSbBGAl0mrgDz/gho3YSGtVkc6PpcUjEDFVRFWo8XXJA++Q\r
+ P5v+jiythEc1HQp7MHD4NhgjVpJbgVV+WsVQ//TUbXe7j8Onlk84PHZIBYcTmptfgg5m\r
+ 1TEw==\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=pcw6+Tq9er4sa7ROzNemL06kbs8q3+z/oOQXlztCE88=;\r
+ b=WQ8gfrezFt/f491EXXGzcFYSQXfVpKuo/UUTruTL5uRfRwI7TM2VCEMJxzcw8aSE4K\r
+ JEnA1nrIyd2ML2b7dRVb9Xt2hOqmaTiA2I1pPecPk1FTiKUwiqdfDATnne4YT/nx0W3E\r
+ E77UQDkdTO1DaGO7ajTfvxzNiWNWlxb0yzeoKz/UkTdjeoGxebGuNhg/Xev4tPhRe1oO\r
+ dTtqohoGDwCmCpVUSixGiuxM0mgaG17/7ybZhLRJlcAZyWhWrafzfos26cMo2MLkuW44\r
+ lQT0SvBFJNU7JmCanh84/CmjVdpiNMcYpWQCAzfIW+ICrdIjjE9PfVopP0lDYRnY75LD\r
+ MjwQ==\r
+X-Gm-Message-State:\r
+ ALyK8tKLxZ6QxoQae6KGydvzWAQb/ICwslAjya0ohIW72MSLmSOoB3C0yiUcGg6HGIkDbg==\r
+X-Received: by 10.194.80.70 with SMTP id p6mr10967510wjx.45.1466367422322;\r
+ Sun, 19 Jun 2016 13:17:02 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee4e-81.dhcp.inet.fi.\r
+ [188.238.78.81])\r
+ by smtp.gmail.com with ESMTPSA id x83sm4796283wmx.9.2016.06.19.13.17.01\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sun, 19 Jun 2016 13:17:01 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Jani Nikula <jani@nikula.org>,\r
+ notmuch@notmuchmail.org\r
+Cc: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+Subject: [RFC PATCH 1/6] cli/reply: use dedicated functions for reply to\r
+ mapping\r
+Date: Sun, 19 Jun 2016 23:15:29 +0300\r
+Message-Id:\r
+ <f56829444b25ef8626cbc04e4f55e9d1c47a4a5e.1466366737.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1466366737.git.jani@nikula.org>\r
+References: <cover.1466284726.git.jani@nikula.org>\r
+ <cover.1466366737.git.jani@nikula.org>\r
+In-Reply-To: <cover.1466366737.git.jani@nikula.org>\r
+References: <cover.1466366737.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: Sun, 19 Jun 2016 20:17:13 -0000\r
+\r
+The main motivation here is to move the special casing around\r
+reply-to/from handling into a function of its own, clarifying the main\r
+logic.\r
+---\r
+ notmuch-reply.c | 82 ++++++++++++++++++++++++++++++++++-----------------------\r
+ 1 file changed, 49 insertions(+), 33 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index b380678e7204..9b78ea2c2b20 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -256,17 +256,13 @@ scan_address_string (const char *recipients,\r
+ * in either the 'To' or 'Cc' header of the message?\r
+ */\r
+ static int\r
+-reply_to_header_is_redundant (notmuch_message_t *message)\r
++reply_to_header_is_redundant (notmuch_message_t *message, const char *reply_to)\r
+ {\r
+- const char *reply_to, *to, *cc, *addr;\r
++ const char *to, *cc, *addr;\r
+ InternetAddressList *list;\r
+ InternetAddress *address;\r
+ InternetAddressMailbox *mailbox;\r
+ \r
+- reply_to = notmuch_message_get_header (message, "reply-to");\r
+- if (reply_to == NULL || *reply_to == '\0')\r
+- return 0;\r
+-\r
+ list = internet_address_list_parse_string (reply_to);\r
+ \r
+ if (internet_address_list_length (list) != 1)\r
+@@ -291,6 +287,47 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
+ return 0;\r
+ }\r
+ \r
++static const char *get_sender(notmuch_message_t *message)\r
++{\r
++ const char *reply_to;\r
++\r
++ reply_to = notmuch_message_get_header (message, "reply-to");\r
++ if (reply_to && *reply_to) {\r
++ /*\r
++ * Some mailing lists munge the Reply-To header despite it\r
++ * being A Bad Thing, see\r
++ * http://marc.merlins.org/netrants/reply-to-harmful.html\r
++ *\r
++ * The munging is easy to detect, because it results in a\r
++ * redundant reply-to header, (with an address that already\r
++ * exists in either To or Cc). So in this case, we ignore the\r
++ * Reply-To field and use the From header. This ensures the\r
++ * original sender will get the reply even if not subscribed\r
++ * to the list. Note that the address in the Reply-To header\r
++ * will always appear in the reply if reply_all is true.\r
++ */\r
++ if (! reply_to_header_is_redundant (message, reply_to))\r
++ return reply_to;\r
++ }\r
++\r
++ return notmuch_message_get_header (message, "from");\r
++}\r
++\r
++static const char *get_to(notmuch_message_t *message)\r
++{\r
++ return notmuch_message_get_header (message, "to");\r
++}\r
++\r
++static const char *get_cc(notmuch_message_t *message)\r
++{\r
++ return notmuch_message_get_header (message, "cc");\r
++}\r
++\r
++static const char *get_bcc(notmuch_message_t *message)\r
++{\r
++ return notmuch_message_get_header (message, "bcc");\r
++}\r
++\r
+ /* Augment the recipients of 'reply' from the "Reply-to:", "From:",\r
+ * "To:", "Cc:", and "Bcc:" headers of 'message'.\r
+ *\r
+@@ -310,43 +347,22 @@ add_recipients_from_message (GMimeMessage *reply,\r
+ notmuch_bool_t reply_all)\r
+ {\r
+ struct {\r
+- const char *header;\r
+- const char *fallback;\r
++ const char * (*get_header)(notmuch_message_t *message);\r
+ GMimeRecipientType recipient_type;\r
+ } reply_to_map[] = {\r
+- { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO },\r
+- { "to", NULL, GMIME_RECIPIENT_TYPE_TO },\r
+- { "cc", NULL, GMIME_RECIPIENT_TYPE_CC },\r
+- { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }\r
++ { get_sender, GMIME_RECIPIENT_TYPE_TO },\r
++ { get_to, GMIME_RECIPIENT_TYPE_TO },\r
++ { get_cc, GMIME_RECIPIENT_TYPE_CC },\r
++ { get_bcc, GMIME_RECIPIENT_TYPE_BCC },\r
+ };\r
+ const char *from_addr = NULL;\r
+ unsigned int i;\r
+ unsigned int n = 0;\r
+ \r
+- /* Some mailing lists munge the Reply-To header despite it being A Bad\r
+- * Thing, see http://marc.merlins.org/netrants/reply-to-harmful.html\r
+- *\r
+- * The munging is easy to detect, because it results in a\r
+- * redundant reply-to header, (with an address that already exists\r
+- * in either To or Cc). So in this case, we ignore the Reply-To\r
+- * field and use the From header. This ensures the original sender\r
+- * will get the reply even if not subscribed to the list. Note\r
+- * that the address in the Reply-To header will always appear in\r
+- * the reply if reply_all is true.\r
+- */\r
+- if (reply_to_header_is_redundant (message)) {\r
+- reply_to_map[0].header = "from";\r
+- reply_to_map[0].fallback = NULL;\r
+- }\r
+-\r
+ for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
+ const char *recipients;\r
+ \r
+- recipients = notmuch_message_get_header (message,\r
+- reply_to_map[i].header);\r
+- if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback)\r
+- recipients = notmuch_message_get_header (message,\r
+- reply_to_map[i].fallback);\r
++ recipients = reply_to_map[i].get_header (message);\r
+ \r
+ n += scan_address_string (recipients, config, reply,\r
+ reply_to_map[i].recipient_type, &from_addr);\r
+-- \r
+2.1.4\r
+\r