bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2006-2018 Dovecot authors, see the included COPYING file */
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainenconst char *fts_lucene_plugin_version = DOVECOT_ABI_VERSION;
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainenstruct fts_lucene_user_module fts_lucene_user_module =
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen MODULE_CONTEXT_INIT(&mail_user_module_register);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainenfts_lucene_plugin_init_settings(struct mail_user *user,
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen const char *str)
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen for (tmp = t_strsplit_spaces(str, " "); *tmp != NULL; tmp++) {
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainen if (strncmp(*tmp, "default_language=", 17) == 0) {
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainen } else if (strncmp(*tmp, "textcat_conf=", 13) == 0) {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen set->textcat_conf = p_strdup(user->pool, *tmp + 13);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen } else if (strncmp(*tmp, "textcat_dir=", 12) == 0) {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen set->textcat_dir = p_strdup(user->pool, *tmp + 12);
2e5d624013c30633e8ded148d338ce46c321a995Timo Sirainen } else if (strncmp(*tmp, "whitespace_chars=", 17) == 0) {
2e5d624013c30633e8ded148d338ce46c321a995Timo Sirainen set->whitespace_chars = p_strdup(user->pool, *tmp + 17);
f26ef7a3a562dc42a1e9a4dde546bd30df3241e8Timo Sirainen } else if (strcmp(*tmp, "no_snowball") == 0) {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen i_error("fts_lucene: Invalid setting: %s", *tmp);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen if (set->textcat_conf != NULL && set->textcat_dir == NULL) {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen i_error("fts_lucene: textcat_conf set, but textcat_dir unset");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen if (set->textcat_conf == NULL && set->textcat_dir != NULL) {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen i_error("fts_lucene: textcat_dir set, but textcat_conf unset");
c37098f8ce6d512ba41f09564d04ed25720f0a77Timo Sirainen "but Dovecot built without stemmer support");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen "but Dovecot built without textcat support");
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainenuint32_t fts_lucene_settings_checksum(const struct fts_lucene_settings *set)
bfcca12a441275b7f4cd510b95669b163263b2e7Timo Sirainen /* checksum is always different when compiling with/without stemmer */
2e5d624013c30633e8ded148d338ce46c321a995Timo Sirainen crc = crc32_str_more(crc, set->whitespace_chars);
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen /* don't include mime_parts here, since changing it doesn't
57b523eeb99ed5d7f5002907a409cdef54353ce5Timo Sirainen necessarily need the index to be rebuilt */
eeb03434472130f9631f164440566fd8d09e6380Timo Sirainenstatic void fts_lucene_mail_user_deinit(struct mail_user *user)
a220c655b1a3d923713afe8b83641c1050b44dbaAki Tuomi struct fts_lucene_user *fuser = FTS_LUCENE_USER_CONTEXT_REQUIRE(user);
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainenstatic void fts_lucene_mail_user_created(struct mail_user *user)
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen fuser = p_new(user->pool, struct fts_lucene_user, 1);
5b6470e0e2ef4012430cdeca7d9b89c1278a0ed4Timo Sirainen env = mail_user_plugin_getenv(user, "fts_lucene");
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen if (fts_lucene_plugin_init_settings(user, &fuser->set, env) < 0) {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen /* invalid settings, disabling */
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen MODULE_CONTEXT_SET(user, fts_lucene_user_module, fuser);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainenstatic struct mail_storage_hooks fts_lucene_mail_storage_hooks = {
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen .mail_user_created = fts_lucene_mail_user_created
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainenvoid fts_lucene_plugin_init(struct module *module ATTR_UNUSED)
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen mail_storage_hooks_add(module, &fts_lucene_mail_storage_hooks);
57f4445a46726a17bfe78b0964dd301a6ccb40ecTimo Sirainen fts_backend_unregister(fts_backend_lucene.name);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainen mail_storage_hooks_remove(&fts_lucene_mail_storage_hooks);
c8296ac1ed68ed5c5168de545b76f9b27fc76d35Timo Sirainenconst char *fts_lucene_plugin_dependencies[] = { "fts", NULL };