]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Don't use separate indexes/ directory anymore. Fixes/cleanups to make it possible.
authorTimo Sirainen <tss@iki.fi>
Fri, 4 Nov 2011 19:20:19 +0000 (21:20 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 4 Nov 2011 19:20:19 +0000 (21:20 +0200)
src/lib-storage/index/imapc/imapc-list.c
src/lib-storage/index/imapc/imapc-storage.c
src/lib-storage/index/imapc/imapc-storage.h
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/mailbox-list-maildir.c
src/lib-storage/mailbox-list.c
src/lib-storage/mailbox-list.h

index cab878648f15e724e3250744afa56e33c31e7ab5..fc2968fe3e87f11a36677594320f550afb73ab02 100644 (file)
@@ -205,16 +205,11 @@ static struct mailbox_list *imapc_list_get_fs(struct imapc_mailbox_list *list)
        } else if (list->index_list == NULL && !list->index_list_failed) {
                memset(&list_set, 0, sizeof(list_set));
                list_set.layout = MAILBOX_LIST_NAME_MAILDIRPLUSPLUS;
-               /* the root dir shouldn't actually ever be used. we just need
-                  it to be different from index_dir so the index directories
-                  get autocreated */
                list_set.root_dir = dir;
-               list_set.index_dir = t_strconcat(dir, "/indexes", NULL);
-               list_set.escape_char = '%';
+               list_set.escape_char = IMAPC_LIST_ESCAPE_CHAR;
 
                if (mailbox_list_create(list_set.layout, list->list.ns,
-                                       &list_set, MAILBOX_LIST_FLAG_SECONDARY |
-                                       MAILBOX_LIST_FLAG_OPTIONAL_BOXES,
+                                       &list_set, MAILBOX_LIST_FLAG_SECONDARY,
                                        &list->index_list, &error) < 0) {
                        i_error("imapc: Couldn't create %s mailbox list: %s",
                                list_set.layout, error);
@@ -589,16 +584,18 @@ int imapc_list_get_mailbox_flags(struct mailbox_list *_list, const char *name,
        i_assert(list->sep != '\0');
 
        vname = mailbox_list_default_get_vname(_list, name);
-       node = mailbox_tree_lookup(list->mailboxes, vname);
-       if (node != NULL)
-               node->flags |= MAILBOX_NONEXISTENT;
-
-       /* refresh the mailbox flags */
-       cmd = imapc_list_simple_context_init(&sctx, list);
-       imapc_command_sendf(cmd, "LIST \"\" %s", name);
-       imapc_simple_run(&sctx);
-       if (sctx.ret < 0)
-               return -1;
+       if (!list->refreshed_mailboxes) {
+               node = mailbox_tree_lookup(list->mailboxes, vname);
+               if (node != NULL)
+                       node->flags |= MAILBOX_NONEXISTENT;
+
+               /* refresh the mailbox flags */
+               cmd = imapc_list_simple_context_init(&sctx, list);
+               imapc_command_sendf(cmd, "LIST \"\" %s", name);
+               imapc_simple_run(&sctx);
+               if (sctx.ret < 0)
+                       return -1;
+       }
 
        node = mailbox_tree_lookup(list->mailboxes, vname);
        if (node == NULL)
@@ -610,7 +607,7 @@ int imapc_list_get_mailbox_flags(struct mailbox_list *_list, const char *name,
 
 struct mailbox_list imapc_mailbox_list = {
        .name = MAILBOX_LIST_NAME_IMAPC,
-       .props = MAILBOX_LIST_PROP_NO_ROOT,
+       .props = MAILBOX_LIST_PROP_NO_ROOT | MAILBOX_LIST_PROP_AUTOCREATE_DIRS,
        .mailbox_name_max_length = MAILBOX_LIST_NAME_MAX_LENGTH,
 
        {
index daaf98b2b3626df8b94c05c76d35b22c773131e5..3939427eee49c9c680df70980a7fcff48a6dbce3 100644 (file)
@@ -288,6 +288,7 @@ imapc_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
                                struct mailbox_list_settings *set)
 {
        set->layout = MAILBOX_LIST_NAME_IMAPC;
+       set->escape_char = IMAPC_LIST_ESCAPE_CHAR;
 }
 
 static struct mailbox *
index 7046cb25453d3d393e20ed19e341b09925be8263..5f3dea7feca2876974e04d6ddb5ba1d089202011 100644 (file)
@@ -5,6 +5,7 @@
 
 #define IMAPC_STORAGE_NAME "imapc"
 #define IMAPC_INDEX_PREFIX "dovecot.index"
+#define IMAPC_LIST_ESCAPE_CHAR '%'
 
 struct imap_arg;
 struct imapc_untagged_reply;
index d52d0a7a42ef903b2f2b825af9c3a85f5afa9eee..802e65336b0976455e37bc3a5c06f39c8b24dec0 100644 (file)
@@ -361,7 +361,7 @@ static int fs_list_delete_mailbox(struct mailbox_list *list, const char *name)
                ret = fs_list_delete_maildir(list, name);
        }
 
-       if (ret == 0 || (list->flags & MAILBOX_LIST_FLAG_OPTIONAL_BOXES) != 0)
+       if (ret == 0 || (list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) != 0)
                mailbox_list_delete_finish(list, name);
        return ret;
 }
index 2da8e26a66d2102d18c762547e1f386289853abf..9b9a0f0ee48e06f2f869a417539e7d360c82a982 100644 (file)
@@ -410,7 +410,7 @@ maildir_list_delete_mailbox(struct mailbox_list *list, const char *name)
                ret = maildir_list_delete_maildir(list, name);
        }
 
-       if (ret == 0 || (list->flags & MAILBOX_LIST_FLAG_OPTIONAL_BOXES) != 0)
+       if (ret == 0 || (list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) != 0)
                mailbox_list_delete_finish(list, name);
        return ret;
 }
index 68cd1704c92cb59e6480b6d5322edebadb579b9d..22fd45586ef89b0de79bdfcafe735ec24b8df2c8 100644 (file)
@@ -1307,7 +1307,9 @@ int mailbox_list_mailbox(struct mailbox_list *list, const char *name,
                enum mailbox_existence existence;
                int ret;
 
-               box = mailbox_alloc(list, "INBOX", 0);
+               /* kludge: with imapc backend we can get here with
+                  list=Maildir++ (for indexes), but list->ns->list=imapc */
+               box = mailbox_alloc(list->ns->list, "INBOX", 0);
                ret = mailbox_exists(box, FALSE, &existence);
                mailbox_free(&box);
                if (ret < 0) {
@@ -1730,8 +1732,13 @@ int mailbox_list_create_missing_index_dir(struct mailbox_list *list,
                                         MAILBOX_LIST_PATH_TYPE_MAILBOX);
        index_dir = mailbox_list_get_path(list, name,
                                          MAILBOX_LIST_PATH_TYPE_INDEX);
-       if (*index_dir == '\0' || strcmp(index_dir, root_dir) == 0)
+       if (*index_dir == '\0')
                return 0;
+       if (strcmp(index_dir, root_dir) == 0) {
+               if ((list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) == 0)
+                       return 0;
+               /* the directory might not have been created yet */
+       }
 
        if (name == NULL) {
                return mailbox_list_mkdir_root(list, index_dir,
index 0d625fda0adeacf3d45b26e6f24c85df05bdc1f8..8ad9d012c13420ebcf991fdce9947d7e4b0931ed 100644 (file)
@@ -24,7 +24,9 @@ enum mailbox_list_properties {
        /* no support for \noselect directories, only mailboxes */
        MAILBOX_LIST_PROP_NO_NOSELECT           = 0x04,
        /* mail root directory isn't required */
-       MAILBOX_LIST_PROP_NO_ROOT               = 0x08
+       MAILBOX_LIST_PROP_NO_ROOT               = 0x08,
+       /* Automatically create mailbox directories when needed */
+       MAILBOX_LIST_PROP_AUTOCREATE_DIRS       = 0x10
 };
 
 enum mailbox_list_flags {
@@ -32,11 +34,7 @@ enum mailbox_list_flags {
        MAILBOX_LIST_FLAG_MAILBOX_FILES         = 0x01,
        /* Namespace already has a mailbox list, don't assign this
           mailbox list to it. */
-       MAILBOX_LIST_FLAG_SECONDARY             = 0x02,
-       /* Don't assume that just because a mailbox directory doesn't exist
-          its index/control directories don't exist (e.g. this is index-only
-          mailbox list) */
-       MAILBOX_LIST_FLAG_OPTIONAL_BOXES        = 0x04
+       MAILBOX_LIST_FLAG_SECONDARY             = 0x02
 };
 
 enum mailbox_info_flags {