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 098F86DE0F72 for ; Sat, 2 Mar 2019 07:41:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.008 X-Spam-Level: X-Spam-Status: No, score=-0.008 tagged_above=-999 required=5 tests=[AWL=-0.007, 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 n_nuL5XnoHEa for ; Sat, 2 Mar 2019 07:41:42 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id CF6876DE0F96 for ; Sat, 2 Mar 2019 07:41:41 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1h06lg-0004IY-8s; Sat, 02 Mar 2019 10:41:40 -0500 Received: (nullmailer pid 25731 invoked by uid 1000); Sat, 02 Mar 2019 15:41:37 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 5/7] lib: support user prefix names in term generation Date: Sat, 2 Mar 2019 11:41:31 -0400 Message-Id: <20190302154133.25642-6-david@tethera.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190302154133.25642-1-david@tethera.net> References: <20190302154133.25642-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, 02 Mar 2019 15:41:43 -0000 This should not change the indexing process yet as nothing calls _notmuch_message_gen_terms with a user prefix name. On the other hand, it should not break anything either. --- lib/database.cc | 20 ++++++++++++++++++++ lib/message.cc | 5 ++++- lib/notmuch-private.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/database.cc b/lib/database.cc index 6caa1311..19aff0e8 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -405,6 +405,26 @@ _find_prefix (const char *name) return ""; } +/* Like find prefix, but include the possibility of user defined + * prefixes specific to this database */ + +const char * +_notmuch_database_prefix (notmuch_database_t *notmuch, const char *name) +{ + unsigned int i; + + /*XXX TODO: reduce code duplication */ + for (i = 0; i < ARRAY_SIZE (prefix_table); i++) { + if (strcmp (name, prefix_table[i].name) == 0) + return prefix_table[i].prefix; + } + + if (notmuch->user_prefix) + return _notmuch_string_map_get (notmuch->user_prefix, name); + + return NULL; +} + static const struct { /* NOTMUCH_FEATURE_* value. */ _notmuch_features value; diff --git a/lib/message.cc b/lib/message.cc index 6f2f6345..bbc5ef99 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1434,7 +1434,10 @@ _notmuch_message_gen_terms (notmuch_message_t *message, term_gen->set_document (message->doc); if (prefix_name) { - const char *prefix = _find_prefix (prefix_name); + const char *prefix = _notmuch_database_prefix (message->notmuch, prefix_name); + + if (prefix == NULL) + return NOTMUCH_PRIVATE_STATUS_BAD_PREFIX; term_gen->set_termpos (message->termpos); term_gen->index_text (text, 1, prefix); diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 1ef26e37..cf08411e 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -136,6 +136,7 @@ typedef enum _notmuch_private_status { /* Then add our own private values. */ NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG = NOTMUCH_STATUS_LAST_STATUS, NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND, + NOTMUCH_PRIVATE_STATUS_BAD_PREFIX, NOTMUCH_PRIVATE_STATUS_LAST_STATUS } notmuch_private_status_t; -- 2.20.1