From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id CKObGM6U82C5FwAAgWs5BA (envelope-from ) for ; Sun, 18 Jul 2021 04:41:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id sFxSFM6U82CwGAAAB5/wlQ (envelope-from ) for ; Sun, 18 Jul 2021 02:41:18 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id F171C1E7FA for ; Sun, 18 Jul 2021 04:41:17 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 3023E295AF; Sat, 17 Jul 2021 22:40:56 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 23CFC29093 for ; Sat, 17 Jul 2021 22:40:36 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 1B5475FD21; Sat, 17 Jul 2021 22:40:36 -0400 (EDT) Received: (nullmailer pid 3853955 invoked by uid 1000); Sun, 18 Jul 2021 02:40:27 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 17/25] lib/query: generalize exclude handling to s-expression queries Date: Sat, 17 Jul 2021 23:40:13 -0300 Message-Id: <20210718024021.3850340-18-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210718024021.3850340-1-david@tethera.net> References: <20210718024021.3850340-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: BOJTOFUWE63YFNOQZ2ADCH4BEIGVBCBX X-Message-ID-Hash: BOJTOFUWE63YFNOQZ2ADCH4BEIGVBCBX 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; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1626576078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc: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-unsubscribe:list-subscribe:list-post; bh=Cq5dphm1ff2suQX6nF4I4yGhahQ24zXpAlhyFj17mcg=; b=s8qJe8p4E91KURwiy+MAcBIcOAdwD1YMhV4ch7bzS05pqdYaiFj+jLd2QK/ijNDmhyv4bQ kz/hIT+kQ4E6Ze7r0wh65JOGzJ7d3zkznLtKudoAu20hAO69VEDf8q7Ouss7NH+bssqwVs 9P1JKcd7Ornf4FSTgX+FcKkcsIL38IzsRrl2o7dxpJGzbsJ0kBMd1EDboLPP4yZWch9tLD e4WWwixhUd8F9VmaJYrXn72w7grgXt3f5moXaVN5rNIhPdmA1a3l84dX+Ucya2QkV3SyuA vDLcU6eTNEKY4GIMnEOmTeElaSS5PDHkXIfVhLF4Lo8XKgoYYZ+HhhOLFFgcYQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626576078; a=rsa-sha256; cv=none; b=gUia3eOr0En3ZXjC/kxC/wcej6tJS1/ydNm2tUlKAsW/JRyGgP1ppsV6+c/RjVIFg34+3r iIfiCAPGycDtHYIlF1zZaBAmNWDQnHjA1aJ53MmQ+bXISaeFgGUnDiq6RFBqSZydBcHZZG CESemN2DIEyfjbLj0fetBBowr4DSU8eDOJ0+I9GPKFjtVxWRGfkSd7VU5bxE6z7IKLFiac o46v0ZUoOHtIHbCXT72DfoUT1XFaVv1GG6N9FhAqe8bYnliSRs/ja34tn1qzQBg/BMzeGc VFGI9LU7KatG+OxohWcNR/lPL7g4EH9CMfwNgUoky+gVP4qOiZC67DOXC5SGng== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.05 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: F171C1E7FA X-Spam-Score: -1.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: p1tjhz3jRn60 In fact most of the code path is in common, only the caching of terms in the query needs to be added for s-expression queries. --- lib/query.cc | 34 +++++++++++++++++++++++----------- test/T081-sexpr-search.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/lib/query.cc b/lib/query.cc index a3cba662..46bc1373 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -153,6 +153,19 @@ notmuch_query_create_sexpr (notmuch_database_t *notmuch, return query; } +static void +_notmuch_query_cache_terms (notmuch_query_t *query) +{ + /* Xapian doesn't support skip_to on terms from a query since + * they are unordered, so cache a copy of all terms in + * something searchable. + */ + + for (Xapian::TermIterator t = query->xapian_query.get_terms_begin (); + t != query->xapian_query.get_terms_end (); ++t) + query->terms.insert (*t); +} + static notmuch_status_t _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) { @@ -161,15 +174,7 @@ _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) query->notmuch->query_parser-> parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS); - /* Xapian doesn't support skip_to on terms from a query since - * they are unordered, so cache a copy of all terms in - * something searchable. - */ - - for (Xapian::TermIterator t = query->xapian_query.get_terms_begin (); - t != query->xapian_query.get_terms_end (); ++t) - query->terms.insert (*t); - + _notmuch_query_cache_terms (query); query->parsed = true; } catch (const Xapian::Error &error) { @@ -191,11 +196,18 @@ _notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) static notmuch_status_t _notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query) { + notmuch_status_t status; + if (query->parsed) return NOTMUCH_STATUS_SUCCESS; - return _notmuch_sexp_string_to_xapian_query (query->notmuch, query->query_string, - query->xapian_query); + status = _notmuch_sexp_string_to_xapian_query (query->notmuch, query->query_string, + query->xapian_query); + if (status) + return status; + + _notmuch_query_cache_terms (query); + return NOTMUCH_STATUS_SUCCESS; } static notmuch_status_t diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 43781f44..04eba2c0 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -340,4 +340,41 @@ notmuch search property:foo=bar > EXPECTED notmuch search --query-syntax=sexp '(property :any)' > OUTPUT test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "Search, exclude \"deleted\" messages from search" +notmuch config set search.exclude_tags deleted +generate_message '[subject]="Not deleted"' +not_deleted_id=$gen_msg_id +generate_message '[subject]="Deleted"' +notmuch new > /dev/null +notmuch tag +deleted id:$gen_msg_id +deleted_id=$gen_msg_id +output=$(notmuch search --query-syntax=sexp '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread)" + +test_begin_subtest "Search, exclude \"deleted\" messages from message search --exclude=false" +output=$(notmuch search --query-syntax=sexp --exclude=false --output=messages '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "id:$not_deleted_id +id:$deleted_id" + +test_begin_subtest "Search, exclude \"deleted\" messages from search, overridden" +output=$(notmuch search --query-syntax=sexp '(and (subject deleted) (tag deleted))' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Deleted (deleted inbox unread)" + +test_begin_subtest "Search, exclude \"deleted\" messages from threads" +add_message '[subject]="Not deleted reply"' '[in-reply-to]="<$gen_msg_id>"' +output=$(notmuch search --query-syntax=sexp '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) +thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)" + +test_begin_subtest "Search, don't exclude \"deleted\" messages when --exclude=flag specified" +output=$(notmuch search --query-syntax=sexp --exclude=flag '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) +thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Deleted (deleted inbox unread)" + +test_begin_subtest "Search, don't exclude \"deleted\" messages from search if not configured" +notmuch config set search.exclude_tags +output=$(notmuch search --query-syntax=sexp '(subject deleted)' | notmuch_search_sanitize) +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) +thread:XXX 2001-01-05 [2/2] Notmuch Test Suite; Deleted (deleted inbox unread)" + test_done -- 2.30.2