diff --git a/src/doveadm/doveadm-mail-mailbox.c b/src/doveadm/doveadm-mail-mailbox.c index a86fb28810..c8b876a629 100644 --- a/src/doveadm/doveadm-mail-mailbox.c +++ b/src/doveadm/doveadm-mail-mailbox.c @@ -63,7 +63,7 @@ struct path_cmd_context { static const char *mailbox_list_path_type_names[] = { "dir", "alt-dir", "mailbox", "alt-mailbox", - "control", "index", "index-private", "index-cache", "list-index", + "control", "index", "fts-index", "index-private", "index-cache", "list-index", }; static_assert_array_size(mailbox_list_path_type_names, MAILBOX_LIST_PATH_TYPE_COUNT); diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index bd9ca7edd2..41216253d6 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -146,6 +146,7 @@ mbox_list_get_path(struct mailbox_list *list, const char *name, *path_r = t_strconcat(t_strdup_until(path, p), "/"MBOX_INDEX_DIR_NAME"/", p+1, NULL); break; + case MAILBOX_LIST_PATH_TYPE_FTS_INDEX: case MAILBOX_LIST_PATH_TYPE_DIR: case MAILBOX_LIST_PATH_TYPE_ALT_DIR: case MAILBOX_LIST_PATH_TYPE_MAILBOX: diff --git a/src/lib-storage/list/mailbox-list-fs.c b/src/lib-storage/list/mailbox-list-fs.c index 8e4640647e..b4db77c3dc 100644 --- a/src/lib-storage/list/mailbox-list-fs.c +++ b/src/lib-storage/list/mailbox-list-fs.c @@ -130,6 +130,14 @@ fs_list_get_path(struct mailbox_list *_list, const char *name, return 1; } break; + case MAILBOX_LIST_PATH_TYPE_FTS_INDEX: + if (set->fts_index_dir != NULL) { + if (*set->fts_index_dir == '\0') + return 0; + *path_r = fs_list_get_path_to(set, set->fts_index_dir, name); + return 1; + } + break; case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE: if (set->index_pvt_dir == NULL) return 0; diff --git a/src/lib-storage/list/mailbox-list-maildir.c b/src/lib-storage/list/mailbox-list-maildir.c index 7e5808e1e3..7eea592c31 100644 --- a/src/lib-storage/list/mailbox-list-maildir.c +++ b/src/lib-storage/list/mailbox-list-maildir.c @@ -152,6 +152,15 @@ maildir_list_get_path(struct mailbox_list *_list, const char *name, return 1; } break; + case MAILBOX_LIST_PATH_TYPE_FTS_INDEX: + if (_list->set.fts_index_dir != NULL) { + if (*_list->set.fts_index_dir == '\0') + return 0; + *path_r = maildir_list_get_dirname_path(_list, + _list->set.fts_index_dir, name); + return 1; + } + break; case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE: if (_list->set.index_pvt_dir == NULL) return 0; diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index d8bc614cf6..a86adac116 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -856,6 +856,8 @@ int mailbox_mark_index_deleted(struct mailbox *box, bool del); const char *mailbox_get_path(struct mailbox *box) ATTR_PURE; /* Similar to mailbox_get_path() but for MAILBOX_LIST_PATH_TYPE_INDEX. */ const char *mailbox_get_index_path(struct mailbox *box) ATTR_PURE; +/* Check if mailbox path for type exists. */ +int mailbox_path_exists(struct mailbox *box, enum mailbox_list_path_type type); /* Wrapper to mailbox_list_get_path() */ int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type, const char **path_r); diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 05ce59d48f..93432048d9 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -3008,6 +3008,15 @@ const char *mailbox_get_index_path(struct mailbox *box) return box->_index_path; } +int mailbox_path_exists(struct mailbox *box, enum mailbox_list_path_type type) +{ + const char *path; + if (get_path_to(box, type, NULL, &path) < 0) + return 0; + + return 1; +} + static void mailbox_get_permissions_if_not_set(struct mailbox *box) { if (box->_perm.file_create_mode != 0) diff --git a/src/lib-storage/mailbox-list.c b/src/lib-storage/mailbox-list.c index 8a3e95eccf..ce5bc7a345 100644 --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -125,7 +125,7 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns, } if ((class->props & MAILBOX_LIST_PROP_NO_MAILDIR_NAME) != 0 && - *set->maildir_name != '\0') { + *set->maildir_name != '\0') { *error_r = "maildir_name not supported by this driver"; return -1; } @@ -210,10 +210,11 @@ int mailbox_list_create(const char *driver, struct mail_namespace *ns, } e_debug(ns->user->event, - "%s: root=%s, index=%s, indexpvt=%s, control=%s, inbox=%s, alt=%s", + "%s: root=%s, index=%s, fts_index=%s, indexpvt=%s, control=%s, inbox=%s, alt=%s", list->name, list->set.root_dir == NULL ? "" : list->set.root_dir, list->set.index_dir == NULL ? "" : list->set.index_dir, + list->set.fts_index_dir == NULL ? "" : list->set.fts_index_dir, list->set.index_pvt_dir == NULL ? "" : list->set.index_pvt_dir, list->set.control_dir == NULL ? "" : list->set.control_dir, @@ -333,6 +334,8 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data, dest = &set_r->inbox_path; else if (strcmp(key, "INDEX") == 0) dest = &set_r->index_dir; + else if (strcmp(key, "FTS_INDEX") == 0) + dest = &set_r->fts_index_dir; else if (strcmp(key, "INDEXPVT") == 0) dest = &set_r->index_pvt_dir; else if (strcmp(key, "INDEXCACHE") == 0) @@ -1485,6 +1488,22 @@ bool mailbox_list_set_get_root_path(const struct mailbox_list_settings *set, path = set->root_dir; } break; + case MAILBOX_LIST_PATH_TYPE_FTS_INDEX: + if (set->fts_index_dir != NULL) { + if (set->fts_index_dir[0] == '\0') { + /* in-memory indexes */ + return 0; + } + path = set->fts_index_dir; + + /* Preserve the old behavior of using the index directory if + * fts_index_dir is not set. */ + } else if (set->index_dir != NULL) { + path = set->index_dir; + } else { + path = set->root_dir; + } + break; case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE: path = set->index_pvt_dir; break; diff --git a/src/lib-storage/mailbox-list.h b/src/lib-storage/mailbox-list.h index 27e8f4655b..8d027bd040 100644 --- a/src/lib-storage/mailbox-list.h +++ b/src/lib-storage/mailbox-list.h @@ -95,6 +95,8 @@ enum mailbox_list_path_type { /* Return mailbox list index directory (usually same as MAILBOX_LIST_PATH_TYPE_INDEX) */ MAILBOX_LIST_PATH_TYPE_LIST_INDEX, + /* Return mailbox fts index directory path */ + MAILBOX_LIST_PATH_TYPE_FTS_INDEX, MAILBOX_LIST_PATH_TYPE_COUNT }; @@ -115,6 +117,7 @@ struct mailbox_list_settings { const char *layout; /* FIXME: shouldn't be here */ const char *root_dir; const char *index_dir; + const char *fts_index_dir; const char *index_pvt_dir; const char *index_cache_dir; const char *control_dir; diff --git a/src/plugins/fts-flatcurve/fts-backend-flatcurve.c b/src/plugins/fts-flatcurve/fts-backend-flatcurve.c index 76d2871a5b..fbbfd572e7 100644 --- a/src/plugins/fts-flatcurve/fts-backend-flatcurve.c +++ b/src/plugins/fts-flatcurve/fts-backend-flatcurve.c @@ -125,14 +125,22 @@ fts_backend_flatcurve_set_mailbox(struct flatcurve_fts_backend *backend, return -1; } - if (mailbox_open(box) < 0 || - mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path) <= 0) { + if (mailbox_open(box) < 0 + || (mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_INDEX) == 0 && + mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX) == 0) + ) { *error_r = t_strdup_printf("Could not open mailbox: %s: %s", - box->vname, - mailbox_get_last_internal_error(box, NULL)); + box->vname, + mailbox_get_last_internal_error(box, NULL)); return -1; } + if (mailbox_path_exists(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX)) { + mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_FTS_INDEX, &path); + } else { + mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path); + } + str_append(backend->boxname, box->vname); str_printfa(backend->db_path, "%s/%s/", path, FTS_FLATCURVE_LABEL); diff --git a/src/plugins/fts/fts-storage.c b/src/plugins/fts/fts-storage.c index cf84b9042b..5095123000 100644 --- a/src/plugins/fts/fts-storage.c +++ b/src/plugins/fts/fts-storage.c @@ -959,7 +959,9 @@ fts_mailbox_list_created(struct mailbox_list *list) return; } - if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_INDEX, &path)) { + /* TODO: Create config item for MAILBOX_LIST_PATH_TYPE... FTS_INDEX||=INDEX */ + bool has_fts_index_path = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_FTS_INDEX, &path); + if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_INDEX, &path) && !has_fts_index_path) { e_debug(list->ns->user->event, "fts: Indexes disabled for namespace '%s'", list->ns->prefix);