From: Timo Sirainen Date: Mon, 30 Oct 2023 20:34:44 +0000 (+0200) Subject: lib-storage: Replace INBOX parameter with mail_inbox_path setting X-Git-Tag: 2.4.1~1225 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cd22bf91a49c9eef431931be0b791251235fc29f;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Replace INBOX parameter with mail_inbox_path setting This commit changes the Maildir INBOX default path when namespace_inbox=no. Now the behavior is the same as with namespace_inbox=yes, i.e. INBOX is created for Maildir/ root directory instead of Maildir/.INBOX/. Preserving the original behavior would have been rather complex, and it likely doesn't matter much, since INBOX isn't normally created for non-inbox namespaces anyway. The original behavior can still be preserved by explicitly setting mail_inbox_path= (to empty value) for the namespace_inbox=no namespaces. --- diff --git a/src/lib-storage/index/maildir/maildir-settings.c b/src/lib-storage/index/maildir/maildir-settings.c index 80a0dd206e..37e42aeb56 100644 --- a/src/lib-storage/index/maildir/maildir-settings.c +++ b/src/lib-storage/index/maildir/maildir-settings.c @@ -28,6 +28,9 @@ static const struct maildir_settings maildir_default_settings = { static const struct setting_keyvalue maildir_default_filter_settings_keyvalue[] = { { "maildir/mailbox_list_layout", "maildir++" }, + /* Use Maildir/ root as the INBOX, not Maildir/.INBOX/ */ + { "maildir/layout_maildir++/mail_inbox_path", "." }, + { "maildir/layout_fs/mail_inbox_path", "." }, { NULL, NULL } }; diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index f2f8635859..16af6f204b 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -64,7 +64,7 @@ maildir_storage_create(struct mail_storage *_storage, struct mail_namespace *ns, mailbox_list_get_temp_prefix(list)); if (list->mail_set->mail_control_path[0] == '\0' && - list->set.inbox_path == NULL && + list->mail_set->mail_inbox_path[0] == '\0' && (ns->flags & NAMESPACE_FLAG_INBOX_ANY) != 0) { /* put the temp files into tmp/ directory preferably */ storage->temp_prefix = p_strconcat(_storage->pool, "tmp/", @@ -87,21 +87,6 @@ static void maildir_storage_destroy(struct mail_storage *_storage) index_storage_destroy(_storage); } -static void -maildir_storage_get_list_settings(const struct mail_namespace *ns, - struct mailbox_list_settings *set, - const struct mail_storage_settings *mail_set) -{ - if (set->inbox_path == NULL && - mail_set->mailbox_directory_name[0] == '\0' && - (strcmp(mail_set->mailbox_list_layout, MAILBOX_LIST_NAME_MAILDIRPLUSPLUS) == 0 || - strcmp(mail_set->mailbox_list_layout, MAILBOX_LIST_NAME_FS) == 0) && - (ns->flags & NAMESPACE_FLAG_INBOX_ANY) != 0) { - /* Maildir++ INBOX is the Maildir base itself */ - set->inbox_path = set->root_dir; - } -} - static const char * maildir_storage_find_root_dir(const struct mail_namespace *ns) { @@ -741,7 +726,7 @@ struct mail_storage maildir_storage = { maildir_storage_create, maildir_storage_destroy, maildir_storage_add_list, - maildir_storage_get_list_settings, + NULL, maildir_storage_autodetect, maildir_mailbox_alloc, NULL, diff --git a/src/lib-storage/index/mbox/mbox-settings.c b/src/lib-storage/index/mbox/mbox-settings.c index 6f746b6c83..d02b663c90 100644 --- a/src/lib-storage/index/mbox/mbox-settings.c +++ b/src/lib-storage/index/mbox/mbox-settings.c @@ -38,6 +38,8 @@ static const struct mbox_settings mbox_default_settings = { static const struct setting_keyvalue mbox_default_filter_settings_keyvalue[] = { { "mbox/mailbox_subscriptions_filename", ".subscriptions" }, + /* Use $mail_path/inbox as the INBOX, not $mail_path/INBOX */ + { "mbox/layout_fs/mail_inbox_path", "inbox" }, { NULL, NULL } }; diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index f3afc45842..3c02cff7c7 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -210,20 +210,6 @@ static void mbox_storage_destroy(struct mail_storage *_storage) index_storage_destroy(_storage); } -static void -mbox_storage_get_list_settings(const struct mail_namespace *ns, - struct mailbox_list_settings *set, - const struct mail_storage_settings *mail_set) -{ - struct event *event = ns->user->event; - - if (set->inbox_path == NULL && - strcasecmp(mail_set->mailbox_list_layout, MAILBOX_LIST_NAME_FS) == 0) { - set->inbox_path = t_strconcat(set->root_dir, "/inbox", NULL); - e_debug(event, "mbox: INBOX defaulted to %s", set->inbox_path); - } -} - static bool mbox_is_file(const char *path, const char *name, struct event *event) { struct stat st; @@ -329,14 +315,14 @@ mbox_storage_find_inbox_file(struct mail_user *user, struct event *event) static bool mbox_storage_autodetect(const struct mail_namespace *ns, struct mailbox_list_settings *set, - const struct mail_storage_settings *mail_set ATTR_UNUSED, + const struct mail_storage_settings *mail_set, const char **root_path_r, const char **inbox_path_r) { struct event *event = ns->user->event; const char *root_dir, *inbox_path; root_dir = set->root_dir; - inbox_path = set->inbox_path; + inbox_path = mail_set->mail_inbox_path; if (root_dir != NULL) { if (inbox_path == NULL && @@ -836,7 +822,7 @@ struct mail_storage mbox_storage = { mbox_storage_create, mbox_storage_destroy, mbox_storage_add_list, - mbox_storage_get_list_settings, + NULL, mbox_storage_autodetect, mbox_mailbox_alloc, NULL, diff --git a/src/lib-storage/list/mailbox-list-fs.c b/src/lib-storage/list/mailbox-list-fs.c index 70db5d0038..cc6d6dd288 100644 --- a/src/lib-storage/list/mailbox-list-fs.c +++ b/src/lib-storage/list/mailbox-list-fs.c @@ -156,13 +156,14 @@ fs_list_get_path(struct mailbox_list *_list, const char *name, if (type == MAILBOX_LIST_PATH_TYPE_ALT_DIR || type == MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX) { /* don't use inbox_path */ - } else if (strcmp(name, "INBOX") == 0 && set->inbox_path != NULL) { + } else if (strcmp(name, "INBOX") == 0 && + mail_set->mail_inbox_path[0] != '\0') { /* If INBOX is a file, index and control directories are located in root directory. */ if ((_list->flags & MAILBOX_LIST_FLAG_MAILBOX_FILES) == 0 || type == MAILBOX_LIST_PATH_TYPE_MAILBOX || type == MAILBOX_LIST_PATH_TYPE_DIR) { - *path_r = set->inbox_path; + *path_r = mail_set->mail_inbox_path; return 1; } } diff --git a/src/lib-storage/list/mailbox-list-maildir.c b/src/lib-storage/list/mailbox-list-maildir.c index 2f12a4d500..bdaebcc327 100644 --- a/src/lib-storage/list/mailbox-list-maildir.c +++ b/src/lib-storage/list/mailbox-list-maildir.c @@ -167,8 +167,9 @@ maildir_list_get_path(struct mailbox_list *_list, const char *name, if (type == MAILBOX_LIST_PATH_TYPE_ALT_DIR || type == MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX) { /* don't use inbox_path */ - } else if (strcmp(name, "INBOX") == 0 && _list->set.inbox_path != NULL) { - *path_r = _list->set.inbox_path; + } else if (strcmp(name, "INBOX") == 0 && + _list->mail_set->mail_inbox_path[0] != '\0') { + *path_r = _list->mail_set->mail_inbox_path; return 1; } diff --git a/src/lib-storage/mail-storage-settings.c b/src/lib-storage/mail-storage-settings.c index 30c5b9b6b7..d550535bd0 100644 --- a/src/lib-storage/mail-storage-settings.c +++ b/src/lib-storage/mail-storage-settings.c @@ -92,6 +92,7 @@ static const struct setting_define mail_storage_setting_defines[] = { DEF(BOOL, mailbox_directory_name_legacy), DEF(STR_HIDDEN, mailbox_root_directory_name), DEF(STR_HIDDEN, mailbox_subscriptions_filename), + DEF(STR, mail_inbox_path), DEF(STR, mail_index_path), DEF(STR, mail_index_private_path), DEF(STR_HIDDEN, mail_cache_path), @@ -171,6 +172,7 @@ const struct mail_storage_settings mail_storage_default_settings = { .mailbox_directory_name_legacy = TRUE, .mailbox_root_directory_name = "", .mailbox_subscriptions_filename = "subscriptions", + .mail_inbox_path = "", .mail_index_path = "", .mail_index_private_path = "", .mail_cache_path = "", @@ -800,6 +802,20 @@ mail_storage_settings_ext_check(struct event *event, void *_set, pool_t pool, return FALSE; } + const char *mail_path = strchr(set->mail_location, ':'); + if (mail_path != NULL) + mail_path = t_strcut(mail_path + 1, ':'); + if (mail_path != NULL && + set->mail_inbox_path[0] != '\0' && set->mail_inbox_path[0] != '/') { + /* Convert to absolute path */ + if (strcmp(set->mail_inbox_path, ".") == 0) + set->mail_inbox_path = mail_path; + else { + set->mail_inbox_path = p_strdup_printf(pool, "%s/%s", + mail_path, set->mail_inbox_path); + } + } + if (!mail_storage_settings_check_namespaces(event, set, error_r)) return FALSE; return TRUE; @@ -1054,6 +1070,7 @@ static const size_t mail_storage_2nd_reset_offsets[] = { OFFSET(mailbox_directory_name_legacy), OFFSET(mailbox_root_directory_name), OFFSET(mailbox_subscriptions_filename), + OFFSET(mail_inbox_path), OFFSET(mail_index_path), OFFSET(mail_index_private_path), OFFSET(mail_cache_path), diff --git a/src/lib-storage/mail-storage-settings.h b/src/lib-storage/mail-storage-settings.h index bf2f8e0732..83289566d9 100644 --- a/src/lib-storage/mail-storage-settings.h +++ b/src/lib-storage/mail-storage-settings.h @@ -71,6 +71,7 @@ struct mail_storage_settings { bool mailbox_directory_name_legacy; const char *mailbox_root_directory_name; const char *mailbox_subscriptions_filename; + const char *mail_inbox_path; const char *mail_index_path; const char *mail_index_private_path; const char *mail_cache_path; diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 1965e53fe6..3237167695 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -141,7 +141,8 @@ struct mail_storage *mail_storage_find_class(const char *name) static struct mail_storage * mail_storage_autodetect(const struct mail_namespace *ns, struct mailbox_list_settings *set, - const struct mail_storage_settings *mail_set) + const struct mail_storage_settings *mail_set, + const char **inbox_path_override) { struct mail_storage *const *classes; const char *root_path, *inbox_path = NULL; @@ -153,8 +154,7 @@ mail_storage_autodetect(const struct mail_namespace *ns, if (classes[i]->v.autodetect(ns, set, mail_set, &root_path, &inbox_path)) { set->root_dir = root_path; - if (inbox_path != NULL) - set->inbox_path = inbox_path; + *inbox_path_override = inbox_path; return classes[i]; } } @@ -182,7 +182,8 @@ static struct mail_storage * mail_storage_get_class(struct mail_namespace *ns, const char *driver, const struct mail_storage_settings *mail_set, struct mailbox_list_settings *list_set, - enum mail_storage_flags flags, const char **error_r) + enum mail_storage_flags flags, + const char **inbox_path_override, const char **error_r) { struct mail_storage *storage_class = NULL; const char *home; @@ -229,7 +230,8 @@ mail_storage_get_class(struct mail_namespace *ns, const char *driver, if (storage_class != NULL) return storage_class; - storage_class = mail_storage_autodetect(ns, list_set, mail_set); + storage_class = mail_storage_autodetect(ns, list_set, mail_set, + inbox_path_override); if (storage_class != NULL) return storage_class; @@ -374,6 +376,7 @@ mail_storage_create_list(struct mail_namespace *ns, struct event *set_event, enum mail_storage_flags flags, struct mailbox_list_settings *list_set, + const char *inbox_path_override, const char **error_r) { enum mailbox_list_flags list_flags = 0; @@ -416,6 +419,13 @@ mail_storage_create_list(struct mail_namespace *ns, event_set_ptr(set_event, SETTINGS_EVENT_FILTER_NAME, layout_filter); settings_free(mail_set); + if (inbox_path_override != NULL) { + mail_storage_create_ns_instance(ns, set_event); + settings_override(ns->_set_instance, "*/mail_inbox_path", + inbox_path_override, + SETTINGS_OVERRIDE_TYPE_CODE); + } + if (settings_get(set_event, &mail_storage_setting_parser_info, 0, &mail_set, error_r) < 0) { event_unref(&set_event); @@ -447,6 +457,7 @@ mail_storage_create_real(struct mail_namespace *ns, struct event *set_event, const struct mail_storage_settings *mail_set; struct mailbox_list_settings list_set; const char *p, *data, *driver = NULL; + const char *inbox_path_override = NULL; /* Lookup initial mailbox list settings. Once they're found, another settings lookup is done with mailbox format as an additional @@ -471,7 +482,8 @@ mail_storage_create_real(struct mail_namespace *ns, struct event *set_event, } storage_class = mail_storage_get_class(ns, driver, mail_set, &list_set, - flags, error_r); + flags, &inbox_path_override, + error_r); settings_free(mail_set); if (storage_class == NULL) return -1; @@ -479,7 +491,8 @@ mail_storage_create_real(struct mail_namespace *ns, struct event *set_event, if (ns->list == NULL) { /* first storage for namespace */ if (mail_storage_create_list(ns, storage_class, set_event, - flags, &list_set, error_r) < 0) + flags, &list_set, + inbox_path_override, error_r) < 0) return -1; if ((storage_class->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) == 0) { if (mail_storage_create_root(ns->list, flags, error_r) < 0) diff --git a/src/lib-storage/mailbox-list.c b/src/lib-storage/mailbox-list.c index f303b85cc9..78c9c3d4c3 100644 --- a/src/lib-storage/mailbox-list.c +++ b/src/lib-storage/mailbox-list.c @@ -152,8 +152,6 @@ int mailbox_list_create(struct event *event, struct mail_namespace *ns, if (set->root_dir != NULL) list->set.root_dir = p_strdup(list->pool, set->root_dir); - list->set.inbox_path = p_strdup(list->pool, set->inbox_path); - if (list->v.init != NULL) { if (list->v.init(list, error_r) < 0) { list->v.deinit(list); @@ -173,8 +171,7 @@ int mailbox_list_create(struct event *event, struct mail_namespace *ns, mail_set->mail_index_path, mail_set->mail_index_private_path, mail_set->mail_control_path, - list->set.inbox_path == NULL ? - "" : list->set.inbox_path, + mail_set->mail_inbox_path, mail_set->mail_alt_path); if ((flags & MAILBOX_LIST_FLAG_SECONDARY) == 0) mail_namespace_finish_list_init(ns, list); @@ -235,7 +232,7 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data, struct mailbox_list_settings *set_r, const char **error_r) { - const char *const *tmp, *key, *value, **dest, *str, *error; + const char *const *tmp, *key, *value, *str, *error; *error_r = NULL; @@ -269,16 +266,8 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data, value++; } - if (strcmp(key, "INBOX") == 0) - dest = &set_r->inbox_path; - else { - *error_r = t_strdup_printf("Unknown setting: %s", key); - return -1; - } - if (fix_path(user, value, expand_home, dest, &error) < 0) { - *error_r = t_strconcat(error, key, " in: ", data, NULL); - return -1; - } + *error_r = t_strdup_printf("Unknown setting: %s", key); + return -1; } return 0; } diff --git a/src/lib-storage/mailbox-list.h b/src/lib-storage/mailbox-list.h index 03568fd078..51eaa8b199 100644 --- a/src/lib-storage/mailbox-list.h +++ b/src/lib-storage/mailbox-list.h @@ -115,8 +115,6 @@ enum mailbox_list_get_storage_flags { struct mailbox_list_settings { const char *root_dir; - - const char *inbox_path; }; struct mailbox_permissions {