From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 541BA6DE02D7 for ; Sat, 17 Nov 2018 06:36:27 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.001 X-Spam-Level: X-Spam-Status: No, score=0.001 tagged_above=-999 required=5 tests=[AWL=0.002, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r-ftR3qzqorx for ; Sat, 17 Nov 2018 06:36:26 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id DC7736DE02DD for ; Sat, 17 Nov 2018 06:36:19 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1gO1He-0006wi-Ga; Sat, 17 Nov 2018 09:09:14 -0500 Received: (nullmailer pid 1943 invoked by uid 1000); Sat, 17 Nov 2018 14:09:11 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [RFC patch 3/5] lib: setup user headers in query parser Date: Sat, 17 Nov 2018 10:08:59 -0400 Message-Id: <20181117140901.1870-4-david@tethera.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181117140901.1870-1-david@tethera.net> References: <20181117140901.1870-1-david@tethera.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Nov 2018 14:36:27 -0000 These tests will need to be updated if the Xapian query print/debug format changes. --- lib/database.cc | 40 ++++++++++++++++++++++++++++++++++++++++ test/T720-user-header.sh | 21 +++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lib/database.cc b/lib/database.cc index 9cf8062c..fa77eb91 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -299,6 +299,8 @@ prefix_t prefix_table[] = { NOTMUCH_FIELD_PROCESSOR}, }; +#define CONFIG_HEADER_PREFIX "index.header." + static void _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch) { @@ -308,6 +310,43 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch) notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix); } +static notmuch_status_t +_setup_user_query_fields (notmuch_database_t *notmuch) +{ + notmuch_config_list_t *list; + void *local = talloc_new(notmuch); + notmuch_status_t status; + + status = notmuch_database_get_config_list (notmuch, "index.header.", &list); + if (status) + return status; + for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) { + + prefix_t query_field { .name = NULL, .prefix = NULL, + .flags = NOTMUCH_FIELD_PROBABILISTIC | + NOTMUCH_FIELD_EXTERNAL + }; + + const char *key = notmuch_config_list_key (list) + + sizeof (CONFIG_HEADER_PREFIX) - 1; + + char *prefix = talloc_asprintf(local, "XU:%s", key); + for (char *p = prefix + 1; *p; p++) + *p = toupper (*p); + + query_field.name = key; + query_field.prefix = prefix; + + _setup_query_field_default (&query_field, notmuch); + } + + talloc_free (local); + + notmuch_config_list_destroy (list); + + return NOTMUCH_STATUS_SUCCESS; +} + #if HAVE_XAPIAN_FIELD_PROCESSOR static void _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) @@ -965,6 +1004,7 @@ notmuch_database_open_verbose (const char *path, _setup_query_field (prefix, notmuch); } } + status = _setup_user_query_fields (notmuch); } catch (const Xapian::Error &error) { IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n", error.get_msg().c_str())); diff --git a/test/T720-user-header.sh b/test/T720-user-header.sh index 774bad2f..ab4d4712 100755 --- a/test/T720-user-header.sh +++ b/test/T720-user-header.sh @@ -35,4 +35,25 @@ index.header.spam=X-Spam EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "parse user prefix" +NOTMUCH_DEBUG_QUERY=t notmuch count 'list:"notmuch"' 2>&1 | grep Tmail >OUTPUT +cat < EXPECTED +Query((Tmail AND XU:LISTnotmuch@1)) +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "parse user prefix, stemmed" +NOTMUCH_DEBUG_QUERY=t notmuch count 'list:notmuch' 2>&1 | grep Tmail >OUTPUT +cat < EXPECTED +Query((Tmail AND ZXU:LISTnotmuch@1)) +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "parse user prefix, phrase" +NOTMUCH_DEBUG_QUERY=t notmuch count 'list:notmuchmail.org' 2>&1 | grep Tmail >OUTPUT +cat < EXPECTED +Query((Tmail AND (XU:LISTnotmuchmail@1 PHRASE 2 XU:LISTorg@2))) +EOF +test_expect_equal_file EXPECTED OUTPUT + test_done -- 2.19.1