[PATCH v2 09/14] cli/reply: use dedicated functions for reply to mapping
authorJani Nikula <jani@nikula.org>
Sat, 13 Aug 2016 11:37:33 +0000 (14:37 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:22:25 +0000 (16:22 -0700)
c7/99a05c0dc059d8d7d080fdf66a0bb53f72903d [new file with mode: 0644]

diff --git a/c7/99a05c0dc059d8d7d080fdf66a0bb53f72903d b/c7/99a05c0dc059d8d7d080fdf66a0bb53f72903d
new file mode 100644 (file)
index 0000000..7206a1b
--- /dev/null
@@ -0,0 +1,214 @@
+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 B37636DE33F3\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:40:49 -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 5EBo5uqOBVAu for <notmuch@notmuchmail.org>;\r
+ Sat, 13 Aug 2016 04:40:41 -0700 (PDT)\r
+Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com\r
+ [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 528266DE3961 for\r
+ <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:17 -0700 (PDT)\r
+Received: by mail-wm0-f65.google.com with SMTP id i5so2016939wmg.2\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:17 -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=sbzxgVh77OTRgCS2fy6ZyXpGO2DUrHQHBnwwr4b1KBfp4MwpPP7BB/eXow9SEP8vxn\r
+ PJwPPAr1J0iyI2IXJ8YyaXjmhq/kiocaXUhkJDXZIjWg8lG19Vva085CcZUll0JlrLTp\r
+ wvYMeg0jm/5Hm1IX28cAsM8XM32QP73XUzXqC7JZoOdC6ac4VGiCuG2JE34qbFK/acRs\r
+ qvviOsAB5L0Yvyfp3RIln1WBJ9oL0F6eG2y34iqyDip5IFVffDVrVJ8CsMK9F3fsSe46\r
+ DwVYzaWBHYvPoO46u8mIf3XfuEgHqo87X4IN8EWYZJc+CmiM1AYxQNZng/XPuRNWT59e\r
+ 0luw==\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=I7V5O1X7F9rDd2yS+wC0tLpkXHJoNu8RBUpQ4asiwFj+10vuQkeuDPEHX6N758LX9e\r
+ ifMq89VtoP0+6I5R3jLcDjb0wWuZkM23tT412tLAuMqUM1f/ZVreWiId6WXwEnIpS5nH\r
+ iALPmZDOSuWcDoOtOvKEF9jcHVSnK2JmeQHDpIHdwCzGuNZI2vHus50U4FtzOKRTWnBH\r
+ 6uuvPbvdHy8uVYDV00H62/tCFfwzv1eHKwoITTl3Xc0qh5Y4CGWg71H1buo0gtuZSvDC\r
+ f0HZtJ/lvQHab9CMPZt3AthfRmrBr1no9QpHVj+Fa3/+0pW81/IZUpHc99sTOJwJmX+g\r
+ tG3Q==\r
+X-Gm-Message-State:\r
+ AEkoous7h0BbGYXDUYsw0W9SHOyTapM/6VKnNRYewi43JZ217/hdrkOJILrQnCr2ZfOjRw==\r
+X-Received: by 10.194.136.196 with SMTP id qc4mr23185541wjb.136.1471088355908;\r
+  Sat, 13 Aug 2016 04:39:15 -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 a184sm6950592wmh.1.2016.08.13.04.39.15\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 13 Aug 2016 04:39:15 -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 09/14] cli/reply: use dedicated functions for reply to\r
+ mapping\r
+Date: Sat, 13 Aug 2016 14:37:33 +0300\r
+Message-Id:\r
+ <9a4c17307d2fe3865fd62b38cb9195c1eba31c14.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:40:49 -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