From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id B37636DE33F3 for ; Sat, 13 Aug 2016 04:40:49 -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.574 X-Spam-Level: X-Spam-Status: No, score=-0.574 tagged_above=-999 required=5 tests=[AWL=0.146, 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 5EBo5uqOBVAu for ; Sat, 13 Aug 2016 04:40:41 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 528266DE3961 for ; Sat, 13 Aug 2016 04:39:17 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id i5so2016939wmg.2 for ; Sat, 13 Aug 2016 04:39:17 -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=pcw6+Tq9er4sa7ROzNemL06kbs8q3+z/oOQXlztCE88=; b=sbzxgVh77OTRgCS2fy6ZyXpGO2DUrHQHBnwwr4b1KBfp4MwpPP7BB/eXow9SEP8vxn PJwPPAr1J0iyI2IXJ8YyaXjmhq/kiocaXUhkJDXZIjWg8lG19Vva085CcZUll0JlrLTp wvYMeg0jm/5Hm1IX28cAsM8XM32QP73XUzXqC7JZoOdC6ac4VGiCuG2JE34qbFK/acRs qvviOsAB5L0Yvyfp3RIln1WBJ9oL0F6eG2y34iqyDip5IFVffDVrVJ8CsMK9F3fsSe46 DwVYzaWBHYvPoO46u8mIf3XfuEgHqo87X4IN8EWYZJc+CmiM1AYxQNZng/XPuRNWT59e 0luw== 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=pcw6+Tq9er4sa7ROzNemL06kbs8q3+z/oOQXlztCE88=; b=I7V5O1X7F9rDd2yS+wC0tLpkXHJoNu8RBUpQ4asiwFj+10vuQkeuDPEHX6N758LX9e ifMq89VtoP0+6I5R3jLcDjb0wWuZkM23tT412tLAuMqUM1f/ZVreWiId6WXwEnIpS5nH iALPmZDOSuWcDoOtOvKEF9jcHVSnK2JmeQHDpIHdwCzGuNZI2vHus50U4FtzOKRTWnBH 6uuvPbvdHy8uVYDV00H62/tCFfwzv1eHKwoITTl3Xc0qh5Y4CGWg71H1buo0gtuZSvDC f0HZtJ/lvQHab9CMPZt3AthfRmrBr1no9QpHVj+Fa3/+0pW81/IZUpHc99sTOJwJmX+g tG3Q== X-Gm-Message-State: AEkoous7h0BbGYXDUYsw0W9SHOyTapM/6VKnNRYewi43JZ217/hdrkOJILrQnCr2ZfOjRw== X-Received: by 10.194.136.196 with SMTP id qc4mr23185541wjb.136.1471088355908; Sat, 13 Aug 2016 04:39:15 -0700 (PDT) Received: from localhost (mobile-access-bcee63-250.dhcp.inet.fi. [188.238.99.250]) by smtp.gmail.com with ESMTPSA id a184sm6950592wmh.1.2016.08.13.04.39.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Aug 2016 04:39:15 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Cc: Daniel Kahn Gillmor , jani@nikula.org Subject: [PATCH v2 09/14] cli/reply: use dedicated functions for reply to mapping Date: Sat, 13 Aug 2016 14:37:33 +0300 Message-Id: <9a4c17307d2fe3865fd62b38cb9195c1eba31c14.1471088022.git.jani@nikula.org> 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:49 -0000 The main motivation here is to move the special casing around reply-to/from handling into a function of its own, clarifying the main logic. --- notmuch-reply.c | 82 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index b380678e7204..9b78ea2c2b20 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -256,17 +256,13 @@ scan_address_string (const char *recipients, * in either the 'To' or 'Cc' header of the message? */ static int -reply_to_header_is_redundant (notmuch_message_t *message) +reply_to_header_is_redundant (notmuch_message_t *message, const char *reply_to) { - const char *reply_to, *to, *cc, *addr; + const char *to, *cc, *addr; InternetAddressList *list; InternetAddress *address; InternetAddressMailbox *mailbox; - reply_to = notmuch_message_get_header (message, "reply-to"); - if (reply_to == NULL || *reply_to == '\0') - return 0; - list = internet_address_list_parse_string (reply_to); if (internet_address_list_length (list) != 1) @@ -291,6 +287,47 @@ reply_to_header_is_redundant (notmuch_message_t *message) return 0; } +static const char *get_sender(notmuch_message_t *message) +{ + const char *reply_to; + + reply_to = notmuch_message_get_header (message, "reply-to"); + if (reply_to && *reply_to) { + /* + * Some mailing lists munge the Reply-To header despite it + * being A Bad Thing, see + * http://marc.merlins.org/netrants/reply-to-harmful.html + * + * The munging is easy to detect, because it results in a + * redundant reply-to header, (with an address that already + * exists in either To or Cc). So in this case, we ignore the + * Reply-To field and use the From header. This ensures the + * original sender will get the reply even if not subscribed + * to the list. Note that the address in the Reply-To header + * will always appear in the reply if reply_all is true. + */ + if (! reply_to_header_is_redundant (message, reply_to)) + return reply_to; + } + + return notmuch_message_get_header (message, "from"); +} + +static const char *get_to(notmuch_message_t *message) +{ + return notmuch_message_get_header (message, "to"); +} + +static const char *get_cc(notmuch_message_t *message) +{ + return notmuch_message_get_header (message, "cc"); +} + +static const char *get_bcc(notmuch_message_t *message) +{ + return notmuch_message_get_header (message, "bcc"); +} + /* Augment the recipients of 'reply' from the "Reply-to:", "From:", * "To:", "Cc:", and "Bcc:" headers of 'message'. * @@ -310,43 +347,22 @@ add_recipients_from_message (GMimeMessage *reply, notmuch_bool_t reply_all) { struct { - const char *header; - const char *fallback; + const char * (*get_header)(notmuch_message_t *message); GMimeRecipientType recipient_type; } reply_to_map[] = { - { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, - { "to", NULL, GMIME_RECIPIENT_TYPE_TO }, - { "cc", NULL, GMIME_RECIPIENT_TYPE_CC }, - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC } + { get_sender, GMIME_RECIPIENT_TYPE_TO }, + { get_to, GMIME_RECIPIENT_TYPE_TO }, + { get_cc, GMIME_RECIPIENT_TYPE_CC }, + { get_bcc, GMIME_RECIPIENT_TYPE_BCC }, }; const char *from_addr = NULL; unsigned int i; unsigned int n = 0; - /* Some mailing lists munge the Reply-To header despite it being A Bad - * Thing, see http://marc.merlins.org/netrants/reply-to-harmful.html - * - * The munging is easy to detect, because it results in a - * redundant reply-to header, (with an address that already exists - * in either To or Cc). So in this case, we ignore the Reply-To - * field and use the From header. This ensures the original sender - * will get the reply even if not subscribed to the list. Note - * that the address in the Reply-To header will always appear in - * the reply if reply_all is true. - */ - if (reply_to_header_is_redundant (message)) { - reply_to_map[0].header = "from"; - reply_to_map[0].fallback = NULL; - } - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { const char *recipients; - recipients = notmuch_message_get_header (message, - reply_to_map[i].header); - if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback) - recipients = notmuch_message_get_header (message, - reply_to_map[i].fallback); + recipients = reply_to_map[i].get_header (message); n += scan_address_string (recipients, config, reply, reply_to_map[i].recipient_type, &from_addr); -- 2.1.4