[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-list.c,1.23,1.24 maildir-storage.c,1.51,1.52 maildir-storage.h,1.18,1.19

cras at procontrol.fi cras at procontrol.fi
Sun Jul 27 07:12:16 EEST 2003


Update of /home/cvs/dovecot/src/lib-storage/index/maildir
In directory danu:/tmp/cvs-serv23650/lib-storage/index/maildir

Modified Files:
	maildir-list.c maildir-storage.c maildir-storage.h 
Log Message:
Mail storages support now configurable namespace prefix and hierarchy
separator. Subscription file handling needs some more thought.



Index: maildir-list.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-list.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- maildir-list.c	26 Jul 2003 23:53:05 -0000	1.23
+++ maildir-list.c	27 Jul 2003 03:12:13 -0000	1.24
@@ -36,15 +36,13 @@
 	while (node != NULL) {
 		if (node->children != NULL) {
 			node->flags |= MAILBOX_CHILDREN;
+			node->flags &= ~MAILBOX_NOCHILDREN;
 			maildir_nodes_fix(node->children, is_subs);
 		} else if ((node->flags & MAILBOX_PLACEHOLDER) != 0) {
 			if (!is_subs) {
 				node->flags &= ~MAILBOX_PLACEHOLDER;
 				node->flags |= MAILBOX_NOSELECT;
 			}
-		} else {
-			if ((node->flags & MAILBOX_CHILDREN) == 0)
-				node->flags |= MAILBOX_NOCHILDREN;
 		}
 		node = node->next;
 	}
@@ -55,7 +53,7 @@
 {
 	DIR *dirp;
 	struct dirent *d;
-	const char *path, *p;
+	const char *path, *p, *mailbox_c;
 	string_t *mailbox;
 	enum imap_match_result match;
 	struct mailbox_node *node;
@@ -73,7 +71,7 @@
 	/* INBOX exists always */
 	if (imap_match(glob, "INBOX") > 0 && !update_only) {
 		node = mailbox_tree_get(ctx->tree_ctx, "INBOX", NULL);
-		node->flags |= MAILBOX_FLAG_MATCHED;
+		node->flags |= MAILBOX_FLAG_MATCHED | MAILBOX_NOCHILDREN;
 		node->flags &= ~(MAILBOX_PLACEHOLDER | MAILBOX_NONEXISTENT);
 	}
 
@@ -81,11 +79,12 @@
 	while ((d = readdir(dirp)) != NULL) {
 		const char *fname = d->d_name;
 
-		if (fname[0] != '.')
+		if (fname[0] != MAILDIR_FS_SEP)
 			continue;
 
 		/* skip . and .. */
-		if (fname[1] == '\0' || (fname[1] == '.' && fname[2] == '\0'))
+		if (fname[0] == '.' &&
+		    (fname[1] == '\0' || (fname[1] == '.' && fname[2] == '\0')))
 			continue;
 
 		/* FIXME: kludges. these files must be renamed later */
@@ -93,8 +92,7 @@
 		    strcmp(fname, ".subscriptions") == 0)
 			continue;
 
-		fname++;
-		if (*fname == '.') {
+		if (fname[1] == MAILDIR_FS_SEP) {
 			/* this mailbox is in the middle of being deleted,
 			   or the process trying to delete it had died.
 
@@ -103,9 +101,6 @@
 			   mail root dir. */
 			struct stat st;
 
-			if (*ctx->prefix == '\0')
-				continue;
-
 			t_push();
 			path = t_strdup_printf("%s/%s", ctx->dir, fname);
 			if (stat(path, &st) == 0 &&
@@ -114,43 +109,54 @@
 			t_pop();
 			continue;
 		}
+		fname++;
 
 		/* make sure the mask matches */
 		str_truncate(mailbox, 0);
 		str_append(mailbox, ctx->prefix);
 		str_append(mailbox, fname);
+                mailbox_c = str_c(mailbox);
 
-		match = imap_match(glob, str_c(mailbox));
+		match = imap_match(glob, mailbox_c);
 
 		if (match != IMAP_MATCH_YES &&
-		    (match != IMAP_MATCH_PARENT || update_only))
+		    match != IMAP_MATCH_PARENT)
 			continue;
 
-		if (strcasecmp(str_c(mailbox), "INBOX") == 0)
+		if (strcasecmp(fname, "INBOX") == 0)
 			continue; /* ignore inboxes */
 
 		if (match == IMAP_MATCH_PARENT) {
 			t_push();
-			while ((p = strrchr(fname, '.')) != NULL) {
-				fname = t_strdup_until(fname, p);
-				p = t_strconcat(ctx->prefix, fname, NULL);
-				if (imap_match(glob, p) > 0)
+			while ((p = strrchr(mailbox_c,
+					    MAILDIR_FS_SEP)) != NULL) {
+				str_truncate(mailbox, (size_t) (p-mailbox_c));
+				mailbox_c = str_c(mailbox);
+				if (imap_match(glob, mailbox_c) > 0)
 					break;
 			}
 			i_assert(p != NULL);
 
-			node = mailbox_tree_get(ctx->tree_ctx, p, &created);
-			if (created)
-				node->flags = MAILBOX_PLACEHOLDER;
-			node->flags |= MAILBOX_CHILDREN | MAILBOX_FLAG_MATCHED;
+			created = FALSE;
+			node = update_only ?
+				mailbox_tree_update(ctx->tree_ctx, mailbox_c) :
+				mailbox_tree_get(ctx->tree_ctx,
+						 mailbox_c, &created);
+			if (node != NULL) {
+				if (created)
+					node->flags = MAILBOX_PLACEHOLDER;
+
+				node->flags |= MAILBOX_CHILDREN |
+					MAILBOX_FLAG_MATCHED;
+				node->flags &= ~MAILBOX_NOCHILDREN;
+			}
 
 			t_pop();
 		} else {
-			p = str_c(mailbox);
-			if (update_only)
-				node = mailbox_tree_update(ctx->tree_ctx, p);
-			else
-				node = mailbox_tree_get(ctx->tree_ctx, p, NULL);
+			node = update_only ?
+				mailbox_tree_update(ctx->tree_ctx, mailbox_c) :
+				mailbox_tree_get(ctx->tree_ctx,
+						 mailbox_c, NULL);
 
 			if (node != NULL) {
 				node->flags &= ~(MAILBOX_PLACEHOLDER |
@@ -172,8 +178,7 @@
 }
 
 static int maildir_fill_subscribed(struct mailbox_list_context *ctx,
-				   struct imap_match_glob *glob,
-				   int nonexistent)
+				   struct imap_match_glob *glob)
 {
 	struct subsfile_list_context *subsfile_ctx;
 	const char *name, *p;
@@ -189,12 +194,15 @@
 		case IMAP_MATCH_YES:
 			node = mailbox_tree_get(ctx->tree_ctx, name, NULL);
 			node->flags = MAILBOX_FLAG_MATCHED;
-			if (nonexistent && strcasecmp(name, "INBOX") != 0)
-				node->flags |= MAILBOX_NONEXISTENT;
+			if ((ctx->flags & MAILBOX_LIST_FAST_FLAGS) == 0) {
+				if (strcasecmp(name, "INBOX") != 0)
+					node->flags |= MAILBOX_NONEXISTENT;
+				node->flags |= MAILBOX_NOCHILDREN;
+			}
 			break;
 		case IMAP_MATCH_PARENT:
 			/* placeholder */
-			while ((p = strrchr(name, '.')) != NULL) {
+			while ((p = strrchr(name, MAILDIR_FS_SEP)) != NULL) {
 				name = t_strdup_until(name, p);
 				if (imap_match(glob, name) > 0)
 					break;
@@ -203,7 +211,8 @@
 
 			node = mailbox_tree_get(ctx->tree_ctx, name, &created);
 			if (created) node->flags = MAILBOX_PLACEHOLDER;
-			node->flags |= MAILBOX_FLAG_MATCHED;
+			node->flags |= MAILBOX_FLAG_MATCHED | MAILBOX_CHILDREN;
+			node->flags &= ~MAILBOX_NOCHILDREN;
 			break;
 		default:
 			break;
@@ -221,7 +230,6 @@
         struct mailbox_list_context *ctx;
         struct imap_match_glob *glob;
 	const char *dir, *p;
-	int nonexistent;
 	pool_t pool;
 
 	mail_storage_clear_error(storage);
@@ -231,33 +239,35 @@
 	ctx->pool = pool;
 	ctx->storage = storage;
 	ctx->flags = flags;
-	ctx->tree_ctx = mailbox_tree_init('.');
+	ctx->tree_ctx = mailbox_tree_init(MAILDIR_FS_SEP);
 
-	glob = imap_match_init(pool, mask, TRUE, '.');
+	if (storage->hierarchy_sep != MAILDIR_FS_SEP &&
+	    strchr(mask, MAILDIR_FS_SEP) != NULL) {
+		/* this will never match, return nothing */
+		return ctx;
+	}
 
-	if ((flags & MAILBOX_LIST_SUBSCRIBED) != 0) {
-		ctx->dir = storage->dir;
-		ctx->prefix = "";
+	mask = maildir_fix_mailbox_name(storage, mask, FALSE);
+	glob = imap_match_init(pool, mask, TRUE, MAILDIR_FS_SEP);
 
-		nonexistent = (flags & MAILBOX_LIST_FAST_FLAGS) == 0;
-		if (!maildir_fill_subscribed(ctx, glob, nonexistent)) {
+	ctx->dir = storage->dir;
+	ctx->prefix = storage->namespace == NULL ? "" :
+		maildir_fix_mailbox_name(storage, storage->namespace, FALSE);
+
+	if ((flags & MAILBOX_LIST_SUBSCRIBED) != 0) {
+		if (!maildir_fill_subscribed(ctx, glob)) {
                         mailbox_tree_deinit(ctx->tree_ctx);
 			pool_unref(pool);
 			return NULL;
 		}
-	} else {
-		if (!full_filesystem_access ||
-		    (p = strrchr(mask, '/')) == NULL) {
-			ctx->dir = storage->dir;
-			ctx->prefix = "";
-		} else {
-			dir = t_strdup_until(mask, p);
-			ctx->prefix = t_strdup_until(mask, p+1);
+	} else if (full_filesystem_access && (p = strrchr(mask, '/')) != NULL) {
+		dir = t_strdup_until(mask, p);
+		ctx->prefix = t_strconcat(ctx->prefix,
+					  t_strdup_until(mask, p+1), NULL);
 
-			if (*mask != '/' && *mask != '~')
-				dir = t_strconcat(storage->dir, "/", dir, NULL);
-			ctx->dir = p_strdup(pool, home_expand(dir));
-		}
+		if (*mask != '/' && *mask != '~')
+			dir = t_strconcat(storage->dir, "/", dir, NULL);
+		ctx->dir = p_strdup(pool, home_expand(dir));
 	}
 
 	if ((flags & MAILBOX_LIST_SUBSCRIBED) == 0 ||
@@ -270,6 +280,7 @@
 		}
 	}
 
+	ctx->prefix = p_strdup(pool, ctx->prefix);
 	ctx->node_path = str_new(pool, 256);
 	ctx->root = mailbox_tree_get(ctx->tree_ctx, NULL, NULL);
 	return ctx;
@@ -283,7 +294,7 @@
 }
 
 static struct mailbox_node *find_next(struct mailbox_node **node,
-				      string_t *path)
+				      string_t *path, char hierarchy_sep)
 {
 	struct mailbox_node *child;
 	size_t len;
@@ -295,10 +306,11 @@
 		if ((*node)->children != NULL) {
 			len = str_len(path);
 			if (len != 0)
-				str_append_c(path, '.');
+				str_append_c(path, hierarchy_sep);
 			str_append(path, (*node)->name);
 
-			child = find_next(&(*node)->children, path);
+			child = find_next(&(*node)->children, path,
+					  hierarchy_sep);
 			if (child != NULL)
 				return child;
 
@@ -322,8 +334,12 @@
 	}
 
 	if (node == NULL) {
+		if (ctx->root == NULL)
+			return NULL;
+
 		str_truncate(ctx->node_path, 0);
-		node = find_next(&ctx->root, ctx->node_path);
+		node = find_next(&ctx->root, ctx->node_path,
+				 ctx->storage->hierarchy_sep);
                 ctx->parent_pos = str_len(ctx->node_path);
 
 		if (node == NULL)
@@ -336,7 +352,7 @@
 
 	str_truncate(ctx->node_path, ctx->parent_pos);
 	if (ctx->parent_pos != 0)
-		str_append_c(ctx->node_path, '.');
+		str_append_c(ctx->node_path, ctx->storage->hierarchy_sep);
 	str_append(ctx->node_path, node->name);
 
 	ctx->list.name = str_c(ctx->node_path);

Index: maildir-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- maildir-storage.c	26 Jul 2003 23:53:05 -0000	1.51
+++ maildir-storage.c	27 Jul 2003 03:12:13 -0000	1.52
@@ -26,7 +26,9 @@
 
 static const char *maildirs[] = { "cur", "new", "tmp", NULL  };
 
-static struct mail_storage *maildir_create(const char *data, const char *user)
+static struct mail_storage *
+maildir_create(const char *data, const char *user,
+	       const char *namespace, char hierarchy_sep)
 {
 	struct mail_storage *storage;
 	const char *root_dir, *inbox_dir, *index_dir, *control_dir;
@@ -80,6 +82,10 @@
 	storage = i_new(struct mail_storage, 1);
 	memcpy(storage, &maildir_storage, sizeof(struct mail_storage));
 
+	if (hierarchy_sep != '\0')
+		storage->hierarchy_sep = hierarchy_sep;
+	storage->namespace = i_strdup(namespace);
+
 	storage->dir = i_strdup(home_expand(root_dir));
 	storage->inbox_file = i_strdup(home_expand(inbox_dir));
 	storage->index_dir = i_strdup(home_expand(index_dir));
@@ -94,6 +100,7 @@
 {
 	index_storage_deinit(storage);
 
+	i_free(storage->namespace);
 	i_free(storage->dir);
 	i_free(storage->inbox_file);
 	i_free(storage->index_dir);
@@ -114,30 +121,37 @@
 		S_ISDIR(st.st_mode);
 }
 
-static int maildir_is_valid_create_name(struct mail_storage *storage,
-					const char *name)
+static int maildir_is_valid_create_name(const char *name)
 {
-	if (name[0] == '\0' || name[strlen(name)-1] == storage->hierarchy_sep ||
+	size_t len;
+
+	len = strlen(name);
+	if (len == 0 ||
+	    name[0] == MAILDIR_FS_SEP || name[len-1] == MAILDIR_FS_SEP ||
 	    strchr(name, '*') != NULL || strchr(name, '%') != NULL)
 		return FALSE;
 
 	if (full_filesystem_access)
 		return TRUE;
 
-	return *name != '~' &&
-		strchr(name, '/') == NULL && strchr(name, '\\') == NULL;
+	if (*name == '~' || strchr(name, '/') != NULL)
+		return FALSE;
+
+	return TRUE;
 }
 
 static int maildir_is_valid_existing_name(const char *name)
 {
-	if (name[0] == '\0' || name[0] == '.')
+	if (name[0] == '\0')
 		return FALSE;
 
 	if (full_filesystem_access)
 		return TRUE;
 
-	return *name != '~' &&
-		strchr(name, '/') == NULL && strchr(name, '\\') == NULL;
+	if (*name == '~' || strchr(name, '/') != NULL)
+		return FALSE;
+
+	return TRUE;
 }
 
 static const char *maildir_get_absolute_path(const char *name, int unlink)
@@ -150,7 +164,50 @@
 	if (p == NULL)
 		return name;
 	return t_strconcat(t_strdup_until(name, p+1),
-			   unlink ? ".." : ".", p+1, NULL);
+			   unlink ? MAILDIR_FS_SEP_S MAILDIR_FS_SEP_S :
+			   MAILDIR_FS_SEP_S, p+1, NULL);
+}
+
+const char *maildir_fix_mailbox_name(struct mail_storage *storage,
+				     const char *name, int remove_namespace)
+{
+	char *dup, *p, sep;
+	size_t len;
+
+	if (strncasecmp(name, "INBOX", 5) == 0 &&
+	    (name[5] == '\0' || name[5] == storage->hierarchy_sep)) {
+		/* use same case with all INBOX folders or we'll get
+		   into trouble */
+		name = t_strconcat("INBOX", name+5, NULL);
+		if (name[5] == '\0') {
+			/* don't check namespace with INBOX */
+			return name;
+		}
+	}
+
+	if (storage->namespace != NULL && remove_namespace) {
+		len = strlen(storage->namespace);
+		if (strncmp(storage->namespace, name, len) != 0) {
+			i_panic("mbox: expecting namespace '%s' in name '%s'",
+				storage->namespace, name);
+		}
+		name += len;
+	}
+
+	if (*name == '/' && full_filesystem_access)
+		return name;
+
+	sep = storage->hierarchy_sep;
+	if (sep == MAILDIR_FS_SEP)
+		return name;
+
+	dup = t_strdup_noconst(name);
+	for (p = dup; *p != '\0'; p++) {
+		if (*p == sep)
+			*p = MAILDIR_FS_SEP;
+	}
+
+	return dup;
 }
 
 const char *maildir_get_path(struct mail_storage *storage, const char *name)
@@ -158,12 +215,12 @@
 	if (full_filesystem_access && (*name == '/' || *name == '~'))
 		return maildir_get_absolute_path(name, FALSE);
 
-	if (strcasecmp(name, "INBOX") == 0) {
+	if (strcmp(name, "INBOX") == 0) {
 		return storage->inbox_file != NULL ?
 			storage->inbox_file : storage->dir;
 	}
 
-	return t_strconcat(storage->dir, "/.", name, NULL);
+	return t_strconcat(storage->dir, "/"MAILDIR_FS_SEP_S, name, NULL);
 }
 
 static const char *
@@ -172,7 +229,8 @@
 	if (full_filesystem_access && (*name == '/' || *name == '~'))
 		return maildir_get_absolute_path(name, TRUE);
 
-	return maildir_get_path(storage, t_strconcat(".", name, NULL));
+	return maildir_get_path(storage,
+				t_strconcat(MAILDIR_FS_SEP_S, name, NULL));
 }
 
 static const char *maildir_get_index_path(struct mail_storage *storage,
@@ -181,13 +239,13 @@
 	if (storage->index_dir == NULL)
 		return NULL;
 
-	if (strcasecmp(name, "INBOX") == 0 && storage->inbox_file != NULL)
+	if (strcmp(name, "INBOX") == 0 && storage->inbox_file != NULL)
 		return storage->inbox_file;
 
 	if (full_filesystem_access && (*name == '/' || *name == '~'))
 		return maildir_get_absolute_path(name, FALSE);
 
-	return t_strconcat(storage->index_dir, "/.", name, NULL);
+	return t_strconcat(storage->index_dir, "/"MAILDIR_FS_SEP_S, name, NULL);
 }
 
 static const char *maildir_get_control_path(struct mail_storage *storage,
@@ -199,7 +257,8 @@
 	if (full_filesystem_access && (*name == '/' || *name == '~'))
 		return maildir_get_absolute_path(name, FALSE);
 
-	return t_strconcat(storage->control_dir, "/.", name, NULL);
+	return t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S,
+			   name, NULL);
 }
 
 static int mkdir_verify(struct mail_storage *storage,
@@ -270,7 +329,7 @@
 	     strcmp(storage->index_dir, storage->inbox_file) == 0))
 		return TRUE;
 
-	dir = t_strconcat(storage->index_dir, "/.", name, NULL);
+	dir = t_strconcat(storage->index_dir, "/"MAILDIR_FS_SEP_S, name, NULL);
 	if (mkdir_parents(dir, CREATE_MODE) == -1 && errno != EEXIST) {
 		mail_storage_set_critical(storage, "mkdir(%s) failed: %m", dir);
 		return FALSE;
@@ -286,7 +345,8 @@
 	if (storage->control_dir == NULL)
 		return TRUE;
 
-	dir = t_strconcat(storage->control_dir, "/.", name, NULL);
+	dir = t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S,
+			  name, NULL);
 	if (mkdir_parents(dir, CREATE_MODE) < 0 && errno != EEXIST) {
 		mail_storage_set_critical(storage, "mkdir(%s) failed: %m", dir);
 		return FALSE;
@@ -306,7 +366,8 @@
 			return FALSE;
 
 		/* create the .INBOX directory */
-		inbox = t_strconcat(storage->dir, "/.INBOX", NULL);
+		inbox = t_strconcat(storage->dir,
+				    "/"MAILDIR_FS_SEP_S"INBOX", NULL);
 		if (!mkdir_verify(storage, inbox, TRUE))
 			return FALSE;
 	} else {
@@ -350,19 +411,6 @@
 	return (struct mailbox *) ibox;
 }
 
-static const char *inbox_fix_case(struct mail_storage *storage,
-				  const char *name)
-{
-        if (strncasecmp(name, "INBOX", 5) == 0 &&
-	    (name[5] == '\0' || name[5] == storage->hierarchy_sep)) {
-		/* use same case with all INBOX folders or we'll get
-		   into trouble */
-		name = t_strconcat("INBOX", name+5, NULL);
-	}
-
-	return name;
-}
-
 static struct mailbox *
 maildir_open_mailbox(struct mail_storage *storage,
 		     const char *name, enum mailbox_open_flags flags)
@@ -372,7 +420,7 @@
 
 	mail_storage_clear_error(storage);
 
-	name = inbox_fix_case(storage, name);
+	name = maildir_fix_mailbox_name(storage, name, TRUE);
 	if (strcmp(name, "INBOX") == 0) {
 		if (!verify_inbox(storage))
 			return NULL;
@@ -410,8 +458,8 @@
 
 	mail_storage_clear_error(storage);
 
-	name = inbox_fix_case(storage, name);
-	if (!maildir_is_valid_create_name(storage, name)) {
+	name = maildir_fix_mailbox_name(storage, name, TRUE);
+	if (!maildir_is_valid_create_name(name)) {
 		mail_storage_set_error(storage, "Invalid mailbox name");
 		return FALSE;
 	}
@@ -442,8 +490,8 @@
 
 	mail_storage_clear_error(storage);
 
-	name = inbox_fix_case(storage, name);
-	if (strcasecmp(name, "INBOX") == 0) {
+	name = maildir_fix_mailbox_name(storage, name, TRUE);
+	if (strcmp(name, "INBOX") == 0) {
 		mail_storage_set_error(storage, "INBOX can't be deleted.");
 		return FALSE;
 	}
@@ -466,7 +514,8 @@
 
 	if (storage->index_dir != NULL && *name != '/' && *name != '~' &&
 	    strcmp(storage->index_dir, storage->dir) != 0) {
-		index_dir = t_strconcat(storage->index_dir, "/.", name, NULL);
+		index_dir = t_strconcat(storage->index_dir,
+					"/"MAILDIR_FS_SEP_S, name, NULL);
 		index_storage_destroy_unrefed();
 
 		/* it can fail with some NFS implementations if indexes are
@@ -517,8 +566,10 @@
 		return TRUE;
 
 	/* Rename it's index. */
-	oldpath = t_strconcat(storage->index_dir, "/.", oldname, NULL);
-	newpath = t_strconcat(storage->index_dir, "/.", newname, NULL);
+	oldpath = t_strconcat(storage->index_dir, "/"MAILDIR_FS_SEP_S,
+			      oldname, NULL);
+	newpath = t_strconcat(storage->index_dir, "/"MAILDIR_FS_SEP_S,
+			      newname, NULL);
 
 	if (rename(oldpath, newpath) < 0 && errno != ENOENT) {
 		mail_storage_set_critical(storage, "rename(%s, %s) failed: %m",
@@ -534,23 +585,29 @@
 {
 	struct mailbox_list_context *ctx;
         struct mailbox_list *list;
-	const char *oldpath, *newpath, *new_listname;
+	const char *oldpath, *newpath, *new_listname, *mask;
 	size_t oldnamelen;
 	int ret;
 
 	ret = 0;
 	oldnamelen = strlen(oldname);
 
-	ctx = storage->list_mailbox_init(storage,
-					 t_strconcat(oldname, ".*", NULL),
+	mask = t_strdup_printf("%s%s%c*", storage->namespace != NULL ?
+			       storage->namespace : "", oldname,
+			       storage->hierarchy_sep);
+	ctx = storage->list_mailbox_init(storage, mask,
 					 MAILBOX_LIST_FAST_FLAGS);
 	while ((list = maildir_list_mailbox_next(ctx)) != NULL) {
-		i_assert(oldnamelen <= strlen(list->name));
+		const char *list_name;
 
 		t_push();
+
+		list_name = maildir_fix_mailbox_name(storage, list->name, TRUE);
+		i_assert(oldnamelen <= strlen(list_name));
+
 		new_listname = t_strconcat(newname,
-					   list->name + oldnamelen, NULL);
-		oldpath = maildir_get_path(storage, list->name);
+					   list_name + oldnamelen, NULL);
+		oldpath = maildir_get_path(storage, list_name);
 		newpath = maildir_get_path(storage, new_listname);
 
 		/* FIXME: it's possible to merge two folders if either one of
@@ -573,7 +630,7 @@
 			break;
 		}
 
-		(void)rename_indexes(storage, list->name, new_listname);
+		(void)rename_indexes(storage, list_name, new_listname);
 		t_pop();
 	}
 
@@ -590,9 +647,11 @@
 
 	mail_storage_clear_error(storage);
 
-	oldname = inbox_fix_case(storage, oldname);
+	oldname = maildir_fix_mailbox_name(storage, oldname, TRUE);
+	newname = maildir_fix_mailbox_name(storage, newname, TRUE);
+
 	if (!maildir_is_valid_existing_name(oldname) ||
-	    !maildir_is_valid_create_name(storage, newname)) {
+	    !maildir_is_valid_create_name(newname)) {
 		mail_storage_set_error(storage, "Invalid mailbox name");
 		return FALSE;
 	}
@@ -636,6 +695,13 @@
 	}
 }
 
+static int maildir_set_subscribed(struct mail_storage *storage,
+				  const char *name, int set)
+{
+	name = maildir_fix_mailbox_name(storage, name, FALSE);
+	return subsfile_set_subscribed(storage, name, set);
+}
+
 static int maildir_get_mailbox_name_status(struct mail_storage *storage,
 					   const char *name,
 					   enum mailbox_name_status *status)
@@ -645,7 +711,7 @@
 
 	mail_storage_clear_error(storage);
 
-	name = inbox_fix_case(storage, name);
+	name = maildir_fix_mailbox_name(storage, name, TRUE);
 	if (!maildir_is_valid_existing_name(name)) {
 		*status = MAILBOX_NAME_INVALID;
 		return TRUE;
@@ -657,7 +723,7 @@
 		return TRUE;
 	}
 
-	if (!maildir_is_valid_create_name(storage, name)) {
+	if (!maildir_is_valid_create_name(name)) {
 		*status = MAILBOX_NAME_INVALID;
 		return TRUE;
 	}
@@ -732,8 +798,9 @@
 
 struct mail_storage maildir_storage = {
 	"maildir", /* name */
+	NULL, /* namespace */
 
-	'.', /* hierarchy_sep - can't be changed */
+	'.', /* default hierarchy separator */
 
 	maildir_create,
 	maildir_free,
@@ -746,7 +813,7 @@
 	maildir_list_mailbox_init,
 	maildir_list_mailbox_deinit,
 	maildir_list_mailbox_next,
-	subsfile_set_subscribed,
+	maildir_set_subscribed,
 	maildir_get_mailbox_name_status,
 	mail_storage_get_last_error,
 

Index: maildir-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- maildir-storage.h	26 Jul 2003 23:53:05 -0000	1.18
+++ maildir-storage.h	27 Jul 2003 03:12:13 -0000	1.19
@@ -1,6 +1,10 @@
 #ifndef __MAILDIR_STORAGE_H
 #define __MAILDIR_STORAGE_H
 
+/* Hierarchy separator in Maildir++ filenames - shouldn't be changed */
+#define MAILDIR_FS_SEP '.'
+#define MAILDIR_FS_SEP_S "."
+
 #include "index-storage.h"
 
 struct mail_copy_context *maildir_storage_copy_init(struct mailbox *box);
@@ -32,6 +36,8 @@
 int maildir_storage_expunge(struct mail *mail, struct mail_expunge_context *ctx,
 			    unsigned int *seq_r, int notify);
 
+const char *maildir_fix_mailbox_name(struct mail_storage *storage,
+				     const char *name, int remove_namespace);
 const char *maildir_get_path(struct mail_storage *storage, const char *name);
 
 #endif



More information about the dovecot-cvs mailing list