--- /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 02BA36DE01F7\r
+ for <notmuch@notmuchmail.org>; Fri, 17 Jun 2016 01:45:54 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.535\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.535 tagged_above=-999 required=5 tests=[AWL=1.255, \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 W02p-krQCg6m for <notmuch@notmuchmail.org>;\r
+ Fri, 17 Jun 2016 01:45:45 -0700 (PDT)\r
+Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com\r
+ [74.125.82.45]) by arlo.cworth.org (Postfix) with ESMTPS id 3A4546DE00EB for\r
+ <notmuch@notmuchmail.org>; Fri, 17 Jun 2016 01:45:45 -0700 (PDT)\r
+Received: by mail-wm0-f45.google.com with SMTP id a66so91091843wme.0\r
+ for <notmuch@notmuchmail.org>; Fri, 17 Jun 2016 01:45:45 -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:subject:in-reply-to:references:user-agent:date:message-id\r
+ :mime-version; bh=NeRLVwI1Ybr1HeFKBdB1Xk+QhMtGlBUrRfAJ9bNRcIk=;\r
+ b=NeBdpeRqwbHodDRqXJfehRbmywzzcR396O7g3PzilYskcqjzJdDthtjJD+3M7z01+I\r
+ qv9oAHz6z7bQA4vrNKjn3F18auaiAG4/vpGXnfuWIpt6d/ulJiErPCOUaub/HAR97Xqg\r
+ wepmxehTr6iICfjFVWToW0KPmH172EleEuVcvXZHaGbyw8parLWx5JdXpqMmQs1ojkIp\r
+ 8d7REkOo/qIHZuimRtnMheXIQTBiN+CmE0K2oYxf7g2U3BRKyo0v7mTEILL3pX/5IMIB\r
+ YeKH0zh0q7U3+GDIiAkVt8eQBTv3yZlY4bTGLcfU2dO2BqAAreU6Ju/Siimnp7oJVP7e\r
+ u00g==\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:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version;\r
+ bh=NeRLVwI1Ybr1HeFKBdB1Xk+QhMtGlBUrRfAJ9bNRcIk=;\r
+ b=OfCVTah90FB0R7eCzv5N94InJc5KxIxolPP+96vKtVwHTLi8CEA1RnL2FACfq/GQhy\r
+ p9RPaEXm9q/D4Tkif0XV9im4u/EpQvLOn82en96meCGzWIyo4SL6HLQjei5DmAaRjRA3\r
+ LPfrdCaXH5p/klyvW5LvVu44ZEhochgu6jaWvuxPCKxE8pEOhNLVulUQLl37U8gBoeos\r
+ eMd2LnwUBUo1MKzzPw/UNdVLb3tFr6kET0ZAFFrS2tDj8pqBVk8HIidvPd0AXcqDggAl\r
+ fASytJVI+xApfufHcb+HuN6WFtI3Zx5CvKJRIMN/w3ynvTETFHj6W8cUY5jy8rpsoRtO\r
+ +TVw==\r
+X-Gm-Message-State:\r
+ ALyK8tIbePDJBeWWjBbNw0Ibjntk3OEJP+3S8A15MUNQNlg4gauEpm9/0egRrKVXfYHfxA==\r
+X-Received: by 10.28.212.198 with SMTP id l189mr20398219wmg.100.1466153143199;\r
+ Fri, 17 Jun 2016 01:45:43 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c37a-44.dhcp.inet.fi.\r
+ [88.195.122.44])\r
+ by smtp.gmail.com with ESMTPSA id zg10sm23283452wjb.1.2016.06.17.01.45.42\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Fri, 17 Jun 2016 01:45:42 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,\r
+ Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: Re: notmuch reply is confused about multiple (or case-insensitive?)\r
+ cc headers\r
+In-Reply-To: <87d1ngv95p.fsf@alice.fifthhorseman.net>\r
+References: <87d1ngv95p.fsf@alice.fifthhorseman.net>\r
+User-Agent: Notmuch/0.22+35~g6a833a6 (https://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Fri, 17 Jun 2016 11:44:19 +0300\r
+Message-ID: <87bn30tdb0.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Fri, 17 Jun 2016 08:45:54 -0000\r
+\r
+On Fri, 17 Jun 2016, Daniel Kahn Gillmor <dkg@fifthhorseman.net> wrote:\r
+> hey notmuchers--\r
+>\r
+> I'm using notmuch from close to git master.\r
+>\r
+> I just received an e-mail with headers like this:\r
+>\r
+> ------\r
+> From: Alice <alice@example.org>\r
+> To: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+> Cc: Bob <bob@example.org>\r
+> Subject: wowsers!\r
+> cc: Charles <charles@example.org>\r
+> Message-Id: <abc123@example.org>\r
+> Date: Thu, 16 Jun 2016 22:14:41 -0400\r
+>\r
+> blah blah\r
+> ------\r
+>\r
+> Note the weirdness about the Cc fields!\r
+>\r
+> https://tools.ietf.org/html/rfc5322#page-21\r
+>\r
+> Makes it clear that there is supposed to only be zero or one cc header\r
+> in an e-mail, but notmuch-emacs is nice enough to show me both.\r
+>\r
+> However, if i do:\r
+>\r
+> notmuch reply id:abc123@example.org\r
+>\r
+> then Charles is omitted:\r
+>\r
+> ----------\r
+> From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+> Subject: Re: wowsers!\r
+> To: Alice <alice@example.org>\r
+> Cc: Bob <bob@example.org>\r
+> In-Reply-To: <abc123@example.org>\r
+> References: <abc123@example.org>\r
+>\r
+> On Thu, 16 Jun 2016 22:14:41 -0400, Alice <alice@example.org> wrote:\r
+>> blah blah\r
+> ----------\r
+>\r
+>\r
+> In json form:\r
+>\r
+> 0 dkg@alice:~$ notmuch reply --format=json id:abc123@example.org | json_pp \r
+> {\r
+> "reply-headers" : {\r
+> "From" : "Daniel Kahn Gillmor <dkg@fifthhorseman.net>",\r
+> "References" : "<abc123@example.org>",\r
+> "To" : "Alice <alice@example.org>",\r
+> "Cc" : "Bob <bob@example.org>",\r
+> "Subject" : "Re: wowsers!",\r
+> "In-reply-to" : "<abc123@example.org>"\r
+> },\r
+> "original" : {\r
+> "id" : "abc123@example.org",\r
+> "filename" : "REDACTED",\r
+> "timestamp" : 1466129681,\r
+> "match" : false,\r
+> "headers" : {\r
+> "Cc" : "Bob <bob@example.org>, Charles <charles@example.org>",\r
+> "Date" : "",\r
+> "Subject" : "wowsers!",\r
+> "From" : "Alice <alice@example.org>",\r
+> "To" : "Daniel Kahn Gillmor <dkg@fifthhorseman.net>"\r
+> },\r
+> "tags" : [],\r
+> "excluded" : false"\r
+> ...\r
+>\r
+>\r
+>\r
+> Note that we see Charles in original[headers[Cc]], but not in\r
+> reply-headers[Cc].\r
+>\r
+> Seems to me like these two should agree. We should either decide to\r
+> take the strict interpretation of RFC 5322 or not. I lean toward\r
+> including Charles in both sets, fwiw.\r
+\r
+The two come from code paths surprisingly far away from each other.\r
+\r
+The original message is formatted using the message printing in\r
+notmuch-show.c. For Cc:, it uses g_mime_message_get_recipients(), which\r
+apparently combines all Cc: fields into one internally.\r
+\r
+The addresses in the reply headers, OTOH, are based on headers queried\r
+through libnotmuch. It boils down to g_mime_object_get_header() in\r
+lib/message-file.c, which returns only the first occurence of header.\r
+\r
+> Anyway, smells like a bug in a weird corner case, and i haven't had time\r
+> to track it down or fix it, but i figured i'd report it so that other\r
+> people can see it.\r
+\r
+I don't think I'd do anything to fix this particular issue. It's a\r
+corner case, we comply with the RFC, and all that.\r
+\r
+However, I would start thinking about our usage of gmime directly\r
+vs. querying through the lib in the cli. The lib has some caching for\r
+efficiency, and is probably the way to go for indexing and searching\r
+etc. But perhaps we should just hit the disk directly using gmime when\r
+we're reading and parsing the messages to show in the cli? So perhaps we\r
+should be using gmime calls instead of notmuch lib calls to get the\r
+from/to/cc headers in notmuch reply, for example. This would fix the\r
+issue as a side effect. (You could argue we should do this just to fix\r
+this bug, but I think it's a bigger design decision.)\r
+\r
+Side note #1, even in the indexing code in the lib we use\r
+g_mime_message_get_all_recipients(), so I think to:charles will find the\r
+original message.\r
+\r
+Side note #2, I think we should provide *all* versions of reply-headers\r
+(reply-to-sender, reply-to-all, mail-followup-to, whatnot) in the\r
+formatted output, and let the user toggle between them in notmuch-emacs\r
+while composing the reply.\r
+\r
+BR,\r
+Jani.\r