[RFC PATCH 5/6] cli/reply: pass gmime message to munge detection
authorJani Nikula <jani@nikula.org>
Sun, 19 Jun 2016 20:15:33 +0000 (23:15 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:22:07 +0000 (16:22 -0700)
6e/039bc70c15e3101d7cd0f130e3771f0b89766e [new file with mode: 0644]

diff --git a/6e/039bc70c15e3101d7cd0f130e3771f0b89766e b/6e/039bc70c15e3101d7cd0f130e3771f0b89766e
new file mode 100644 (file)
index 0000000..8146da7
--- /dev/null
@@ -0,0 +1,158 @@
+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 4603E6DE092F\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:29 -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 CvuAhonsk-JN for <notmuch@notmuchmail.org>;\r
+ Sun, 19 Jun 2016 13:17:20 -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 98AD86DE0352 for\r
+ <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:09 -0700 (PDT)\r
+Received: by mail-wm0-f66.google.com with SMTP id a66so4470244wme.2\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:09 -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=JbNUhTkfYGeVGMQbfELh7g4/EzRbs31Oukows4w45v3VlQ4ju7jMDqRIs0junNNMk1\r
+ HPuGmSDL8w9KSYYMMMS1leHOqvJthLngLvi65xwZosfVhAP46O2J7PPDuZ1sf4i7lb8Z\r
+ st47H/eH3rIhlWdeYAADg1YCEq085YYfA+ovwknme5Fpvq5GypeGGzwsZvTzUyyyNN+N\r
+ HAxy74nozcNSJVliuX9hMY29BvpUrqCcoL0k/u8lQJnkEMhqez8SSVNoVmqb19S43aGI\r
+ tFo0YIAkRcRbNoOp7i4yBckDhJ1sENttDTr5iuZ+PyhfPe8BmQQKKibl2ke5hlcjT2rg\r
+ dMBA==\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=cQdpNNwWoNDrjNqIjjIgecQxrqmQQJ0ysQhfZkXW9eUfjlP0tSYMl/7BSkwhxAxVnr\r
+ 7XOeRmbzFuG8MiPjL84Kch1NJDw+YNEZxeTndOnwO7mcKwNk7GCO3Blc0cLgA5bdZfjg\r
+ FbwmphqoClWDJeWxrYNz5B90o6Z/JR5CwRR/EBPuwxuZRI3c+B25ytW3rlXMKcdL1sNq\r
+ tBSRkd8oQHK2h4DxeSco5i0nD5+tWZPyMgS+rhBDRsWbFEcnGc7fijBTHMSXQl7TQApo\r
+ 7XKMxVZfh05iBa5PBEUuivjiN2vKjAVwYA0B+yI88nTYrc8vKUbETRXkmuRktYqH+Rit\r
+ 3YgQ==\r
+X-Gm-Message-State:\r
+ ALyK8tJ0B86gOR7Mxla6JXdfWYD6O4IWJq9lMHnpY3sDqoIURbOnTzHASPuJ09aOVW6sMg==\r
+X-Received: by 10.194.104.40 with SMTP id gb8mr12503228wjb.146.1466367428318; \r
+ Sun, 19 Jun 2016 13:17:08 -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 zg10sm35591520wjb.1.2016.06.19.13.17.07\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sun, 19 Jun 2016 13:17:07 -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 5/6] cli/reply: pass gmime message to munge detection\r
+Date: Sun, 19 Jun 2016 23:15:33 +0300\r
+Message-Id:\r
+ <fb88de98628ea7e2282849b0149099bb999e4e4e.1466366738.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:29 -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