]> git.notmuchmail.org Git - notmuch/blobdiff - lib/parse-sexp.cc
lib/parse-sexp: handle lastmod queries.
[notmuch] / lib / parse-sexp.cc
index dbc3f89d903305969dccc2752582b97d3c45f74a..06825dc477377d3b4570a760abffce8d626cfe0c 100644 (file)
@@ -79,6 +79,8 @@ static _sexp_prefix_t prefixes[] =
       SEXP_FLAG_SINGLE | SEXP_FLAG_ORPHAN },
     { "is",             Xapian::Query::OP_AND,          Xapian::Query::MatchAll,
       SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
+    { "lastmod",           Xapian::Query::OP_INVALID,      Xapian::Query::MatchAll,
+      SEXP_FLAG_RANGE },
     { "matching",       Xapian::Query::OP_AND,          Xapian::Query::MatchAll,
       SEXP_FLAG_DO_EXPAND },
     { "mid",            Xapian::Query::OP_OR,           Xapian::Query::MatchNothing,
@@ -495,6 +497,29 @@ _sexp_parse_range (notmuch_database_t *notmuch,  const _sexp_prefix_t *prefix,
        return status;
     }
 
+    if (strcmp (prefix->name, "lastmod") == 0) {
+       long from_idx, to_idx;
+
+       try {
+           from_idx = std::stol (from);
+       } catch (std::logic_error &e) {
+           _notmuch_database_log (notmuch, "bad 'from' revision: '%s'\n", from);
+           return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
+       }
+
+       try {
+           to_idx = std::stol (to);
+       } catch (std::logic_error &e) {
+           _notmuch_database_log (notmuch, "bad 'to' revision: '%s'\n", to);
+           return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
+       }
+
+       output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, NOTMUCH_VALUE_LAST_MOD,
+                               Xapian::sortable_serialise (from_idx),
+                               Xapian::sortable_serialise (to_idx));
+       return NOTMUCH_STATUS_SUCCESS;
+    }
+
     _notmuch_database_log (notmuch, "unimplimented range prefix: '%s'\n", prefix->name);
     return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
 }