From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id kFtxJaRVFWFdNwEAgWs5BA (envelope-from ) for ; Thu, 12 Aug 2021 19:08:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 8PgEIaRVFWFgHQAAbx9fmQ (envelope-from ) for ; Thu, 12 Aug 2021 17:08:52 +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 235676C59 for ; Thu, 12 Aug 2021 19:08:52 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id D53D629307; Thu, 12 Aug 2021 13:08:18 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6DA8E29224 for ; Thu, 12 Aug 2021 13:08:07 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 65E535FD5C; Thu, 12 Aug 2021 13:08:07 -0400 (EDT) Received: (nullmailer pid 1348728 invoked by uid 1000); Thu, 12 Aug 2021 17:07:43 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 04/31] CLI/search+address: support sexpr queries Date: Thu, 12 Aug 2021 10:07:01 -0700 Message-Id: <20210812170728.1348333-5-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812170728.1348333-1-david@tethera.net> References: <20210812170728.1348333-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: H4UPQMKGBALKJI3JNMBTTA2LKQVZFWJM X-Message-ID-Hash: H4UPQMKGBALKJI3JNMBTTA2LKQVZFWJM 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=1628788132; 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=MNeX9LArgNCax0T5awYOUEqn6UDkHi2foM8w0tSomCk=; b=rHDfH5osGqyAdTwTEDJKYYCEeoz1ius6HJAPwjyKmh9LgjaOixI9IOu8TZMhohAvpvMGRG CI2PoiWkWnHHn6Nj5QALK+hklvhzwGkrNEdOMxLY4rfg4UkFqRDNYXS9GclVddWMJIok6b h+NMVk9ZLFYe4PYhGncZnWj6NDYTn2Pcy+QGBGipCe9+iPRRB+qXrC48wdrnUaZK+na3Y0 pglbn46PZXXU2o59Y3DIJy03nTVfNirqeBcaEemBjA90aagYGKvaICB0UJDUD7QMJqzQYl 6m96RCqhQnwhYpkcj6ZfgJzEtxtU5z2nrX+MTXZFiRpQLG/avb6cR7phktc03A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628788132; a=rsa-sha256; cv=none; b=eCunkj0w3ODpnAVdtfq3SS9LEqF4q2TciipltJC0d1RcblYAEWJSp0Se2r1ePrWwIc4nou Oxo+M5ogTXsISHl10k38+oE/payhRBs94y6XIItJpFWuFxRV7ugBPevCA0bknM5wSJywFW genoLWPUOLBHEDOE/tLLOYBTn7xmoAiMBouWl87PUiAS59e0t4rftACl/WQtf5iNmIHGHL 1mGim/TRidTYN14fSXHghT94PShl3Nu+Ku0pcbRsRdloM9oJ4stx2DrFopNeAMENfijxpD vByuntPSaq2iQlNyBaME2w5hSrxtZUcPwH9pWJmwUsDs2HNEWMwGiV9xWnzU6w== 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: 0.56 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: 235676C59 X-Spam-Score: 0.56 X-Migadu-Scanner: scn0.migadu.com X-TUID: RExCBt3V9PlQ Initially support selection of query syntax in two subcommands to enable testing. --- notmuch-search.c | 13 +++++++++---- test/T080-search.sh | 5 +++++ test/T095-address.sh | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/notmuch-search.c b/notmuch-search.c index 244817a9..9ac15596 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -56,6 +56,7 @@ typedef struct { int format_sel; sprinter_t *format; int exclude; + int query_syntax; notmuch_query_t *query; int sort; int output; @@ -721,11 +722,10 @@ _notmuch_search_prepare (search_context_t *ctx, int argc, char *argv[]) return EXIT_FAILURE; } - ctx->query = notmuch_query_create (ctx->notmuch, query_str); - if (ctx->query == NULL) { - fprintf (stderr, "Out of memory\n"); + if (print_status_database ("notmuch search", ctx->notmuch, + notmuch_query_create_with_syntax (ctx->notmuch, query_str, + ctx->query_syntax, &ctx->query))) return EXIT_FAILURE; - } notmuch_query_set_sort (ctx->query, ctx->sort); @@ -771,6 +771,7 @@ static search_context_t search_context = { .format_sel = NOTMUCH_FORMAT_TEXT, .exclude = NOTMUCH_EXCLUDE_TRUE, .sort = NOTMUCH_SORT_NEWEST_FIRST, + .query_syntax = NOTMUCH_QUERY_SYNTAX_XAPIAN, .output = 0, .offset = 0, .limit = -1, /* unlimited */ @@ -789,6 +790,10 @@ static const notmuch_opt_desc_t common_options[] = { { "text", NOTMUCH_FORMAT_TEXT }, { "text0", NOTMUCH_FORMAT_TEXT0 }, { 0, 0 } } }, + { .opt_keyword = &search_context.query_syntax, .name = "query", .keywords = + (notmuch_keyword_t []){ { "infix", NOTMUCH_QUERY_SYNTAX_XAPIAN }, + { "sexp", NOTMUCH_QUERY_SYNTAX_SEXP }, + { 0, 0 } } }, { .opt_int = ¬much_format_version, .name = "format-version" }, { } }; diff --git a/test/T080-search.sh b/test/T080-search.sh index a3f0dead..5f6c1456 100755 --- a/test/T080-search.sh +++ b/test/T080-search.sh @@ -189,4 +189,9 @@ test_begin_subtest "parts do not have adjacent term positions" output=$(notmuch search id:termpos and '"c x"') test_expect_equal "$output" "" +test_begin_subtest "sexpr query: all messages" +notmuch search '*' > EXPECTED +notmuch search --query=sexp '()' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + test_done diff --git a/test/T095-address.sh b/test/T095-address.sh index 817be538..3060f603 100755 --- a/test/T095-address.sh +++ b/test/T095-address.sh @@ -325,4 +325,9 @@ cat <EXPECTED EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "sexpr query: all messages" +notmuch address '*' > EXPECTED +notmuch address --query=sexp '()' > OUTPUT +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.30.2