[PATCH] show: add In-reply-to, References fields to structured formats

Peter Wang novalazy at gmail.com
Sat Jan 11 21:00:00 PST 2014


This is useful when 'show' is used to retrieve a draft message
which is in reply to another message.
---
 devel/schemata      |  9 ++++++++-
 notmuch-show.c      | 16 ++++++++++++----
 test/thread-replies |  7 +++++++
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/devel/schemata b/devel/schemata
index 41dc4a6..dd41217 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -14,7 +14,7 @@ are interleaved. Keys are printed as keywords (symbols preceded by a
 colon), e.g. (:id "123" :time 54321 :from "foobar"). Null is printed as
 nil, true as t and false as nil.
 
-This is version 2 of the structured output format.
+This is version 3 of the structured output format.
 
 Version history
 ---------------
@@ -26,6 +26,9 @@ v1
 v2
 - Added the thread_summary.query field.
 
+v3
+- Added headers.in-reply-to and headers.references fields.
+
 Common non-terminals
 --------------------
 
@@ -105,6 +108,10 @@ headers = {
     Cc?:            string,
     Bcc?:           string,
     Reply-To?:      string,
+    # Added in schema version 3.
+    In-reply-to?:   string,
+    # Added in schema version 3.
+    References?:    string,
     Date:           string
 }
 
diff --git a/notmuch-show.c b/notmuch-show.c
index c07f887..774ba44 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -222,6 +222,8 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
     InternetAddressList *recipients;
     const char *recipients_string;
     const char *reply_to_string;
+    const char *in_reply_to_string;
+    const char *references_string;
 
     sp->begin_map (sp);
 
@@ -258,13 +260,19 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
 	sp->string (sp, reply_to_string);
     }
 
-    if (reply) {
+    in_reply_to_string = g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to");
+    if (in_reply_to_string || reply) {
 	sp->map_key (sp, "In-reply-to");
-	sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to"));
+	sp->string (sp, in_reply_to_string);
+    }
 
+    references_string = g_mime_object_get_header (GMIME_OBJECT (message), "References");
+    if (references_string || reply) {
 	sp->map_key (sp, "References");
-	sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References"));
-    } else {
+	sp->string (sp, references_string);
+    }
+
+    if (! reply) {
 	sp->map_key (sp, "Date");
 	sp->string (sp, g_mime_message_get_date_as_string (message));
     }
diff --git a/test/thread-replies b/test/thread-replies
index eeb70d0..9d4b379 100755
--- a/test/thread-replies
+++ b/test/thread-replies
@@ -39,6 +39,8 @@ expected='[[[{"id": "foo at one.com",
  "tags": ["inbox", "unread"], "headers": {"Subject": "Re: one",
  "From": "Notmuch Test Suite <test_suite at notmuchmail.org>",
  "To": "Notmuch Test Suite <test_suite at notmuchmail.org>",
+ "In-reply-to": "mumble",
+ "References": "<foo at one.com>",
  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
  "body": [{"id": 1, "content-type": "text/plain",
  "content": "This is just a test message (#2)\n"}]}, []]]]]]'
@@ -68,6 +70,8 @@ expected='[[[{"id": "foo at two.com",
  "headers": {"Subject": "Re: two",
  "From": "Notmuch Test Suite <test_suite at notmuchmail.org>",
  "To": "Notmuch Test Suite <test_suite at notmuchmail.org>",
+ "In-reply-to": "<bar at baz.com>",
+ "References": "<foo at two.com>",
  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
  "body": [{"id": 1,
  "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},
@@ -95,6 +99,7 @@ expected='[[[{"id": "foo at three.com", "match": true, "excluded": false,
  "headers": {"Subject": "Re: three",
  "From": "Notmuch Test Suite <test_suite at notmuchmail.org>",
  "To": "Notmuch Test Suite <test_suite at notmuchmail.org>",
+ "In-reply-to": "<foo at three.com>",
  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
  "content-type": "text/plain", "content": "This is just a test message (#6)\n"}]},
  []]]]]]'
@@ -124,6 +129,8 @@ expected='[[[{"id": "foo at four.com", "match": true, "excluded": false,
  "headers": {"Subject": "neither",
  "From": "Notmuch Test Suite <test_suite at notmuchmail.org>",
  "To": "Notmuch Test Suite <test_suite at notmuchmail.org>",
+ "In-reply-to": "<baz at four.com>",
+ "References": "<baz at four.com> <foo at four.com>",
  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
  "content-type": "text/plain", "content": "This is just a test message (#9)\n"}]},
  []]]]], [[{"id": "bar at four.com", "match": true, "excluded": false,
-- 
1.8.4



More information about the notmuch mailing list