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 7DAC96DE0C1E for ; Tue, 13 Sep 2016 10:16:45 -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.587 X-Spam-Level: X-Spam-Status: No, score=-0.587 tagged_above=-999 required=5 tests=[AWL=0.133, 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 R8NEmZk8YBrG for ; Tue, 13 Sep 2016 10:16:45 -0700 (PDT) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by arlo.cworth.org (Postfix) with ESMTPS id 21EF66DE0B14 for ; Tue, 13 Sep 2016 10:16:32 -0700 (PDT) Received: by mail-wm0-f68.google.com with SMTP id c131so3939790wmh.2 for ; Tue, 13 Sep 2016 10:16:32 -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=Wxi7dykyKiqlySEJ+NLgOfWUX9C7XznCWX69a+zBLuA=; b=oZLYUcACF5Urw0Y//sJpH2uE0ASLXcCPmNKfIk2nEBkn4ifLyAHVF5F0QaYqRK1Q6S T6/RaRooGq0PqWTG7kNgh7C/kG80Y/j6v/K49vWGbVGaBPWN2KPP68XCfbYeTRT0FtTG hg1jUL9If5Zx3yORidl8952WRyG+yx87by5IqTEvcDIsA/MsADRMu/AvAqRhG5HCGkEa eDFC7WKuLRfw6z5XSVYOrIdyoJikSKXKZxJjy/51NMJj01FEDPkAZNMJXbyA1YSweUFS PC2tx+ZvM09GUIy1davyVwY2Cznwu9718U8ADd7c1EAbTJp7frb5N+1vStDi3fWfY7f9 VtyA== 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=Wxi7dykyKiqlySEJ+NLgOfWUX9C7XznCWX69a+zBLuA=; b=etZ5baIu7Oux9AKgCAGEJuRykMdpcRfcu9fFVOuk07FZuXESahqTDy61EHwl99yp3R TtYrZVHLMBqf1Im2gJ2+wmR9dv7C+5XUBelibtTaTzRO6wXjqu6IDBLSOOtzWcvYmmke 2v+AfA8SBW6XRhDu8VUQTUJQcyWdSfTpIZqpv/b2YStDKf7rfyYSgnFHvH8OzcIJ4unj 9eBtAfxhxQj+OdgL3Bj4k/N3Mc/4T6HXN8fLE666EMSipCijXfRHfQf6t1udMIp899sZ 6YiPXdRsrJshRTpJzFHKM10EP5y1GirMgdxXF2gQxbSdN1iI51B7mHqU1X40kmdhgkmq NGSA== X-Gm-Message-State: AE9vXwP9MdIeF89w4FR8Ghx64uwjdL7RriyfQfd4n9xFZ6GGT10eDJ04Wm2eyWvgA5V0Tw== X-Received: by 10.28.4.211 with SMTP id 202mr5996350wme.7.1473786990724; Tue, 13 Sep 2016 10:16:30 -0700 (PDT) Received: from localhost (mobile-access-bcee6a-45.dhcp.inet.fi. [188.238.106.45]) by smtp.gmail.com with ESMTPSA id d62sm24031448wmd.7.2016.09.13.10.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Sep 2016 10:16:30 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v3 13/15] cli/reply: do not parse Reply-To: header into internet address list twice Date: Tue, 13 Sep 2016 20:14:20 +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.22 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: Tue, 13 Sep 2016 17:16:45 -0000 Avoid parsing Reply-To: header into internet address list twice. Move the parsing outside of reply_to_header_is_redundant(), and pass the parsed internet address list in as parameter. This also avoids leaking the memory of one copy of the internet address list. --- notmuch-reply.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 98034485c546..cf4248bd6794 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -231,19 +231,18 @@ scan_address_list (InternetAddressList *list, * in either the 'To' or 'Cc' header of the message? */ static int -reply_to_header_is_redundant (notmuch_message_t *message, const char *reply_to) +reply_to_header_is_redundant (notmuch_message_t *message, + InternetAddressList *reply_to_list) { const char *to, *cc, *addr; - InternetAddressList *list; InternetAddress *address; InternetAddressMailbox *mailbox; - list = internet_address_list_parse_string (reply_to); - - if (internet_address_list_length (list) != 1) + if (reply_to_list == NULL || + internet_address_list_length (reply_to_list) != 1) return 0; - address = internet_address_list_get_address (list, 0); + address = internet_address_list_get_address (reply_to_list, 0); if (INTERNET_ADDRESS_IS_GROUP (address)) return 0; @@ -269,6 +268,8 @@ static InternetAddressList *get_sender(notmuch_message_t *message, reply_to = g_mime_message_get_reply_to (mime_message); if (reply_to && *reply_to) { + InternetAddressList *reply_to_list; + /* * Some mailing lists munge the Reply-To header despite it * being A Bad Thing, see @@ -282,8 +283,11 @@ static InternetAddressList *get_sender(notmuch_message_t *message, * 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 internet_address_list_parse_string (reply_to); + reply_to_list = internet_address_list_parse_string (reply_to); + if (! reply_to_header_is_redundant (message, reply_to_list)) + return reply_to_list; + + g_object_unref (G_OBJECT (reply_to_list)); } return internet_address_list_parse_string ( -- 2.1.4