--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 D18286DE1BB6\r
+ for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:03:44 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.495\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.495 tagged_above=-999 required=5 tests=[AWL=0.485, \r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=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 tX931MVO-Mzt for <notmuch@notmuchmail.org>;\r
+ Sun, 5 Apr 2015 16:03:43 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 24B2E6DE1BAD\r
+ for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:03:36 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YetZ8-0002qC-Gw; Sun, 05 Apr 2015 23:02:54 +0000\r
+Received: (nullmailer pid 2251 invoked by uid 1000); Sun, 05 Apr 2015\r
+ 22:59:25 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP2 08/12] cli/show: add lastmod to structured output\r
+Date: Mon, 6 Apr 2015 07:59:10 +0900\r
+Message-Id: <1428274754-1698-9-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net>\r
+References: <1428274754-1698-1-git-send-email-david@tethera.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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, 05 Apr 2015 23:03:44 -0000\r
+\r
+Here again we restrict a few tests to version 2, to keep them passing.\r
+---\r
+ devel/schemata | 2 ++\r
+ lib/message.cc | 20 ++++++++++++++++++++\r
+ lib/notmuch.h | 8 ++++++++\r
+ notmuch-show.c | 7 +++++++\r
+ test/T190-multipart.sh | 6 +++---\r
+ test/T220-reply.sh | 2 +-\r
+ 6 files changed, 41 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/devel/schemata b/devel/schemata\r
+index 76dad01..02f7cc0 100644\r
+--- a/devel/schemata\r
++++ b/devel/schemata\r
+@@ -71,6 +71,8 @@ message = {\r
+ match: bool,\r
+ filename: string,\r
+ timestamp: unix_time, # date header as unix time\r
++ lastmod: int, # database revision when message\r
++ # was update\r
+ date_relative: string, # user-friendly timestamp\r
+ tags: [string*],\r
+ \r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 26b5e76..9d04438 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -939,6 +939,26 @@ notmuch_message_get_date (notmuch_message_t *message)\r
+ return Xapian::sortable_unserialise (value);\r
+ }\r
+ \r
++time_t\r
++notmuch_message_get_last_mod (notmuch_message_t *message)\r
++{\r
++ std::string value;\r
++\r
++ try {\r
++ value = message->doc.get_value (NOTMUCH_VALUE_LAST_MOD);\r
++ } catch (Xapian::Error &error) {\r
++ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading last modification: %s\n",\r
++ error.get_msg().c_str());\r
++ message->notmuch->exception_reported = TRUE;\r
++ return 0;\r
++ }\r
++\r
++ if (value.empty ())\r
++ /* sortable_unserialise is undefined on empty string */\r
++ return -1;\r
++ return Xapian::sortable_unserialise (value);\r
++}\r
++\r
+ notmuch_tags_t *\r
+ notmuch_message_get_tags (notmuch_message_t *message)\r
+ {\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 5c17d97..b4897ab 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -1324,6 +1324,14 @@ time_t\r
+ notmuch_message_get_date (notmuch_message_t *message);\r
+ \r
+ /**\r
++ * Get the last database modifaction revision of 'message' as an\r
++ * integer.\r
++ *\r
++ */\r
++long int\r
++notmuch_message_get_last_mod (notmuch_message_t *message);\r
++\r
++/**\r
+ * Get the value of the specified header from 'message' as a UTF-8 string.\r
+ *\r
+ * Common headers are stored in the database when the message is\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 4489ea5..3917b82 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -121,6 +121,7 @@ format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)\r
+ void *local = talloc_new (NULL);\r
+ notmuch_tags_t *tags;\r
+ time_t date;\r
++ long int revision;\r
+ const char *relative_date;\r
+ \r
+ sp->map_key (sp, "id");\r
+@@ -139,6 +140,12 @@ format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)\r
+ date = notmuch_message_get_date (message);\r
+ sp->integer (sp, date);\r
+ \r
++ if (notmuch_format_version >= 3) {\r
++ sp->map_key (sp, "lastmod");\r
++ revision = notmuch_message_get_last_mod (message);\r
++ sp->integer (sp, revision);\r
++ }\r
++\r
+ sp->map_key (sp, "date_relative");\r
+ relative_date = notmuch_time_relative_date (local, date);\r
+ sp->string (sp, relative_date);\r
+diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh\r
+index f8b805f..a6b4fca 100755\r
+--- a/test/T190-multipart.sh\r
++++ b/test/T190-multipart.sh\r
+@@ -343,7 +343,7 @@ test_expect_success \\r
+ "notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"\r
+ \r
+ test_begin_subtest "--format=json --part=0, full message"\r
+-notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT\r
++notmuch show --format=json --format-version=2 --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT\r
+ cat <<EOF >EXPECTED\r
+ {"id": "87liy5ap00.fsf@yoom.home.cworth.org", "match": true, "excluded": false, "filename": "${MAIL_DIR}/multipart", "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["attachment","inbox","signed","unread"], "headers": {"Subject": "Multipart message", "From": "Carl Worth <cworth@cworth.org>", "To": "cworth@cworth.org", "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [\r
+ {"id": 1, "content-type": "multipart/signed", "content": [\r
+@@ -449,7 +449,7 @@ notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT\r
+ test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart\r
+ \r
+ test_begin_subtest "--format=raw --part=0, full message"\r
+-notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT\r
++NOTMUCH_SHOW --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT\r
+ test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart\r
+ \r
+ test_begin_subtest "--format=raw --part=1, message body"\r
+@@ -617,7 +617,7 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "'notmuch reply' to a multipart message with json format"\r
+-notmuch reply --format=json 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT\r
++notmuch reply --format=json --format-version=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT\r
+ notmuch_json_show_sanitize <<EOF >EXPECTED\r
+ {"reply-headers": {"Subject": "Re: Multipart message",\r
+ "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",\r
+diff --git a/test/T220-reply.sh b/test/T220-reply.sh\r
+index b0d854a..e72f2e4 100755\r
+--- a/test/T220-reply.sh\r
++++ b/test/T220-reply.sh\r
+@@ -216,7 +216,7 @@ On Tue, 05 Jan 2010 15:43:56 -0000, ☃ <snowman@example.com> wrote:\r
+ > Encoding"\r
+ \r
+ test_begin_subtest "Reply with RFC 2047-encoded headers (JSON)"\r
+-output=$(notmuch reply --format=json id:${gen_msg_id})\r
++output=$(notmuch reply --format=json --format-version=2 id:${gen_msg_id})\r
+ test_expect_equal_json "$output" '\r
+ {\r
+ "original": {\r
+-- \r
+2.1.4\r
+\r