From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id x6PHJ0O302FvCAAAgWs5BA (envelope-from ) for ; Tue, 04 Jan 2022 03:56:03 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id OCyqI0O302GP6AAAauVa8A (envelope-from ) for ; Tue, 04 Jan 2022 03:56:03 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 42B4CE430 for ; Tue, 4 Jan 2022 03:56:03 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 07C6B5F727; Tue, 4 Jan 2022 02:55:45 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 705B95F401 for ; Tue, 4 Jan 2022 02:55:41 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id C86C05FC48; Mon, 3 Jan 2022 21:55:40 -0500 (EST) Received: (nullmailer pid 1725912 invoked by uid 1000); Tue, 04 Jan 2022 02:55:35 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 6/6] lib/parse-sexp: handle lastmod queries. Date: Mon, 3 Jan 2022 22:55:29 -0400 Message-Id: <20220104025529.1725839-7-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104025529.1725839-1-david@tethera.net> References: <20220104025529.1725839-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: AYBLQ72SAUWBJCI3BLLG2QT5NRAN2B2C X-Message-ID-Hash: AYBLQ72SAUWBJCI3BLLG2QT5NRAN2B2C X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641264963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=RWdNlTIMuSS1JAJY/2MpWfC5x+UR49Sv40NmW74QPW0=; b=WUZy7alx5zrteZEDzc3LN4VN72sYOkVgGRhgJTHSgqiIgyACa2izw7RYwtRpmiiStiOzg8 YcCZVNG5rJmiNtaPjvfU6vl1/NWL3SlGGljpls8fgLKyG2c+429oebuMReYWiXUOZQVVV3 JMl05WYS3RcNtvA+6qaphm6w3etzxgIax6GFitYybC5sFgQquH8Rcs7elY5wNMO8tPM/Fn IVOEBVKdqag58lRHT5uQEvP24hjZDLt+t55yKgyrtxaswZqXOG8HW7kR1F0XqB5aa9tebo sX57I34rhc0U/zH7tJQzKzckjSYYEuSvjhC0evxV3teZYeeyr5a9R5DsuX73CQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641264963; a=rsa-sha256; cv=none; b=Zruu8Ump/dN93WqBgGDZINSEeltuWTA6aXUoLI+pcAMIVHxUVDp+xlOGH033ROYdgbyjyB z+W4RVunD5E2A8gHpd+/r9fIp/wDoBp/lHV1DGhvDhCk0s1+H//Unx3F+8h0Y7yvxds2nM S6kCOCBAXnJJum/xuPuvG5HQlyTz6Ys+QhSUTidXQX1dIrSmJC2lSzJPjdjtJ5mTps/O+y V1E4Ij+80Nm36DQiB+pvfs+D4LSLxFKTCMzdogShhcrAgGqT52PGPft8iIINoOf+fEjRuP 8ol8hE5NNmDTkdbbNo2ojY9xCOnlFLHoudZ9n2JA38DBu2c3eSjuy5xITPH2SA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.24 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 42B4CE430 X-Spam-Score: -1.24 X-Migadu-Scanner: scn0.migadu.com X-TUID: uUgQZ7Q4kQ/e This particular choice of converting strings to integers requires C++11. --- lib/parse-sexp.cc | 38 +++++++++++++++++++++++++++++++++++--- test/T081-sexpr-search.sh | 11 ----------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index fa88071e..06825dc4 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -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, @@ -454,7 +456,7 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix, const sexp_t *sx, Xapian::Query &output) { const char *from, *to; - std::string msg; /* ignored */ + std::string msg; /* empty range matches everything */ if (! sx) { @@ -485,8 +487,38 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix, to = sx->next->val; } - if (strcmp (prefix->name, "date") == 0) - return _notmuch_date_strings_to_query (NOTMUCH_VALUE_TIMESTAMP, from, to, output, msg); + if (strcmp (prefix->name, "date") == 0) { + notmuch_status_t status; + status = _notmuch_date_strings_to_query (NOTMUCH_VALUE_TIMESTAMP, from, to, output, msg); + if (status) { + if (! msg.empty ()) + _notmuch_database_log (notmuch, "%s\n", msg.c_str ()); + } + 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; diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 0b4ecf8e..73f45041 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -824,7 +824,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "date query, bad date" -test_subtest_known_broken notmuch search --query=sexp '(date "hawaiian-pizza-day")' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query @@ -833,13 +832,11 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, empty" -test_subtest_known_broken notmuch search from:keithp | notmuch_search_sanitize > EXPECTED notmuch search --query=sexp '(and (lastmod) (from keithp))'| notmuch_search_sanitize > OUTPUT test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, one argument" -test_subtest_known_broken notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org revision=$(notmuch count --lastmod '*' | cut -f3) notmuch search lastmod:$revision..$revision | notmuch_search_sanitize > EXPECTED @@ -847,7 +844,6 @@ notmuch search --query=sexp "(and (lastmod $revision))" | notmuch_search_saniti test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, two arguments" -test_subtest_known_broken notmuch tag +keithp from:keithp revision2=$(notmuch count --lastmod '*' | cut -f3) notmuch search lastmod:$revision..$revision2 | notmuch_search_sanitize > EXPECTED @@ -855,7 +851,6 @@ notmuch search --query=sexp "(and (lastmod $revision $revision2))" | notmuch_se test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 1" -test_subtest_known_broken notmuch search --query=sexp '(to (lastmod))' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query @@ -864,7 +859,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, bad from revision" -test_subtest_known_broken notmuch search --query=sexp '(lastmod apples)' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query @@ -873,7 +867,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, bad to revision" -test_subtest_known_broken notmuch search --query=sexp '(lastmod 0 apples)' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query @@ -882,7 +875,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 2" -test_subtest_known_broken notmuch search --query=sexp '(to (lastmod 2021-11-18))' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query @@ -891,7 +883,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 3" -test_subtest_known_broken notmuch search --query=sexp '(lastmod (to))' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query @@ -900,7 +891,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, illegal nesting 4" -test_subtest_known_broken notmuch search --query=sexp '(lastmod today (to))' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query @@ -909,7 +899,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "lastmod query, too many arguments" -test_subtest_known_broken notmuch search --query=sexp '(lastmod yesterday and tommorow)' > OUTPUT 2>&1 cat < EXPECTED notmuch search: Syntax error in query -- 2.34.1