From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id yDbxMsop7mD8egAAgWs5BA (envelope-from ) for ; Wed, 14 Jul 2021 02:03:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CFCNLsop7mDubwAAbx9fmQ (envelope-from ) for ; Wed, 14 Jul 2021 00:03:22 +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 5360682E3 for ; Wed, 14 Jul 2021 02:03:22 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2DB1B290E1; Tue, 13 Jul 2021 20:03:04 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 09449290D1 for ; Tue, 13 Jul 2021 20:02:46 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id EA6135FD21; Tue, 13 Jul 2021 20:02:46 -0400 (EDT) Received: (nullmailer pid 804671 invoked by uid 1000); Wed, 14 Jul 2021 00:02:42 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 11/11] lib/parse-sexp: initial support for wildcard queries Date: Tue, 13 Jul 2021 21:02:39 -0300 Message-Id: <20210714000239.804384-12-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210714000239.804384-1-david@tethera.net> References: <20210714000239.804384-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: T5VQO2ERDDZYYNVJ66OK7CZ2GAAUEXMF X-Message-ID-Hash: T5VQO2ERDDZYYNVJ66OK7CZ2GAAUEXMF 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=1626221002; 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=eexUPXWM816DQg364urMiZnQZi8lUsEJmGgh/Imd8VA=; b=dQ8HZ0mCMZh2N1GawnylC5Lm6cxStP0YeU1fGGZLxpMyjbrdYzBlHeumgzRRrO1PwT7V90 +wDLDtAyAvd+F2k53eq1U/qoRJ8MKLIsw6PvazIWqkOZ9P/r2Kv5QM8hJLB5MrP4Fa4sOJ jKfQ27ObJ5NsEKs4xjdwy0dWBIIGiPxkkYS+3oUcjJ0JSZk7X3gIwg8OybOzUUyFQgVnN0 62bVHbrQ+X0F+BWn7xHR0AF+yaaEpqqRpU0gkeWmp0UZ+N3fHQBShsXYj1U4Qny75B/Av4 u7peA8V6VZlXllnaVY1HzB2TB5oFp5jvjIi2MCWvPHeLNfiwvjBuSG9pOXeyrw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626221002; a=rsa-sha256; cv=none; b=r+Uyf/VI8zkPsrTHX5GLlPMv4lqo8H2+YDB5J60CBOR6wAfYFB/uchSa7WAxXomthyizT8 ubixZHfVWztcc+qdcfdRri27+i+92idlBjjg4jOH4hq4CpNqWTxK3rnrgIdWYkoOFQBykE clKJOqoAJR2MCvXZOPCURo7UzlwnyC2+8X2R2w5fSonI1LlsKLPOb6xneK99Z69xMYQ5qe 1Lt4P7mtE3ubmUBj3HZIuEMJRHOmW9fe4BUbAvRyvnH7x8GKvdPY5p0ha4NGkXanQWnYYT b7c6bfGZht+EpttVIVyYTb4pSDio0rll/3SH05YpuVts2Gg2WZicCQL4lU5kLA== 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.08 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: 5360682E3 X-Spam-Score: -1.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: 46UMNv0ZZWDb Because of the implicit way body: queries are implemented, additional code will be needed for them. --- lib/parse-sexp.cc | 12 +++++++-- test/T081-sexpr-search.sh | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index bfa566b1..a0f5e5bf 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -221,6 +221,7 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, sexp_t *sx, Xapian::Query &o if (strcasecmp (field->name, hd_sexp (sx)->val) == 0) { _sexp_flag_t flags; sexp_t *rest; + const char *term_prefix; notmuch_status_t status = _sexp_parse_keywords (notmuch, sx->list->val, sx->list->next, field->flags_allowed, @@ -228,8 +229,15 @@ _sexp_to_xapian_query (notmuch_database_t *notmuch, sexp_t *sx, Xapian::Query &o if (status) return status; - return _sexp_combine_field (_find_prefix (field->name), field->xapian_op, rest, - output); + term_prefix = _find_prefix (field->name); + + if (flags & SEXP_FLAG_WILDCARD) { + output = Xapian::Query (Xapian::Query::OP_WILDCARD, term_prefix); + return NOTMUCH_STATUS_SUCCESS; + } else { + return _sexp_combine_field (term_prefix, field->xapian_op, rest, + output); + } } } diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh index 6e8687da..d8a89c6f 100755 --- a/test/T081-sexpr-search.sh +++ b/test/T081-sexpr-search.sh @@ -221,4 +221,58 @@ test_expect_success 'notmuch search --query-syntax=sexp "(subject \":foo\")"' test_begin_subtest "unknown keyword after non-keyword" test_expect_success 'notmuch search --query-syntax=sexp "(subject foo :foo)"' +test_begin_subtest "wildcard search for attachment" +notmuch search tag:attachment > EXPECTED +notmuch search --query-syntax=sexp '(attachment :*)' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +add_message '[subject]="empty body"' '[body]="."' +notmuch tag +nobody id:${gen_msg_id} + +test_begin_subtest "wildcard search for body" +test_subtest_known_broken +notmuch search not tag:nobody > EXPECTED +notmuch search --query-syntax=sexp '(body :any)' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "negated wildcard search for body" +test_subtest_known_broken +notmuch search tag:nobody > EXPECTED +notmuch search --query-syntax=sexp '(not (body :any))' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +add_message '[subject]="no tags"' +notag_mid=${gen_msg_id} +notmuch tag -unread -inbox id:${notag_mid} + +test_begin_subtest "wildcard search for 'is'" +notmuch search not id:${notag_mid} > EXPECTED +notmuch search --query-syntax=sexp '(is :any)' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "negated wildcard search for 'is'" +notmuch search id:${notag_mid} > EXPECTED +notmuch search --query-syntax=sexp '(not (is :any))' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "wildcard search for 'tag'" +notmuch search not id:${notag_mid} > EXPECTED +notmuch search --query-syntax=sexp '(tag :any)' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "negated wildcard search for 'tag'" +notmuch search id:${notag_mid} > EXPECTED +notmuch search --query-syntax=sexp '(not (tag :any))' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + +add_message '[subject]="message with properties"' +notmuch restore < EXPECTED +notmuch search --query-syntax=sexp '(property :any)' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.30.2