--- /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 C0F4D6DE1760\r
+ for <notmuch@notmuchmail.org>; Sun, 9 Aug 2015 02:27:14 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.139\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.139 tagged_above=-999 required=5 tests=[AWL=0.129, \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 FkiZULXQoo-i for <notmuch@notmuchmail.org>;\r
+ Sun, 9 Aug 2015 02:27:12 -0700 (PDT)\r
+Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 7E24B6DE100F\r
+ for <notmuch@notmuchmail.org>; Sun, 9 Aug 2015 02:27:12 -0700 (PDT)\r
+Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1ZOMrC-0005WB-Nh; Sun, 09 Aug 2015 09:25:30 +0000\r
+Received: (nullmailer pid 7069 invoked by uid 1000); Sun, 09 Aug 2015\r
+ 09:24:47 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 5/5] lib: Add "lastmod:" queries for filtering by last\r
+ modification\r
+Date: Sun, 9 Aug 2015 11:24:45 +0200\r
+Message-Id: <1439112285-6681-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1439112285-6681-1-git-send-email-david@tethera.net>\r
+References: <1439112285-6681-1-git-send-email-david@tethera.net>\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, 09 Aug 2015 09:27:15 -0000\r
+\r
+From: Austin Clements <amdragon@mit.edu>\r
+\r
+The implementation is essentially the same as the date range search\r
+prior to Jani's fancy date parser.\r
+---\r
+ doc/man7/notmuch-search-terms.rst | 8 ++++++++\r
+ lib/database-private.h | 1 +\r
+ lib/database.cc | 4 ++++\r
+ test/T570-revision-tracking.sh | 17 +++++++++++++++++\r
+ 4 files changed, 30 insertions(+)\r
+\r
+diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst\r
+index 1d27ac1..e71a525 100644\r
+--- a/doc/man7/notmuch-search-terms.rst\r
++++ b/doc/man7/notmuch-search-terms.rst\r
+@@ -54,6 +54,8 @@ indicate user-supplied values):\r
+ \r
+ - date:<since>..<until>\r
+ \r
++- lastmod:<since>..<until>\r
++\r
+ The **from:** prefix is used to match the name or address of the sender\r
+ of an email message.\r
+ \r
+@@ -124,6 +126,12 @@ The time range can also be specified using timestamps with a syntax of:\r
+ Each timestamp is a number representing the number of seconds since\r
+ 1970-01-01 00:00:00 UTC.\r
+ \r
++The **lastmod:** prefix can be used to restrict the result by the\r
++database revision number of when messages were last modified (tags\r
++were added/removed or filenames changed). This is usually used in\r
++conjunction with the **--uuid** argument to **notmuch search**\r
++to find messages that have changed since an earlier query.\r
++\r
+ Operators\r
+ ---------\r
+ \r
+diff --git a/lib/database-private.h b/lib/database-private.h\r
+index 4e93257..3fb10f7 100644\r
+--- a/lib/database-private.h\r
++++ b/lib/database-private.h\r
+@@ -176,6 +176,7 @@ struct _notmuch_database {\r
+ Xapian::TermGenerator *term_gen;\r
+ Xapian::ValueRangeProcessor *value_range_processor;\r
+ Xapian::ValueRangeProcessor *date_range_processor;\r
++ Xapian::ValueRangeProcessor *last_mod_range_processor;\r
+ };\r
+ \r
+ /* Prior to database version 3, features were implied by the database\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index fc78769..bab3334 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1000,6 +1000,7 @@ notmuch_database_open_verbose (const char *path,\r
+ notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
+ notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
+ notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
++ notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");\r
+ \r
+ notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
+ notmuch->query_parser->set_database (*notmuch->xapian_db);\r
+@@ -1007,6 +1008,7 @@ notmuch_database_open_verbose (const char *path,\r
+ notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME);\r
+ notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor);\r
+ notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor);\r
++ notmuch->query_parser->add_valuerangeprocessor (notmuch->last_mod_range_processor);\r
+ \r
+ for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) {\r
+ prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i];\r
+@@ -1085,6 +1087,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+ notmuch->value_range_processor = NULL;\r
+ delete notmuch->date_range_processor;\r
+ notmuch->date_range_processor = NULL;\r
++ delete notmuch->last_mod_range_processor;\r
++ notmuch->last_mod_range_processor = NULL;\r
+ \r
+ return status;\r
+ }\r
+diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh\r
+index 74e3ba9..55337e6 100755\r
+--- a/test/T570-revision-tracking.sh\r
++++ b/test/T570-revision-tracking.sh\r
+@@ -73,4 +73,21 @@ test_expect_success 'tag succeeds with correct uuid' \\r
+ test_expect_code 1 'tag fails with incorrect uuid' \\r
+ "notmuch tag --uuid=this-is-no-uuid '*' +test2"\r
+ \r
++test_begin_subtest 'lastmod:0.. matches everything'\r
++total=$(notmuch count '*')\r
++modtotal=$(notmuch count lastmod:0..)\r
++test_expect_equal "$total" "$modtotal"\r
++\r
++test_begin_subtest 'lastmod:1000000.. matches nothing'\r
++modtotal=$(notmuch count lastmod:1000000..)\r
++test_expect_equal 0 "$modtotal"\r
++\r
++test_begin_subtest 'exclude one message using lastmod'\r
++lastmod=$(notmuch count --output=modifications '*' | cut -f2)\r
++total=$(notmuch count '*')\r
++notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org\r
++subtotal=$(notmuch count lastmod:..$lastmod)\r
++result=$(($subtotal == $total-1))\r
++test_expect_equal 1 "$result"\r
++\r
+ test_done\r
+-- \r
+2.1.4\r
+\r