--- /dev/null
+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 A6C836DE37B9\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:40:57 -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.574\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.574 tagged_above=-999 required=5 tests=[AWL=0.146,\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 DC3JgMCZkVxP for <notmuch@notmuchmail.org>;\r
+ Sat, 13 Aug 2016 04:40:49 -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 3D14F6DE396D for\r
+ <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:20 -0700 (PDT)\r
+Received: by mail-wm0-f66.google.com with SMTP id q128so2021406wma.1\r
+ for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:20 -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=RiruvyPTe4M6SzkyFmUG/Rd/HLQ1Tvqhpp5XQSylaXA=;\r
+ b=koCYhZb2Wlm9FhlWO1fF38B1fJ6Jerv/jAG5AvQHNnpqYtN6reUM10F9O62VcMJR6C\r
+ trP51VpLUCAnsDAXkBQST7W5FN9DapHfee/+aEA1NHV/1zaJ3ynHwJjTT6f7hjErN7HY\r
+ fhW1t9JCpq7QFWoW5F89RE8LsIBqFSUtmTBg6FIbHcd6YZj8hEgF16089XeTuLpE9PdI\r
+ Swqk6pNoZMXUoQqcsk+jeSXF1n/6lazapQkR230AQSDxKUVz6SRebXoXU7TfpxhET7Dk\r
+ IJaGeohUNcp7RqT1v1Y5fczipS2EhjxJmWOqDSYdP0PrZQ26uCdZAf/6LAJPRM4UKUVT\r
+ LjOA==\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=RiruvyPTe4M6SzkyFmUG/Rd/HLQ1Tvqhpp5XQSylaXA=;\r
+ b=bLhuFoBqLzWcjN9QKV7eUWSZATGTg/I2vN7hXo7ghkFKAC6/h/BADWaPPavm2Fa7qA\r
+ x8Np0RqgQzoDmyibk1j/RcZwW3WpPAf+sdmyxCOGlYe7m60moyCIShhnsOiSQpmtIDVX\r
+ JiOqt6Q5dw1sYi0vSy1HZHXTWYwEpwq7RB7ce6iUhwA13eK6PhDqNVs/4yW6DPmf5FK8\r
+ +DM9z04B2fHYGgyvWX5EwQoOxl7lBW6T6odeKf+UGkzXeeIiUrYc7/LT69uaBx09vX3V\r
+ P76q1/wRX/mF+CMygir5j4y4F65mVfVnYAttSy0Or+TKZYVlf0wJwflnoQSbxorVoAEi\r
+ n8bQ==\r
+X-Gm-Message-State:\r
+ AEkooutj4XTbqiCndVryfO8ggmlIzXyI3YQjmj6CvI9ZPwzrUJ/UKMuL+4OYaLn27cAJrQ==\r
+X-Received: by 10.194.67.198 with SMTP id p6mr19801346wjt.138.1471088358835;\r
+ Sat, 13 Aug 2016 04:39:18 -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 b203sm6796561wmh.20.2016.08.13.04.39.18\r
+ (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 13 Aug 2016 04:39:18 -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 11/14] cli/reply: return internet address list from get\r
+ header funcs\r
+Date: Sat, 13 Aug 2016 14:37:35 +0300\r
+Message-Id:\r
+ <dd7cce90a41f7d68074f69b0c72ebe33cfba0141.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:40:57 -0000\r
+\r
+Pass in GMimeMessage to simplify To/Cc/Bcc headers. We'll eventually\r
+remove the notmuch message passing altogether, but keep both for now\r
+to not make too big changes at once.\r
+\r
+Getting the headers from GMimeMessage using GMime functions fixes the\r
+error on duplicate Cc headers reported by Daniel Kahn Gillmor\r
+<dkg@fifthhorseman.net> in id:87d1ngv95p.fsf@alice.fifthhorseman.net.\r
+\r
+Get rid of an intermediate function.\r
+\r
+The small annoyance is the ownership differences in the address lists.\r
+---\r
+ notmuch-reply.c | 73 ++++++++++++++++++++++--------------------------------\r
+ test/T220-reply.sh | 1 -\r
+ 2 files changed, 30 insertions(+), 44 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index d90f46f9bed3..98034485c546 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -227,31 +227,6 @@ scan_address_list (InternetAddressList *list,\r
+ return n;\r
+ }\r
+ \r
+-/* Scan addresses in 'recipients'.\r
+- *\r
+- * See the documentation of scan_address_list() above. This function\r
+- * does exactly the same, but converts 'recipients' to an\r
+- * InternetAddressList first.\r
+- */\r
+-static unsigned int\r
+-scan_address_string (const char *recipients,\r
+- notmuch_config_t *config,\r
+- GMimeMessage *message,\r
+- GMimeRecipientType type,\r
+- const char **user_from)\r
+-{\r
+- InternetAddressList *list;\r
+-\r
+- if (recipients == NULL)\r
+- return 0;\r
+-\r
+- list = internet_address_list_parse_string (recipients);\r
+- if (list == NULL)\r
+- return 0;\r
+-\r
+- return scan_address_list (list, config, message, type, user_from);\r
+-}\r
+-\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
+@@ -287,11 +262,12 @@ reply_to_header_is_redundant (notmuch_message_t *message, const char *reply_to)\r
+ return 0;\r
+ }\r
+ \r
+-static const char *get_sender(notmuch_message_t *message)\r
++static InternetAddressList *get_sender(notmuch_message_t *message,\r
++ GMimeMessage *mime_message)\r
+ {\r
+ const char *reply_to;\r
+ \r
+- reply_to = notmuch_message_get_header (message, "reply-to");\r
++ reply_to = g_mime_message_get_reply_to (mime_message);\r
+ if (reply_to && *reply_to) {\r
+ /*\r
+ * Some mailing lists munge the Reply-To header despite it\r
+@@ -307,25 +283,32 @@ static const char *get_sender(notmuch_message_t *message)\r
+ * will always appear in the reply if reply_all is true.\r
+ */\r
+ if (! reply_to_header_is_redundant (message, reply_to))\r
+- return reply_to;\r
++ return internet_address_list_parse_string (reply_to);\r
+ }\r
+ \r
+- return notmuch_message_get_header (message, "from");\r
++ return internet_address_list_parse_string (\r
++ g_mime_message_get_sender (mime_message));\r
+ }\r
+ \r
+-static const char *get_to(notmuch_message_t *message)\r
++static InternetAddressList *get_to(unused(notmuch_message_t *message),\r
++ GMimeMessage *mime_message)\r
+ {\r
+- return notmuch_message_get_header (message, "to");\r
++ return g_mime_message_get_recipients (mime_message,\r
++ GMIME_RECIPIENT_TYPE_TO);\r
+ }\r
+ \r
+-static const char *get_cc(notmuch_message_t *message)\r
++static InternetAddressList *get_cc(unused(notmuch_message_t *message),\r
++ GMimeMessage *mime_message)\r
+ {\r
+- return notmuch_message_get_header (message, "cc");\r
++ return g_mime_message_get_recipients (mime_message,\r
++ GMIME_RECIPIENT_TYPE_CC);\r
+ }\r
+ \r
+-static const char *get_bcc(notmuch_message_t *message)\r
++static InternetAddressList *get_bcc(unused(notmuch_message_t *message),\r
++ GMimeMessage *mime_message)\r
+ {\r
+- return notmuch_message_get_header (message, "bcc");\r
++ return g_mime_message_get_recipients (mime_message,\r
++ GMIME_RECIPIENT_TYPE_BCC);\r
+ }\r
+ \r
+ /* Augment the recipients of 'reply' from the "Reply-to:", "From:",\r
+@@ -344,10 +327,12 @@ static const char *\r
+ add_recipients_from_message (GMimeMessage *reply,\r
+ notmuch_config_t *config,\r
+ notmuch_message_t *message,\r
++ GMimeMessage *mime_message,\r
+ notmuch_bool_t reply_all)\r
+ {\r
+ struct {\r
+- const char * (*get_header)(notmuch_message_t *message);\r
++ InternetAddressList * (*get_header)(notmuch_message_t *message,\r
++ GMimeMessage *mime_message);\r
+ GMimeRecipientType recipient_type;\r
+ } reply_to_map[] = {\r
+ { get_sender, GMIME_RECIPIENT_TYPE_TO },\r
+@@ -360,12 +345,12 @@ add_recipients_from_message (GMimeMessage *reply,\r
+ unsigned int n = 0;\r
+ \r
+ for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
+- const char *recipients;\r
++ InternetAddressList *recipients;\r
+ \r
+- recipients = reply_to_map[i].get_header (message);\r
++ recipients = reply_to_map[i].get_header (message, mime_message);\r
+ \r
+- n += scan_address_string (recipients, config, reply,\r
+- reply_to_map[i].recipient_type, &from_addr);\r
++ n += scan_address_list (recipients, config, reply,\r
++ reply_to_map[i].recipient_type, &from_addr);\r
+ \r
+ if (!reply_all && n) {\r
+ /* Stop adding new recipients in reply-to-sender mode if\r
+@@ -536,6 +521,7 @@ static GMimeMessage *\r
+ create_reply_message(void *ctx,\r
+ notmuch_config_t *config,\r
+ notmuch_message_t *message,\r
++ GMimeMessage *mime_message,\r
+ notmuch_bool_t reply_all,\r
+ notmuch_bool_t limited)\r
+ {\r
+@@ -566,8 +552,8 @@ create_reply_message(void *ctx,\r
+ \r
+ g_mime_object_set_header (GMIME_OBJECT (reply), "References", references);\r
+ \r
+- from_addr = add_recipients_from_message (reply, config,\r
+- message, reply_all);\r
++ from_addr = add_recipients_from_message (reply, config, message,\r
++ mime_message, reply_all);\r
+ \r
+ /* The above is all that is needed for limited headers. */\r
+ if (limited)\r
+@@ -666,7 +652,8 @@ static int do_reply(notmuch_config_t *config,\r
+ if (mime_node_open (config, message, ¶ms->crypto, &node))\r
+ return 1;\r
+ \r
+- reply = create_reply_message (config, config, message, reply_all,\r
++ reply = create_reply_message (config, config, message,\r
++ GMIME_MESSAGE (node->part), reply_all,\r
+ format == FORMAT_HEADERS_ONLY);\r
+ if (!reply)\r
+ return 1;\r
+diff --git a/test/T220-reply.sh b/test/T220-reply.sh\r
+index d6f3a839ca48..47ba5d38e18d 100755\r
+--- a/test/T220-reply.sh\r
++++ b/test/T220-reply.sh\r
+@@ -254,7 +254,6 @@ test_expect_equal_json "$output" '\r
+ }'\r
+ \r
+ test_begin_subtest "Reply to a message with multiple Cc headers"\r
+-test_subtest_known_broken\r
+ cat > "${MAIL_DIR}"/broken_cc <<EOF\r
+ From: Alice <alice@example.org>\r
+ To: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+-- \r
+2.1.4\r
+\r