From 539e32f0565d3ce9602f5241efc424d3db9f0df1 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 6 Apr 2015 07:59:10 +0900 Subject: [PATCH] [WIP2 08/12] cli/show: add lastmod to structured output --- 2a/416a31ecd4710a4fd876021be0a07aec8e2a2f | 195 ++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 2a/416a31ecd4710a4fd876021be0a07aec8e2a2f diff --git a/2a/416a31ecd4710a4fd876021be0a07aec8e2a2f b/2a/416a31ecd4710a4fd876021be0a07aec8e2a2f new file mode 100644 index 000000000..adfb2ac8f --- /dev/null +++ b/2a/416a31ecd4710a4fd876021be0a07aec8e2a2f @@ -0,0 +1,195 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id D18286DE1BB6 + for ; Sun, 5 Apr 2015 16:03:44 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.495 +X-Spam-Level: +X-Spam-Status: No, score=0.495 tagged_above=-999 required=5 tests=[AWL=0.485, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id tX931MVO-Mzt for ; + Sun, 5 Apr 2015 16:03:43 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 24B2E6DE1BAD + for ; Sun, 5 Apr 2015 16:03:36 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YetZ8-0002qC-Gw; Sun, 05 Apr 2015 23:02:54 +0000 +Received: (nullmailer pid 2251 invoked by uid 1000); Sun, 05 Apr 2015 + 22:59:25 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [WIP2 08/12] cli/show: add lastmod to structured output +Date: Mon, 6 Apr 2015 07:59:10 +0900 +Message-Id: <1428274754-1698-9-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net> +References: <1428274754-1698-1-git-send-email-david@tethera.net> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 05 Apr 2015 23:03:44 -0000 + +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 <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 ", "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 <EXPECTED + {"reply-headers": {"Subject": "Re: Multipart message", + "From": "Notmuch Test Suite ", +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, ☃ 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 + -- 2.26.2