From: Jani Nikula Date: Sun, 19 Jun 2016 20:15:29 +0000 (+0300) Subject: [RFC PATCH 1/6] cli/reply: use dedicated functions for reply to mapping X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6ad8d849b660ca42a07b0b76ccabf21282c119c0;p=notmuch-archives.git [RFC PATCH 1/6] cli/reply: use dedicated functions for reply to mapping --- diff --git a/16/7052b02609d1d42f30bbde7b12fd4208f0414e b/16/7052b02609d1d42f30bbde7b12fd4208f0414e new file mode 100644 index 000000000..8192e1740 --- /dev/null +++ b/16/7052b02609d1d42f30bbde7b12fd4208f0414e @@ -0,0 +1,215 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 179C16DE0360 + for ; Sun, 19 Jun 2016 13:17:13 -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.568 +X-Spam-Level: +X-Spam-Status: No, score=-0.568 tagged_above=-999 required=5 tests=[AWL=0.152, + 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 YqqYV9wV4n3x for ; + Sun, 19 Jun 2016 13:17:04 -0700 (PDT) +Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com + [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id DAD7E6DE0188 for + ; Sun, 19 Jun 2016 13:17:03 -0700 (PDT) +Received: by mail-wm0-f66.google.com with SMTP id 187so9592334wmz.1 + for ; Sun, 19 Jun 2016 13:17:03 -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=cDLOVrZyeD+vr4nxuuQ7tUd18SX8Omhjeqibq1jeQqzCsuisVJgw4TQB22qTU/0JZ/ + H5+xVJsYEwtZuB0KDr8rlFB6W5TaSuVoWJ6QPCZCioA1SnB7aX+Pb6tCGStyDszHU9XT + 0pNwA1mtSlhQTas4TGyqjaGOox6MHDWWu0bWizJRi6ssAabw9WyTSrwQ1S0jNTYSiCVO + yb3DsMQ5g+s81GlAqkuQwPSbBGAl0mrgDz/gho3YSGtVkc6PpcUjEDFVRFWo8XXJA++Q + P5v+jiythEc1HQp7MHD4NhgjVpJbgVV+WsVQ//TUbXe7j8Onlk84PHZIBYcTmptfgg5m + 1TEw== +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=WQ8gfrezFt/f491EXXGzcFYSQXfVpKuo/UUTruTL5uRfRwI7TM2VCEMJxzcw8aSE4K + JEnA1nrIyd2ML2b7dRVb9Xt2hOqmaTiA2I1pPecPk1FTiKUwiqdfDATnne4YT/nx0W3E + E77UQDkdTO1DaGO7ajTfvxzNiWNWlxb0yzeoKz/UkTdjeoGxebGuNhg/Xev4tPhRe1oO + dTtqohoGDwCmCpVUSixGiuxM0mgaG17/7ybZhLRJlcAZyWhWrafzfos26cMo2MLkuW44 + lQT0SvBFJNU7JmCanh84/CmjVdpiNMcYpWQCAzfIW+ICrdIjjE9PfVopP0lDYRnY75LD + MjwQ== +X-Gm-Message-State: + ALyK8tKLxZ6QxoQae6KGydvzWAQb/ICwslAjya0ohIW72MSLmSOoB3C0yiUcGg6HGIkDbg== +X-Received: by 10.194.80.70 with SMTP id p6mr10967510wjx.45.1466367422322; + Sun, 19 Jun 2016 13:17:02 -0700 (PDT) +Received: from localhost (mobile-access-bcee4e-81.dhcp.inet.fi. + [188.238.78.81]) + by smtp.gmail.com with ESMTPSA id x83sm4796283wmx.9.2016.06.19.13.17.01 + (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sun, 19 Jun 2016 13:17:01 -0700 (PDT) +From: Jani Nikula +To: Jani Nikula , + notmuch@notmuchmail.org +Cc: Daniel Kahn Gillmor +Subject: [RFC PATCH 1/6] cli/reply: use dedicated functions for reply to + mapping +Date: Sun, 19 Jun 2016 23:15:29 +0300 +Message-Id: + +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: Sun, 19 Jun 2016 20:17:13 -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 +