--- /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 2C3BA6DE1785\r
+ for <notmuch@notmuchmail.org>; Fri, 5 Jun 2015 10:31:40 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.234\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.234 tagged_above=-999 required=5 tests=[AWL=0.224, \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 aRPszRHIhMQF for <notmuch@notmuchmail.org>;\r
+ Fri, 5 Jun 2015 10:31:38 -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 0EFC06DE18DF\r
+ for <notmuch@notmuchmail.org>; Fri, 5 Jun 2015 10:31:38 -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 1Z0vRM-0002nr-CN; Fri, 05 Jun 2015 17:29:56 +0000\r
+Received: (nullmailer pid 24258 invoked by uid 1000); Fri, 05 Jun 2015\r
+ 17:28:42 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 6/6] lib: Add "lastmod:" queries for filtering by last\r
+ modification\r
+Date: Fri, 5 Jun 2015 19:28:38 +0200\r
+Message-Id: <1433525318-23756-7-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1433525318-23756-1-git-send-email-david@tethera.net>\r
+References: <1432936375-astroid-4-0i1n6yczs2-1520@strange>\r
+ <1433525318-23756-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: Fri, 05 Jun 2015 17:31:40 -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 | 18 ++++++++++++++++++\r
+ 4 files changed, 31 insertions(+)\r
+\r
+diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst\r
+index 1d27ac1..d9f213e 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 **--db-revision** 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 ba8b8d9..a7daa44 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -986,6 +986,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
+@@ -993,6 +994,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
+@@ -1071,6 +1073,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 bb09bf6..7ad8b2a 100755\r
+--- a/test/T570-revision-tracking.sh\r
++++ b/test/T570-revision-tracking.sh\r
+@@ -72,4 +72,22 @@ test_expect_success 'tag succeeds with correct db revision' \\r
+ \r
+ test_expect_code 1 'tag fails with incorrect db revision' \\r
+ "notmuch show --db-revision=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