]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mailbox list iter: Require MAILBOX_LIST_ITER_VIRTUAL_NAMES flag.
authorTimo Sirainen <tss@iki.fi>
Thu, 17 Jun 2010 20:09:24 +0000 (21:09 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 17 Jun 2010 20:09:24 +0000 (21:09 +0100)
The backend code will be simplified later by removing two code paths for
virtual/non-virtual names.

--HG--
branch : HEAD

src/imap/cmd-list.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/list/mailbox-list-maildir.c
src/lib-storage/mailbox-list.c
src/plugins/acl/acl-backend-vfile-acllist.c
src/plugins/acl/acl-mailbox-list.c
src/plugins/acl/acl-shared-storage.c

index ce31352905a203c6f0346a5ea1c9972755687185..cb766c5180b2f51b462c2bbaa915e749c085e410 100644 (file)
@@ -184,7 +184,8 @@ list_get_inbox_flags(struct cmd_list_context *ctx)
 
        /* find the INBOX flags */
        ns = mail_namespace_find_inbox(ctx->cmd->client->user->namespaces);
-       list_iter = mailbox_list_iter_init(ns->list, "INBOX", 0);
+       list_iter = mailbox_list_iter_init(ns->list, "INBOX",
+                                          MAILBOX_LIST_ITER_VIRTUAL_NAMES);
        info = mailbox_list_iter_next(list_iter);
        if (info != NULL) {
                i_assert(strcasecmp(info->name, "INBOX") == 0);
@@ -197,7 +198,8 @@ list_get_inbox_flags(struct cmd_list_context *ctx)
 static bool list_namespace_has_children(struct cmd_list_context *ctx)
 {
        enum mailbox_list_iter_flags list_flags =
-               MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
+               MAILBOX_LIST_ITER_RETURN_NO_FLAGS |
+               MAILBOX_LIST_ITER_VIRTUAL_NAMES;
        struct mailbox_list_iterate_context *list_iter;
        const struct mailbox_info *info;
        bool ret = FALSE;
index dd4137d6952c2ac73ae96a3573bb633d857dd834..b82a02167a0bac9454d60d88e787c78748d5b673 100644 (file)
@@ -457,7 +457,7 @@ static void mdbox_header_update(struct dbox_sync_rebuild_context *rebuild_ctx,
 
 static int
 rebuild_mailbox(struct mdbox_storage_rebuild_context *ctx,
-               struct mail_namespace *ns, const char *name)
+               struct mail_namespace *ns, const char *vname)
 {
        struct mailbox *box;
        struct mdbox_mailbox *mbox;
@@ -466,8 +466,10 @@ rebuild_mailbox(struct mdbox_storage_rebuild_context *ctx,
        struct mail_index_transaction *trans;
        struct dbox_sync_rebuild_context *rebuild_ctx;
        enum mail_error error;
+       const char *name;
        int ret;
 
+       name = mail_namespace_get_storage_name(ns, vname);
        box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_READONLY |
                            MAILBOX_FLAG_KEEP_RECENT |
                            MAILBOX_FLAG_IGNORE_ACLS);
@@ -518,6 +520,7 @@ rebuild_namespace_mailboxes(struct mdbox_storage_rebuild_context *ctx,
                ctx->default_list = ns->list;
 
        iter = mailbox_list_iter_init(ns->list, "*",
+                                     MAILBOX_LIST_ITER_VIRTUAL_NAMES |
                                      MAILBOX_LIST_ITER_RAW_LIST |
                                      MAILBOX_LIST_ITER_RETURN_NO_FLAGS);
        while ((info = mailbox_list_iter_next(iter)) != NULL) {
index 238f094ad0742a2a27a6602ebc3776b025a5f753..252b1d5c16e1a91f1657f811dec666071dc484de 100644 (file)
@@ -5,6 +5,7 @@
 #include "hostpid.h"
 #include "eacces-error.h"
 #include "mkdir-parents.h"
+#include "str.h"
 #include "subscription-file.h"
 #include "mailbox-list-delete.h"
 #include "mailbox-list-maildir.h"
@@ -467,16 +468,14 @@ maildir_rename_children(struct mailbox_list *oldlist, const char *oldname,
        struct mailbox_list_iterate_context *iter;
         const struct mailbox_info *info;
        ARRAY_DEFINE(names_arr, const char *);
-       const char *pattern, *oldpath, *newpath, *old_listname, *new_listname;
-       const char *const *names;
-       unsigned int i, count;
-       size_t oldnamelen;
+       const char *pattern, *oldpath, *newpath, *old_childname, *new_childname;
+       const char *const *names, *old_vname, *new_vname;
+       unsigned int i, count, old_vnamelen;
        pool_t pool;
-       char old_sep;
+       string_t *str;
        int ret;
 
        ret = 0;
-       oldnamelen = strlen(oldname);
 
        /* first get the list of the children and save them to memory, because
           we can't rely on readdir() not skipping files while the directory
@@ -485,9 +484,16 @@ maildir_rename_children(struct mailbox_list *oldlist, const char *oldname,
        pool = pool_alloconly_create("Maildir++ children list", 1024);
        i_array_init(&names_arr, 64);
 
-       old_sep = mailbox_list_get_hierarchy_sep(oldlist);
-       pattern = t_strdup_printf("%s%c*", oldname, old_sep);
+       str = t_str_new(256);
+       old_vname = t_strdup(mail_namespace_get_vname(oldlist->ns, str, oldname));
+       old_vnamelen = strlen(oldname);
+
+       str_truncate(str, 0);
+       new_vname = t_strdup(mail_namespace_get_vname(newlist->ns, str, newname));
+
+       pattern = t_strdup_printf("%s%c*", old_vname, oldlist->ns->sep);
        iter = mailbox_list_iter_init(oldlist, pattern,
+                                     MAILBOX_LIST_ITER_VIRTUAL_NAMES |
                                      MAILBOX_LIST_ITER_RETURN_NO_FLAGS |
                                      MAILBOX_LIST_ITER_RAW_LIST);
        while ((info = mailbox_list_iter_next(iter)) != NULL) {
@@ -495,9 +501,9 @@ maildir_rename_children(struct mailbox_list *oldlist, const char *oldname,
 
                /* verify that the prefix matches, otherwise we could have
                   problems with mailbox names containing '%' and '*' chars */
-               if (strncmp(info->name, oldname, oldnamelen) == 0 &&
-                   info->name[oldnamelen] == old_sep) {
-                       name = p_strdup(pool, info->name + oldnamelen);
+               if (strncmp(info->name, old_vname, old_vnamelen) == 0 &&
+                   info->name[old_vnamelen] == oldlist->ns->sep) {
+                       name = p_strdup(pool, info->name + old_vnamelen);
                        array_append(&names_arr, &name, 1);
                }
        }
@@ -509,17 +515,19 @@ maildir_rename_children(struct mailbox_list *oldlist, const char *oldname,
        }
 
        for (i = 0; i < count; i++) {
-               old_listname = t_strconcat(oldname, names[i], NULL);
-               if (strcmp(old_listname, newname) == 0) {
+               old_childname = mail_namespace_get_storage_name(oldlist->ns,
+                                       t_strconcat(old_vname, names[i], NULL));
+               if (strcmp(old_childname, new_vname) == 0) {
                        /* When doing RENAME "a" "a.b" we see "a.b" here.
                           We don't want to rename it anymore to "a.b.b". */
                        continue;
                }
 
-               new_listname = t_strconcat(newname, names[i], NULL);
-               oldpath = mailbox_list_get_path(oldlist, old_listname,
+               new_childname = mail_namespace_get_storage_name(newlist->ns,
+                                       t_strconcat(new_vname, names[i], NULL));
+               oldpath = mailbox_list_get_path(oldlist, old_childname,
                                                MAILBOX_LIST_PATH_TYPE_MAILBOX);
-               newpath = mailbox_list_get_path(newlist, new_listname,
+               newpath = mailbox_list_get_path(newlist, new_childname,
                                                MAILBOX_LIST_PATH_TYPE_MAILBOX);
 
                /* FIXME: it's possible to merge two mailboxes if either one of
@@ -539,9 +547,9 @@ maildir_rename_children(struct mailbox_list *oldlist, const char *oldname,
                        break;
                }
 
-               (void)rename_dir(oldlist, old_listname, newlist, new_listname,
+               (void)rename_dir(oldlist, old_childname, newlist, new_childname,
                                 MAILBOX_LIST_PATH_TYPE_CONTROL);
-               (void)rename_dir(oldlist, old_listname, newlist, new_listname,
+               (void)rename_dir(oldlist, old_childname, newlist, new_childname,
                                 MAILBOX_LIST_PATH_TYPE_INDEX);
        }
        array_free(&names_arr);
index 4ff45fcad4e4f788afdd7f52586b10dbe912c949..46fc8691af6a2833e43880b91c760a9da06a0502 100644 (file)
@@ -787,6 +787,11 @@ mailbox_list_iter_init_multiple(struct mailbox_list *list,
 {
        i_assert(*patterns != NULL);
 
+       /* we'll want to remove MAILBOX_LIST_ITER_VIRTUAL_NAMES flag completely.
+          this assert will be here until it's sure that there are no more
+          non-virtual users and it can be safely removed. (and if there are,
+          this assert can still be easily removed) */
+       i_assert((flags & MAILBOX_LIST_ITER_VIRTUAL_NAMES) != 0);
        return list->v.iter_init(list, patterns, flags);
 }
 
index 82db28aa35eb1a40a8bfc10fe5db2f9f9b5d3ff8..9dafd22d0bf63a6acd540c84a78f64c2cf2e4ba5 100644 (file)
@@ -156,14 +156,17 @@ void acl_backend_vfile_acllist_refresh(struct acl_backend_vfile *backend)
 
 static int
 acllist_append(struct acl_backend_vfile *backend, struct ostream *output,
-              const char *name)
+              const char *vname)
 {
        struct acl_object *aclobj;
        struct acl_object_list_iter *iter;
        struct acl_rights rights;
        struct acl_backend_vfile_acllist acllist;
+       const char *name;
        int ret;
 
+       name = mail_namespace_get_storage_name(backend->backend.list->ns,
+                                              vname);
        acl_cache_flush(backend->backend.cache, name);
        aclobj = acl_object_init_from_name(&backend->backend, name);
 
@@ -248,7 +251,9 @@ acl_backend_vfile_acllist_try_rebuild(struct acl_backend_vfile *backend)
        acllist_clear(backend, 0);
 
        backend->rebuilding_acllist = TRUE;
-       iter = mailbox_list_iter_init(list, "*", MAILBOX_LIST_ITER_RAW_LIST |
+       iter = mailbox_list_iter_init(list, "*",
+                                     MAILBOX_LIST_ITER_VIRTUAL_NAMES |
+                                     MAILBOX_LIST_ITER_RAW_LIST |
                                      MAILBOX_LIST_ITER_RETURN_NO_FLAGS);
        while ((info = mailbox_list_iter_next(iter)) != NULL) {
                if (acllist_append(backend, output, info->name) < 0) {
index efde55ec7d203999e3d4928b02111dcab146ef9d..2b0cb1e51283f8fc815a28947f995af157755cc1 100644 (file)
@@ -224,21 +224,12 @@ acl_mailbox_list_iter_get_name(struct mailbox_list_iterate_context *ctx,
 {
        struct mail_namespace *ns = ctx->list->ns;
        unsigned int len;
-       char sep;
 
-       if ((ctx->flags & MAILBOX_LIST_ITER_VIRTUAL_NAMES) == 0)
-               sep = ns->sep;
-       else {
-               /* Mailbox names contain namespace prefix,
-                  except when listing INBOX. */
-               if (strncmp(name, ns->prefix, ns->prefix_len) == 0)
-                       name += ns->prefix_len;
-               name = mail_namespace_fix_sep(ns, name);
-               sep = ns->real_sep;
-       }
+       if ((ctx->flags & MAILBOX_LIST_ITER_VIRTUAL_NAMES) != 0)
+               name = mail_namespace_get_storage_name(ns, name);
 
        len = strlen(name);
-       if (name[len-1] == sep) {
+       if (name[len-1] == ns->real_sep) {
                /* name ends with separator. this can happen if doing e.g.
                   LIST "" foo/% and it lists "foo/". */
                name = t_strndup(name, len-1);
index 98cea60eb637e201e0d470fc9c2f92f8fcd9b744..b7ca769825b4d74fc6ff06e795ca807847fe4cc4 100644 (file)
@@ -51,6 +51,7 @@ acl_shared_namespace_add(struct mail_namespace *ns,
 
        /* check if there are any mailboxes really visible to us */
        iter = mailbox_list_iter_init(new_ns->list, "*",
+                                     MAILBOX_LIST_ITER_VIRTUAL_NAMES |
                                      MAILBOX_LIST_ITER_RETURN_NO_FLAGS);
        while ((info = mailbox_list_iter_next(iter)) != NULL)
                break;