From: Marco Bettini Date: Mon, 4 Dec 2023 16:10:41 +0000 (+0000) Subject: fts: storage - Use fts_settings for autoindex_exclude X-Git-Tag: 2.4.1~1119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82c80e7734f14acb9cf8146da5f95496bfe2c32a;p=thirdparty%2Fdovecot%2Fcore.git fts: storage - Use fts_settings for autoindex_exclude --- diff --git a/src/lib-storage/Makefile.am b/src/lib-storage/Makefile.am index 6072c9aafb..497629f98e 100644 --- a/src/lib-storage/Makefile.am +++ b/src/lib-storage/Makefile.am @@ -60,7 +60,6 @@ libstorage_la_SOURCES = \ mailbox-list.c \ mailbox-list-notify.c \ mailbox-list-register.c \ - mailbox-match-plugin.c \ mailbox-recent-flags.c \ mailbox-search-result.c \ mailbox-tree.c \ @@ -98,7 +97,6 @@ headers = \ mailbox-list-iter.h \ mailbox-list-private.h \ mailbox-list-notify.h \ - mailbox-match-plugin.h \ mailbox-recent-flags.h \ mailbox-search-result-private.h \ mailbox-tree.h \ diff --git a/src/lib-storage/mailbox-match-plugin.c b/src/lib-storage/mailbox-match-plugin.c deleted file mode 100644 index fc919b154b..0000000000 --- a/src/lib-storage/mailbox-match-plugin.c +++ /dev/null @@ -1,87 +0,0 @@ -/* Copyright (c) 2021 Dovecot authors, see the included COPYING file */ - -#include "lib.h" -#include "array.h" -#include "str.h" -#include "wildcard-match.h" -#include "mail-storage-private.h" -#include "mailbox-match-plugin.h" -#include "mailbox-list-private.h" - -struct mailbox_match_plugin { - ARRAY_TYPE(const_string) patterns; -}; - -struct mailbox_match_plugin * -mailbox_match_plugin_init(struct mail_user *user, const char *set_prefix) -{ - struct mailbox_match_plugin *match; - string_t *str; - const char *value; - - match = i_new(struct mailbox_match_plugin, 1); - - value = mail_user_plugin_getenv(user, set_prefix); - if (value == NULL) - return match; - - i_array_init(&match->patterns, 16); - str = t_str_new(128); - for (unsigned int i = 2; value != NULL; i++) { - /* value points to user's settings, so there's no need to - strdup() it. */ - array_push_back(&match->patterns, &value); - - str_truncate(str, 0); - str_printfa(str, "%s%u", set_prefix, i); - - value = mail_user_plugin_getenv(user, str_c(str)); - } - - return match; -} - -bool mailbox_match_plugin_exclude(struct mailbox_match_plugin *match, - struct mailbox *box) -{ - const struct mailbox_settings *set; - const char *const *special_use; - const char *pattern; - - if (!array_is_created(&match->patterns)) - return FALSE; - - set = mailbox_get_settings(box); - special_use = set == NULL ? NULL : - t_strsplit_spaces(set->special_use, " "); - - array_foreach_elem(&match->patterns, pattern) { - if (pattern[0] == '\\') { - /* \Special-use flag */ - if (special_use != NULL && - str_array_icase_find(special_use, pattern)) - return TRUE; - } else { - if (wildcard_match(box->vname, pattern)) - return TRUE; - - /* for namespaces with inbox=yes, try to match also without prefix */ - if (HAS_ALL_BITS(box->list->ns->flags, NAMESPACE_FLAG_INBOX_USER) && - wildcard_match(box->vname + box->list->ns->prefix_len, pattern)) - return TRUE; - } - } - return FALSE; -} - -void mailbox_match_plugin_deinit(struct mailbox_match_plugin **_match) -{ - struct mailbox_match_plugin *match = *_match; - - if (match == NULL) - return; - *_match = NULL; - - array_free(&match->patterns); - i_free(match); -} diff --git a/src/lib-storage/mailbox-match-plugin.h b/src/lib-storage/mailbox-match-plugin.h deleted file mode 100644 index c6dbfe9c22..0000000000 --- a/src/lib-storage/mailbox-match-plugin.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MAILBOX_MATCH_PLUGIN_H -#define MAILBOX_MATCH_PLUGIN_H - -struct mailbox; - -/* Utility library to allow a Dovecot plugin an easy way to configure a list - of mailbox patterns and special-use flags that can be matched against. */ - -struct mailbox_match_plugin * -mailbox_match_plugin_init(struct mail_user *user, const char *set_prefix); -void mailbox_match_plugin_deinit(struct mailbox_match_plugin **match); - -bool mailbox_match_plugin_exclude(struct mailbox_match_plugin *match, - struct mailbox *box); - -#endif diff --git a/src/plugins/fts/fts-storage.c b/src/plugins/fts/fts-storage.c index 5030d5eec9..cb7b86d599 100644 --- a/src/plugins/fts/fts-storage.c +++ b/src/plugins/fts/fts-storage.c @@ -48,7 +48,6 @@ struct fts_mailbox { union mailbox_module_context module_ctx; const struct fts_settings *set; struct fts_backend_update_context *sync_update_ctx; - bool fts_mailbox_excluded; }; struct fts_transaction_context { @@ -663,15 +662,13 @@ fts_transaction_commit(struct mailbox_transaction_context *t, struct mail_transaction_commit_changes *changes_r) { struct mailbox *box = t->box; - const struct fts_settings *set = fts_user_get_settings(box->storage->user); struct fts_transaction_context *ft = FTS_CONTEXT_REQUIRE(t); struct fts_mailbox *fbox = FTS_CONTEXT_REQUIRE(box); bool autoindex; int ret = 0; const char *error; - autoindex = set->autoindex && ft->mails_saved && - !fbox->fts_mailbox_excluded; + autoindex = fbox->set->autoindex && ft->mails_saved; if (fts_transaction_end(t, &error) < 0) { mail_storage_set_error(t->box->storage, MAIL_ERROR_TEMP, @@ -833,8 +830,6 @@ void fts_mailbox_allocated(struct mailbox *box) v->free = fts_mailbox_free; fbox->set = set; box->vlast = &fbox->module_ctx.super; - fbox->fts_mailbox_excluded = fts_user_autoindex_exclude(box); - v->get_status = fts_mailbox_get_status; v->search_init = fts_mailbox_search_init; v->search_next_nonblock = fts_mailbox_search_next_nonblock; diff --git a/src/plugins/fts/fts-user.c b/src/plugins/fts/fts-user.c index e83f99e62c..48964908a7 100644 --- a/src/plugins/fts/fts-user.c +++ b/src/plugins/fts/fts-user.c @@ -5,7 +5,6 @@ #include "str-parse.h" #include "mail-user.h" #include "mail-storage-private.h" -#include "mailbox-match-plugin.h" #include "language.h" #include "lang-filter.h" #include "lang-tokenizer.h" @@ -26,8 +25,6 @@ struct fts_user { struct language_list *lang_list; struct fts_user_language *data_lang; ARRAY_TYPE(fts_user_language) languages, data_languages; - - struct mailbox_match_plugin *autoindex_exclude; }; static MODULE_CONTEXT_DEFINE_INIT(fts_user_module, @@ -350,13 +347,6 @@ const struct fts_settings *fts_user_get_settings(struct mail_user *user) return fuser->set; } -bool fts_user_autoindex_exclude(struct mailbox *box) -{ - struct fts_user *fuser = FTS_USER_CONTEXT_REQUIRE(box->storage->user); - - return mailbox_match_plugin_exclude(fuser->autoindex_exclude, box); -} - int fts_user_try_get_settings(struct mail_user *user, const struct fts_settings **set_r) { @@ -435,8 +425,6 @@ int fts_mail_user_init(struct mail_user *user, bool initialize_libfts, return -1; } } - fuser->autoindex_exclude = - mailbox_match_plugin_init(user, "fts_autoindex_exclude"); MODULE_CONTEXT_SET(user, fts_user_module, fuser); return 0; diff --git a/src/plugins/fts/fts-user.h b/src/plugins/fts/fts-user.h index 1ba3763a71..6fa4ea0c49 100644 --- a/src/plugins/fts/fts-user.h +++ b/src/plugins/fts/fts-user.h @@ -24,7 +24,6 @@ const struct fts_settings *fts_user_get_settings(struct mail_user *user); int fts_user_try_get_settings(struct mail_user *user, const struct fts_settings **set_r); -bool fts_user_autoindex_exclude(struct mailbox *box); size_t fts_mail_user_message_max_size(struct mail_user *user); int fts_mail_user_init(struct mail_user *user, bool initialize_libfts,