From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [WIP2 08/12] cli/show: add lastmod to structured output
Date: Mon, 6 Apr 2015 07:59:10 +0900 [thread overview]
Message-ID: <1428274754-1698-9-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net>
Here again we restrict a few tests to version 2, to keep them passing.
---
devel/schemata | 2 ++
lib/message.cc | 20 ++++++++++++++++++++
lib/notmuch.h | 8 ++++++++
notmuch-show.c | 7 +++++++
test/T190-multipart.sh | 6 +++---
test/T220-reply.sh | 2 +-
6 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/devel/schemata b/devel/schemata
index 76dad01..02f7cc0 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -71,6 +71,8 @@ message = {
match: bool,
filename: string,
timestamp: unix_time, # date header as unix time
+ lastmod: int, # database revision when message
+ # was update
date_relative: string, # user-friendly timestamp
tags: [string*],
diff --git a/lib/message.cc b/lib/message.cc
index 26b5e76..9d04438 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -939,6 +939,26 @@ notmuch_message_get_date (notmuch_message_t *message)
return Xapian::sortable_unserialise (value);
}
+time_t
+notmuch_message_get_last_mod (notmuch_message_t *message)
+{
+ std::string value;
+
+ try {
+ value = message->doc.get_value (NOTMUCH_VALUE_LAST_MOD);
+ } catch (Xapian::Error &error) {
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading last modification: %s\n",
+ error.get_msg().c_str());
+ message->notmuch->exception_reported = TRUE;
+ return 0;
+ }
+
+ if (value.empty ())
+ /* sortable_unserialise is undefined on empty string */
+ return -1;
+ return Xapian::sortable_unserialise (value);
+}
+
notmuch_tags_t *
notmuch_message_get_tags (notmuch_message_t *message)
{
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 5c17d97..b4897ab 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1324,6 +1324,14 @@ time_t
notmuch_message_get_date (notmuch_message_t *message);
/**
+ * Get the last database modifaction revision of 'message' as an
+ * integer.
+ *
+ */
+long int
+notmuch_message_get_last_mod (notmuch_message_t *message);
+
+/**
* Get the value of the specified header from 'message' as a UTF-8 string.
*
* Common headers are stored in the database when the message is
diff --git a/notmuch-show.c b/notmuch-show.c
index 4489ea5..3917b82 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -121,6 +121,7 @@ format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)
void *local = talloc_new (NULL);
notmuch_tags_t *tags;
time_t date;
+ long int revision;
const char *relative_date;
sp->map_key (sp, "id");
@@ -139,6 +140,12 @@ format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)
date = notmuch_message_get_date (message);
sp->integer (sp, date);
+ if (notmuch_format_version >= 3) {
+ sp->map_key (sp, "lastmod");
+ revision = notmuch_message_get_last_mod (message);
+ sp->integer (sp, revision);
+ }
+
sp->map_key (sp, "date_relative");
relative_date = notmuch_time_relative_date (local, date);
sp->string (sp, relative_date);
diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh
index f8b805f..a6b4fca 100755
--- a/test/T190-multipart.sh
+++ b/test/T190-multipart.sh
@@ -343,7 +343,7 @@ test_expect_success \
"notmuch show --format=text --part=8 'id:87liy5ap00.fsf@yoom.home.cworth.org'"
test_begin_subtest "--format=json --part=0, full message"
-notmuch show --format=json --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
+notmuch show --format=json --format-version=2 --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
cat <<EOF >EXPECTED
{"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": [
{"id": 1, "content-type": "multipart/signed", "content": [
@@ -449,7 +449,7 @@ notmuch show --format=raw 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
test_begin_subtest "--format=raw --part=0, full message"
-notmuch show --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
+NOTMUCH_SHOW --format=raw --part=0 'id:87liy5ap00.fsf@yoom.home.cworth.org' >OUTPUT
test_expect_equal_file OUTPUT "${MAIL_DIR}"/multipart
test_begin_subtest "--format=raw --part=1, message body"
@@ -617,7 +617,7 @@ EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "'notmuch reply' to a multipart message with json format"
-notmuch reply --format=json 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT
+notmuch reply --format=json --format-version=2 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT
notmuch_json_show_sanitize <<EOF >EXPECTED
{"reply-headers": {"Subject": "Re: Multipart message",
"From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
diff --git a/test/T220-reply.sh b/test/T220-reply.sh
index b0d854a..e72f2e4 100755
--- a/test/T220-reply.sh
+++ b/test/T220-reply.sh
@@ -216,7 +216,7 @@ On Tue, 05 Jan 2010 15:43:56 -0000, ☃ <snowman@example.com> wrote:
> Encoding"
test_begin_subtest "Reply with RFC 2047-encoded headers (JSON)"
-output=$(notmuch reply --format=json id:${gen_msg_id})
+output=$(notmuch reply --format=json --format-version=2 id:${gen_msg_id})
test_expect_equal_json "$output" '
{
"original": {
--
2.1.4
next prev parent reply other threads:[~2015-04-05 23:03 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-05 22:59 Revision tracking, round 2 David Bremner
2015-04-05 22:59 ` [WIP2 01/12] lib: Only sync modified message documents David Bremner
2015-04-05 22:59 ` [WIP2 02/12] lib: Add per-message last modification tracking David Bremner
2015-04-05 22:59 ` [WIP2 03/12] lib: API to retrieve database revision and UUID David Bremner
2015-04-05 22:59 ` [WIP2 04/12] cli: add type introspection to sprinter type David Bremner
2015-04-05 22:59 ` [WIP2 05/12] cli: add two sprinter utility functions David Bremner
2015-04-05 22:59 ` [WIP2 06/12] cli/show: add extra element to structured output for metadata David Bremner
2015-04-05 22:59 ` [WIP2 07/12] lib: Add "lastmod:" queries for filtering by last modification David Bremner
2015-04-05 22:59 ` David Bremner [this message]
2015-04-05 22:59 ` [WIP2 09/12] cli/search: add metadata element to structured output David Bremner
2015-04-05 22:59 ` [WIP2 10/12] emacs: convert notmuch-search to format-version 3 David Bremner
2015-04-05 22:59 ` [WIP2 11/12] emacs: convert notmuch-tree " David Bremner
2015-04-05 22:59 ` [WIP2 12/12] cli: add global option "--db-revision" David Bremner
2015-05-29 21:56 ` Revision tracking, round 2 Gaute Hope
2015-06-05 17:28 ` revision tracking patches, round 1 David Bremner
2015-06-05 17:28 ` [PATCH 1/6] lib: Only sync modified message documents David Bremner
2015-08-04 7:07 ` David Bremner
2015-06-05 17:28 ` [PATCH 2/6] lib: Add per-message last modification tracking David Bremner
2015-08-07 7:36 ` Daniel Schoepe
2015-08-07 20:38 ` David Bremner
2015-08-08 13:05 ` Austin Clements
2015-08-08 5:33 ` [PATCH] fixup! " David Bremner
2015-06-05 17:28 ` [PATCH 3/6] lib: API to retrieve database revision and UUID David Bremner
2015-08-06 10:26 ` Tomi Ollila
2015-06-05 17:28 ` [PATCH 4/6] cli/count: add --output=modifications David Bremner
2015-06-05 17:28 ` [PATCH 5/6] cli: add global option "--db-revision" David Bremner
2015-08-07 8:05 ` Daniel Schoepe
2015-08-07 20:47 ` David Bremner
2015-06-05 17:28 ` [PATCH 6/6] lib: Add "lastmod:" queries for filtering by last modification David Bremner
2015-08-07 8:16 ` Daniel Schoepe
2015-08-07 20:22 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428274754-1698-9-git-send-email-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).