[PATCH v2 13/14] cli/reply: pass gmime message to munge detection
authorJani Nikula <jani@nikula.org>
Sat, 13 Aug 2016 11:37:37 +0000 (14:37 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:22:25 +0000 (16:22 -0700)
1b/9c297e23de0051751b697965d6359cbd20df14 [new file with mode: 0644]

diff --git a/1b/9c297e23de0051751b697965d6359cbd20df14 b/1b/9c297e23de0051751b697965d6359cbd20df14
new file mode 100644 (file)
index 0000000..236821d
--- /dev/null
@@ -0,0 +1,157 @@
+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 4B8216DE3B39\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:41:35 -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.575\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.575 tagged_above=-999 required=5 tests=[AWL=0.145,\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 BzeVEKQ5tz-Z for <notmuch@notmuchmail.org>;\r
+ Sat, 13 Aug 2016 04:41:27 -0700 (PDT)\r
+Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com\r
+ [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id 1A3BD6DE38C5 for\r
+ <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:23 -0700 (PDT)\r
+Received: by mail-wm0-f67.google.com with SMTP id q128so2021557wma.1\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:23 -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=EBSFEIre9w10UPwn/U5SUVD/q7bQedUt80//bcDsm5Y=;\r
+ b=qO9ETH3LVndM85clLdz9rmvEOeLDG7LqSCxrX/ToSsdNZn3MCG8GHqG9Xj62TSVCHC\r
+ vfW6025FlYEN5WrSvBDg96csBlKGR/MgBNWL6bStx9AIzPq4w4qI1fRk/k8FPq533fon\r
+ J/vkJ0quNIItXBtwUGw7IhZRPf0N/WADm1GL2jhAfNpuCPjQbRstHof7hq7n+Avxf1VV\r
+ Vt2ax3unPk4OI6bYVS6vcyFR46gsmgXfRUqlhPTxazlbf796DbGzEa5/x4s8U/KH6m75\r
+ qDGCe68h46chvU6rdu6j3J6Zj1ZpjuuhRdEITzWeoO51n2fKthYyYWGJmHC3GXcq0ZHe\r
+ Yrlg==\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=EBSFEIre9w10UPwn/U5SUVD/q7bQedUt80//bcDsm5Y=;\r
+ b=JFYhBydoVvaK16EdznIacVDwfMZ6CC0I4QZ3yUgaYULQfx9u2QTM9x+3mvLwkaGaRs\r
+ IFU4H+u76P9Dh1S1c+6TW5NJ9m4sAVUgC1W2xGdTNjdx0h98xCe6tCgfrtkl6unyCp6H\r
+ 0/D9y1czUaRsuBqRgjS8UO0khgI65S6erTbrn8Ilgl5pAryi3R6aRN1wg5vHYDMTczw3\r
+ OoPjUdhIn2PRab3H2YRZlMmzxnePlSTaADJk/WFWvBA+nUjVpZK3b/7D1CXiUfmZ9FUX\r
+ HSnkAvDdjnoDj4YQ5A+Igjbu8uU4iNoYdJk0vK02aLG+5mYwMWLsdJNFundBA7A0rDpf\r
+ 0n1Q==\r
+X-Gm-Message-State:\r
+ AEkoouuUXtva8gF6hr3DqvWzq+UGv1jb1fSY3L9WRAavQSdbSpdZFAlTvIKPAArmTEEaqw==\r
+X-Received: by 10.28.148.21 with SMTP id w21mr3739056wmd.50.1471088361726;\r
+ Sat, 13 Aug 2016 04:39:21 -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 e10sm11794272wjc.21.2016.08.13.04.39.20\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 13 Aug 2016 04:39:21 -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 13/14] cli/reply: pass gmime message to munge detection\r
+Date: Sat, 13 Aug 2016 14:37:37 +0300\r
+Message-Id:\r
+ <771c4118ad840f9b9af1a3744d53e7ede3bd837d.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:41:35 -0000\r
+\r
+Improves the accuracy in many ways.\r
+---\r
+ notmuch-reply.c | 35 +++++++++++++++++++++++------------\r
+ 1 file changed, 23 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index cf4248bd6794..abf3a6c1824c 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -230,13 +230,16 @@ scan_address_list (InternetAddressList *list,\r
+ /* Does the address in the Reply-To header of 'message' already appear\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
++static notmuch_bool_t\r
++reply_to_header_is_redundant (GMimeMessage *message,\r
+                             InternetAddressList *reply_to_list)\r
+ {\r
+-    const char *to, *cc, *addr;\r
++    const char *addr, *reply_to;\r
+     InternetAddress *address;\r
+     InternetAddressMailbox *mailbox;\r
++    InternetAddressList *recipients;\r
++    notmuch_bool_t ret = FALSE;\r
++    int i;\r
\r
+     if (reply_to_list == NULL ||\r
+       internet_address_list_length (reply_to_list) != 1)\r
+@@ -247,18 +250,26 @@ reply_to_header_is_redundant (notmuch_message_t *message,\r
+       return 0;\r
\r
+     mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
+-    addr = internet_address_mailbox_get_addr (mailbox);\r
++    reply_to = internet_address_mailbox_get_addr (mailbox);\r
\r
+-    to = notmuch_message_get_header (message, "to");\r
+-    cc = notmuch_message_get_header (message, "cc");\r
++    recipients = g_mime_message_get_all_recipients (message);\r
\r
+-    if ((to && strstr (to, addr) != 0) ||\r
+-      (cc && strstr (cc, addr) != 0))\r
+-    {\r
+-      return 1;\r
++    for (i = 0; i < internet_address_list_length (recipients); i++) {\r
++      address = internet_address_list_get_address (recipients, i);\r
++      if (INTERNET_ADDRESS_IS_GROUP (address))\r
++          continue;\r
++\r
++      mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
++      addr = internet_address_mailbox_get_addr (mailbox);\r
++      if (strcmp (addr, reply_to) == 0) {\r
++          ret = TRUE;\r
++          break;\r
++      }\r
+     }\r
\r
+-    return 0;\r
++    g_object_unref (G_OBJECT (recipients));\r
++\r
++    return ret;\r
+ }\r
\r
+ static InternetAddressList *get_sender(notmuch_message_t *message,\r
+@@ -284,7 +295,7 @@ static InternetAddressList *get_sender(notmuch_message_t *message,\r
+        * will always appear in the reply if reply_all is true.\r
+        */\r
+       reply_to_list = internet_address_list_parse_string (reply_to);\r
+-      if (! reply_to_header_is_redundant (message, reply_to_list))\r
++      if (! reply_to_header_is_redundant (mime_message, reply_to_list))\r
+           return reply_to_list;\r
\r
+       g_object_unref (G_OBJECT (reply_to_list));\r
+-- \r
+2.1.4\r
+\r