dovecot-2.0: mailbox list iter: Require MAILBOX_LIST_ITER_VIRTUA...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 17 23:09:32 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/99d56a37edd0
changeset: 11576:99d56a37edd0
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 17 21:09:24 2010 +0100
description:
mailbox list iter: Require MAILBOX_LIST_ITER_VIRTUAL_NAMES flag.
The backend code will be simplified later by removing two code paths for
virtual/non-virtual names.

diffstat:

 src/imap/cmd-list.c                                      |   6 ++-
 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c |   5 ++-
 src/lib-storage/list/mailbox-list-maildir.c              |  44 +++++++++++++---------
 src/lib-storage/mailbox-list.c                           |   5 ++
 src/plugins/acl/acl-backend-vfile-acllist.c              |   9 +++-
 src/plugins/acl/acl-mailbox-list.c                       |  15 +------
 src/plugins/acl/acl-shared-storage.c                     |   1 +
 7 files changed, 50 insertions(+), 35 deletions(-)

diffs (242 lines):

diff -r 6d0b4dfc0829 -r 99d56a37edd0 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Thu Jun 17 20:57:22 2010 +0100
+++ b/src/imap/cmd-list.c	Thu Jun 17 21:09:24 2010 +0100
@@ -184,7 +184,8 @@
 
 	/* 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 @@
 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;
diff -r 6d0b4dfc0829 -r 99d56a37edd0 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Jun 17 20:57:22 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Jun 17 21:09:24 2010 +0100
@@ -457,7 +457,7 @@
 
 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 @@
 	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 @@
 		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) {
diff -r 6d0b4dfc0829 -r 99d56a37edd0 src/lib-storage/list/mailbox-list-maildir.c
--- a/src/lib-storage/list/mailbox-list-maildir.c	Thu Jun 17 20:57:22 2010 +0100
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Thu Jun 17 21:09:24 2010 +0100
@@ -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 @@
 	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 @@
 	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 @@
 
 		/* 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 @@
 	}
 
 	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 @@
 			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);
diff -r 6d0b4dfc0829 -r 99d56a37edd0 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Thu Jun 17 20:57:22 2010 +0100
+++ b/src/lib-storage/mailbox-list.c	Thu Jun 17 21:09:24 2010 +0100
@@ -787,6 +787,11 @@
 {
 	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);
 }
 
diff -r 6d0b4dfc0829 -r 99d56a37edd0 src/plugins/acl/acl-backend-vfile-acllist.c
--- a/src/plugins/acl/acl-backend-vfile-acllist.c	Thu Jun 17 20:57:22 2010 +0100
+++ b/src/plugins/acl/acl-backend-vfile-acllist.c	Thu Jun 17 21:09:24 2010 +0100
@@ -156,14 +156,17 @@
 
 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 @@
 	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) {
diff -r 6d0b4dfc0829 -r 99d56a37edd0 src/plugins/acl/acl-mailbox-list.c
--- a/src/plugins/acl/acl-mailbox-list.c	Thu Jun 17 20:57:22 2010 +0100
+++ b/src/plugins/acl/acl-mailbox-list.c	Thu Jun 17 21:09:24 2010 +0100
@@ -224,21 +224,12 @@
 {
 	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);
diff -r 6d0b4dfc0829 -r 99d56a37edd0 src/plugins/acl/acl-shared-storage.c
--- a/src/plugins/acl/acl-shared-storage.c	Thu Jun 17 20:57:22 2010 +0100
+++ b/src/plugins/acl/acl-shared-storage.c	Thu Jun 17 21:09:24 2010 +0100
@@ -51,6 +51,7 @@
 
 	/* 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;


More information about the dovecot-cvs mailing list