]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Replace INBOX parameter with mail_inbox_path setting
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 30 Oct 2023 20:34:44 +0000 (22:34 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:11 +0000 (12:34 +0200)
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.

src/lib-storage/index/maildir/maildir-settings.c
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/mbox/mbox-settings.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/mailbox-list-maildir.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-list.c
src/lib-storage/mailbox-list.h

index 80a0dd206e5ed286a2d0c0846078aa77983774c9..37e42aeb568804150ce378a46017303fd7781362 100644 (file)
@@ -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 }
 };
 
index f2f8635859b2556f4c2df55e7e95a95256a4f9be..16af6f204b953ce431dcd6b2a3d1dd92ecf14597 100644 (file)
@@ -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,
index 6f746b6c83065e05e6c4e1019b4f8e5cd5bd0905..d02b663c9035262a0bd637185f90c495561cfccb 100644 (file)
@@ -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 }
 };
 
index f3afc45842b0410c65bb2d860b92e58daebe56d7..3c02cff7c796f885139402e0fd7a54e6df6c2dfd 100644 (file)
@@ -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,
index 70db5d0038c010f804496a0d0dfc32467e183f1e..cc6d6dd288778582f297dac500097ddb3794558a 100644 (file)
@@ -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;
                }
        }
index 2f12a4d5004f1783d28e1fe0dba48b8af51cf2d6..bdaebcc3276d3a4c645088d047872c0dc59430f8 100644 (file)
@@ -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;
        }
 
index 30c5b9b6b7cf25a720c871841a91537d6530cab3..d550535bd0d2c45a0abde268efb98ca1dc6f80c4 100644 (file)
@@ -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),
index bf2f8e07320eb27ef481e43a6b46c98fc451adc8..83289566d90e98afda9b71383046928fb94b7950 100644 (file)
@@ -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;
index 1965e53fe6bf2b78a547c6b04a5b31ed015b8d91..3237167695f2b39c37c4c990a4f3a6160db6f75c 100644 (file)
@@ -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)
index f303b85cc9e97316a50c47bc4f9958020e3e3995..78c9c3d4c34a57df4cca84cea1e9e24161877f25 100644 (file)
@@ -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;
 }
index 03568fd0783c55f0f8e14db03321d35c5bda9f9d..51eaa8b199c43429d6e7163c94c0a9958234f19b 100644 (file)
@@ -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 {