--- /dev/null
+Return-Path: <novalazy@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1308C431FD0\r
+ for <notmuch@notmuchmail.org>; Sat, 11 Jan 2014 21:00:24 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id vY3wYX7PR+RK for <notmuch@notmuchmail.org>;\r
+ Sat, 11 Jan 2014 21:00:16 -0800 (PST)\r
+Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com\r
+ [209.85.220.52]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id F3A76431FC3\r
+ for <notmuch@notmuchmail.org>; Sat, 11 Jan 2014 21:00:15 -0800 (PST)\r
+Received: by mail-pa0-f52.google.com with SMTP id kx10so2498821pab.25\r
+ for <notmuch@notmuchmail.org>; Sat, 11 Jan 2014 21:00:14 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id;\r
+ bh=lScT2gNr4j5m5tnAQT9fzWjvIbwWVU4+DR0YvantN6k=;\r
+ b=0HrQSqWII1+4WKIAs0vDfA+oeMa2iSXVDqqkKivI+SEESuhDKRK2q5P/w44UDa4XbK\r
+ Q7zcOVSeZbxqVDBICiBQUqCgzjlMtpYQgtvZNu6GVGEepLL1KMS4RpqN7MT7lC2QEI8U\r
+ TiaqK9pAEgSOBwnBmUJ6gau8E1wuAUoU7j1ogSUunGIF4g0vQ9kNxYOPdqpuVyX/ldFw\r
+ yugUIJ26cQmrlc+/ipGjYm89quYMue9VFoO7Pv/83WHex4j5oaYUKYM1R+f4KETCn+jn\r
+ MbHGE1CsWWOxf2xwD31zv+p3cQyWs13Ksrh9HTZ+xST+5PmCaB+M2xB/x2zg1ZRe5Igi\r
+ Pvdw==\r
+X-Received: by 10.68.234.67 with SMTP id uc3mr21589381pbc.27.1389502814070;\r
+ Sat, 11 Jan 2014 21:00:14 -0800 (PST)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+ [220.233.42.215])\r
+ by mx.google.com with ESMTPSA id sx8sm36257204pab.5.2014.01.11.21.00.11\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 11 Jan 2014 21:00:12 -0800 (PST)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] show: add In-reply-to, References fields to structured\r
+ formats\r
+Date: Sun, 12 Jan 2014 16:00:00 +1100\r
+Message-Id: <1389502800-9237-1-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.8.4\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 12 Jan 2014 05:00:24 -0000\r
+\r
+This is useful when 'show' is used to retrieve a draft message\r
+which is in reply to another message.\r
+---\r
+ devel/schemata | 9 ++++++++-\r
+ notmuch-show.c | 16 ++++++++++++----\r
+ test/thread-replies | 7 +++++++\r
+ 3 files changed, 27 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/devel/schemata b/devel/schemata\r
+index 41dc4a6..dd41217 100644\r
+--- a/devel/schemata\r
++++ b/devel/schemata\r
+@@ -14,7 +14,7 @@ are interleaved. Keys are printed as keywords (symbols preceded by a\r
+ colon), e.g. (:id "123" :time 54321 :from "foobar"). Null is printed as\r
+ nil, true as t and false as nil.\r
+ \r
+-This is version 2 of the structured output format.\r
++This is version 3 of the structured output format.\r
+ \r
+ Version history\r
+ ---------------\r
+@@ -26,6 +26,9 @@ v1\r
+ v2\r
+ - Added the thread_summary.query field.\r
+ \r
++v3\r
++- Added headers.in-reply-to and headers.references fields.\r
++\r
+ Common non-terminals\r
+ --------------------\r
+ \r
+@@ -105,6 +108,10 @@ headers = {\r
+ Cc?: string,\r
+ Bcc?: string,\r
+ Reply-To?: string,\r
++ # Added in schema version 3.\r
++ In-reply-to?: string,\r
++ # Added in schema version 3.\r
++ References?: string,\r
+ Date: string\r
+ }\r
+ \r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index c07f887..774ba44 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -222,6 +222,8 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,\r
+ InternetAddressList *recipients;\r
+ const char *recipients_string;\r
+ const char *reply_to_string;\r
++ const char *in_reply_to_string;\r
++ const char *references_string;\r
+ \r
+ sp->begin_map (sp);\r
+ \r
+@@ -258,13 +260,19 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,\r
+ sp->string (sp, reply_to_string);\r
+ }\r
+ \r
+- if (reply) {\r
++ in_reply_to_string = g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to");\r
++ if (in_reply_to_string || reply) {\r
+ sp->map_key (sp, "In-reply-to");\r
+- sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to"));\r
++ sp->string (sp, in_reply_to_string);\r
++ }\r
+ \r
++ references_string = g_mime_object_get_header (GMIME_OBJECT (message), "References");\r
++ if (references_string || reply) {\r
+ sp->map_key (sp, "References");\r
+- sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References"));\r
+- } else {\r
++ sp->string (sp, references_string);\r
++ }\r
++\r
++ if (! reply) {\r
+ sp->map_key (sp, "Date");\r
+ sp->string (sp, g_mime_message_get_date_as_string (message));\r
+ }\r
+diff --git a/test/thread-replies b/test/thread-replies\r
+index eeb70d0..9d4b379 100755\r
+--- a/test/thread-replies\r
++++ b/test/thread-replies\r
+@@ -39,6 +39,8 @@ expected='[[[{"id": "foo@one.com",\r
+ "tags": ["inbox", "unread"], "headers": {"Subject": "Re: one",\r
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
+ "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++ "In-reply-to": "mumble",\r
++ "References": "<foo@one.com>",\r
+ "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},\r
+ "body": [{"id": 1, "content-type": "text/plain",\r
+ "content": "This is just a test message (#2)\n"}]}, []]]]]]'\r
+@@ -68,6 +70,8 @@ expected='[[[{"id": "foo@two.com",\r
+ "headers": {"Subject": "Re: two",\r
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
+ "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++ "In-reply-to": "<bar@baz.com>",\r
++ "References": "<foo@two.com>",\r
+ "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},\r
+ "body": [{"id": 1,\r
+ "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},\r
+@@ -95,6 +99,7 @@ expected='[[[{"id": "foo@three.com", "match": true, "excluded": false,\r
+ "headers": {"Subject": "Re: three",\r
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
+ "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++ "In-reply-to": "<foo@three.com>",\r
+ "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,\r
+ "content-type": "text/plain", "content": "This is just a test message (#6)\n"}]},\r
+ []]]]]]'\r
+@@ -124,6 +129,8 @@ expected='[[[{"id": "foo@four.com", "match": true, "excluded": false,\r
+ "headers": {"Subject": "neither",\r
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
+ "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
++ "In-reply-to": "<baz@four.com>",\r
++ "References": "<baz@four.com> <foo@four.com>",\r
+ "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,\r
+ "content-type": "text/plain", "content": "This is just a test message (#9)\n"}]},\r
+ []]]]], [[{"id": "bar@four.com", "match": true, "excluded": false,\r
+-- \r
+1.8.4\r
+\r