[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-list.c, 1.25, 1.26 mbox-storage.c, 1.89, 1.90 mbox-storage.h, 1.25, 1.26

cras at dovecot.org cras at dovecot.org
Fri Jul 23 00:20:03 EEST 2004


Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv11339/lib-storage/index/mbox

Modified Files:
	mbox-list.c mbox-storage.c mbox-storage.h 
Log Message:
Moved namespace and hierarchy separator handling to imap-specific code. LIST
now shows non-hidden namespaces in the LIST reply.



Index: mbox-list.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-list.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mbox-list.c	22 Jun 2004 19:28:15 -0000	1.25
+++ mbox-list.c	22 Jul 2004 21:20:01 -0000	1.26
@@ -31,7 +31,6 @@
 
 	enum mailbox_list_flags flags;
 
-	const char *prefix;
 	struct imap_match_glob *glob;
 	struct subsfile_list_context *subsfile_ctx;
 
@@ -45,23 +44,12 @@
 };
 
 static struct mailbox_list *mbox_list_subs(struct mbox_list_context *ctx);
-static struct mailbox_list *mbox_list_inbox(struct mbox_list_context *ctx);
 static struct mailbox_list *mbox_list_path(struct mbox_list_context *ctx);
 static struct mailbox_list *mbox_list_next(struct mbox_list_context *ctx);
-static struct mailbox_list *mbox_list_none(struct mbox_list_context *ctx);
 
-static const char *mask_get_dir(struct mail_storage *storage, const char *mask)
+static const char *mask_get_dir(const char *mask)
 {
 	const char *p, *last_dir;
-	size_t len;
-
-	if (storage->namespace != NULL) {
-		len = strlen(storage->namespace);
-		if (strncmp(mask, storage->namespace, len) != 0)
-			return NULL;
-
-		mask += len;
-	}
 
 	last_dir = NULL;
 	for (p = mask; *p != '\0' && *p != '%' && *p != '*'; p++) {
@@ -110,7 +98,8 @@
 }
 
 struct mailbox_list_context *
-mbox_mailbox_list_init(struct mail_storage *storage, const char *mask,
+mbox_mailbox_list_init(struct mail_storage *storage,
+		       const char *ref, const char *mask,
 		       enum mailbox_list_flags flags)
 {
 	struct index_storage *istorage = (struct index_storage *)storage;
@@ -118,26 +107,32 @@
 	const char *path, *virtual_path;
 	DIR *dirp;
 
+	ctx = i_new(struct mbox_list_context, 1);
+	ctx->mailbox_ctx.storage = storage;
+	ctx->istorage = istorage;
+	ctx->list_pool = pool_alloconly_create("mbox_list", 1024);
+        ctx->next = mbox_list_next;
+
 	mail_storage_clear_error(storage);
 
-	if (storage->hierarchy_sep != '/' && strchr(mask, '/') != NULL) {
-		/* this will never match, return nothing */
-		ctx = i_new(struct mbox_list_context, 1);
-		ctx->mailbox_ctx.storage = storage;
-                ctx->next = mbox_list_none;
+	/* check that we're not trying to do any "../../" lists */
+	if (!mbox_is_valid_mask(ref) ||
+	    !mbox_is_valid_mask(mask)) {
+		mail_storage_set_error(storage, "Invalid mask");
 		return &ctx->mailbox_ctx;
 	}
 
-	mask = mbox_fix_mailbox_name(istorage, mask, FALSE);
-
-	/* check that we're not trying to do any "../../" lists */
-	if (!mbox_is_valid_mask(mask)) {
-		mail_storage_set_error(storage, "Invalid mask");
-		return NULL;
+	if (*mask == '/' || *mask == '~') {
+		/* mask overrides reference */
+	} else if (*ref != '\0') {
+		/* merge reference and mask */
+		if (ref[strlen(ref)-1] == '/')
+			mask = t_strconcat(ref, mask, NULL);
+		else
+			mask = t_strconcat(ref, "/", mask, NULL);
 	}
 
 	if ((flags & MAILBOX_LIST_SUBSCRIBED) != 0) {
-		ctx = i_new(struct mbox_list_context, 1);
 		ctx->mailbox_ctx.storage = storage;
 		ctx->istorage = istorage;
 		ctx->flags = flags;
@@ -148,45 +143,33 @@
 		ctx->subsfile_ctx =
 			subsfile_list_init(storage, path);
 		if (ctx->subsfile_ctx == NULL) {
-			i_free(ctx);
-			return NULL;
+			ctx->next = mbox_list_next;
+			return &ctx->mailbox_ctx;
 		}
 		ctx->glob = imap_match_init(default_pool, mask, TRUE, '/');
-		ctx->list_pool = pool_alloconly_create("mbox_list", 1024);
 		return &ctx->mailbox_ctx;
 	}
 
 	/* if we're matching only subdirectories, don't bother scanning the
 	   parent directories */
-	virtual_path = mask_get_dir(storage, mask);
+	virtual_path = mask_get_dir(mask);
 
 	path = mbox_get_path(istorage, virtual_path);
 	if (list_opendir(storage, path, TRUE, &dirp) < 0)
-		return NULL;
+		return &ctx->mailbox_ctx;
 	/* if user gave invalid directory, we just don't show any results. */
 
-	ctx = i_new(struct mbox_list_context, 1);
-	ctx->mailbox_ctx.storage = storage;
-	ctx->istorage = istorage;
 	ctx->flags = flags;
 	ctx->glob = imap_match_init(default_pool, mask, TRUE, '/');
-	ctx->list_pool = pool_alloconly_create("mbox_list", 1024);
-	ctx->prefix = storage->namespace == NULL ? "" :
-		mbox_fix_mailbox_name(istorage, storage->namespace, FALSE);
 
-	if (virtual_path == NULL && imap_match(ctx->glob, "INBOX") > 0)
-		ctx->next = mbox_list_inbox;
-	else if (virtual_path != NULL && dirp != NULL)
+	if (virtual_path != NULL && dirp != NULL)
 		ctx->next = mbox_list_path;
-	else
-		ctx->next = mbox_list_next;
 
 	if (dirp != NULL) {
 		ctx->dir = i_new(struct list_dir_context, 1);
 		ctx->dir->dirp = dirp;
 		ctx->dir->real_path = i_strdup(path);
-		ctx->dir->virtual_path = virtual_path == NULL ? NULL :
-			i_strconcat(ctx->prefix, virtual_path, NULL);
+		ctx->dir->virtual_path = i_strdup(virtual_path);
 	}
 	return &ctx->mailbox_ctx;
 }
@@ -253,7 +236,7 @@
 
 	/* check the mask */
 	if (ctx->dir->virtual_path == NULL)
-		list_path = t_strconcat(ctx->prefix, fname, NULL);
+		list_path = fname;
 	else {
 		list_path = t_strconcat(ctx->dir->virtual_path,
 					"/", fname, NULL);
@@ -303,12 +286,7 @@
 		} else if (ret < 0)
 			return -1;
 		return match > 0 || match2 > 0;
-	} else if (match > 0 &&
-		   strcmp(real_path, ctx->istorage->inbox_path) != 0 &&
-		   strcasecmp(list_path, "INBOX") != 0) {
-		/* don't match any INBOX here, it's added separately.
-		   we might also have ~/mail/inbox, ~/mail/Inbox etc.
-		   Just ignore them for now. */
+	} else if (match > 0) {
 		ctx->list.flags = noselect ? MAILBOX_NOSELECT :
 			(MAILBOX_NOINFERIORS | STAT_GET_MARKED(st));
 		ctx->list.name = p_strdup(ctx->list_pool, list_path);
@@ -318,24 +296,6 @@
 	return 0;
 }
 
-static struct mailbox_list *list_fix_name(struct mbox_list_context *ctx)
-{
-	char *p, *str, sep;
-
-	if (strchr(ctx->list.name, '/') != NULL) {
-		str = p_strdup(ctx->list_pool, ctx->list.name);
-		ctx->list.name = str;
-
-		sep = ctx->mailbox_ctx.storage->hierarchy_sep;
-		for (p = str; *p != '\0'; p++) {
-			if (*p == '/')
-				*p = sep;
-		}
-	}
-
-	return &ctx->list;
-}
-
 static struct mailbox_list *mbox_list_subs(struct mbox_list_context *ctx)
 {
 	struct stat st;
@@ -362,19 +322,17 @@
 			if (imap_match(ctx->glob, name) > 0) {
 				p_clear(ctx->list_pool);
 				ctx->list.name = p_strdup(ctx->list_pool, name);
-				return list_fix_name(ctx);
+				return &ctx->list;
 			}
 		}
 		i_unreached();
 	}
 
-        (void)list_fix_name(ctx);
 	if ((ctx->flags & MAILBOX_LIST_FAST_FLAGS) != 0)
 		return &ctx->list;
 
 	t_push();
-	name = mbox_fix_mailbox_name(ctx->istorage, ctx->list.name, TRUE);
-	path = mbox_get_path(ctx->istorage, name);
+	path = mbox_get_path(ctx->istorage, ctx->list.name);
 	if (stat(path, &st) == 0) {
 		if (S_ISDIR(st.st_mode))
 			ctx->list.flags = MAILBOX_NOSELECT | MAILBOX_CHILDREN;
@@ -383,48 +341,22 @@
 				STAT_GET_MARKED(st);
 		}
 	} else {
-		if (strcasecmp(ctx->list.name, "INBOX") == 0)
-			ctx->list.flags = MAILBOX_UNMARKED;
-		else
-			ctx->list.flags = MAILBOX_NONEXISTENT;
+		ctx->list.flags = MAILBOX_NONEXISTENT;
 	}
 	t_pop();
 	return &ctx->list;
 }
 
-static struct mailbox_list *mbox_list_inbox(struct mbox_list_context *ctx)
-{
-	struct stat st;
-
-	if (ctx->dir != NULL && ctx->dir->virtual_path != NULL)
-		ctx->next = mbox_list_path;
-	else
-		ctx->next = mbox_list_next;
-
-	/* INBOX exists always, even if the file doesn't. */
-	ctx->list.flags = strncmp(ctx->prefix, "INBOX/", 6) == 0 ?
-		MAILBOX_CHILDREN : MAILBOX_NOINFERIORS;
-	if ((ctx->flags & MAILBOX_LIST_FAST_FLAGS) == 0) {
-		if (stat(ctx->istorage->inbox_path, &st) < 0)
-			ctx->list.flags |= MAILBOX_UNMARKED;
-		else
-			ctx->list.flags |= STAT_GET_MARKED(st);
-	}
-
-	ctx->list.name = "INBOX";
-	return &ctx->list;
-}
-
 static struct mailbox_list *mbox_list_path(struct mbox_list_context *ctx)
 {
 	ctx->next = mbox_list_next;
 
 	ctx->list.flags = MAILBOX_NOSELECT | MAILBOX_CHILDREN;
-	ctx->list.name = p_strconcat(ctx->list_pool, ctx->prefix,
-				     ctx->dir->virtual_path, "/", NULL);
+	ctx->list.name =
+		p_strconcat(ctx->list_pool, ctx->dir->virtual_path, "/", NULL);
 
 	if (imap_match(ctx->glob, ctx->list.name) > 0)
-		return list_fix_name(ctx);
+		return &ctx->list;
 	else
 		return ctx->next(ctx);
 }
@@ -445,7 +377,7 @@
 			t_pop();
 
 			if (ret > 0)
-				return list_fix_name(ctx);
+				return &ctx->list;
 			if (ret < 0) {
 				ctx->failed = TRUE;
 				return NULL;
@@ -460,9 +392,3 @@
 	/* finished */
 	return NULL;
 }
-
-static struct mailbox_list *
-mbox_list_none(struct mbox_list_context *ctx __attr_unused__)
-{
-	return NULL;
-}

Index: mbox-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -d -r1.89 -r1.90
--- mbox-storage.c	20 Jul 2004 18:45:43 -0000	1.89
+++ mbox-storage.c	22 Jul 2004 21:20:01 -0000	1.90
@@ -150,9 +150,7 @@
 	return path;
 }
 
-static struct mail_storage *
-mbox_create(const char *data, const char *user,
-	    const char *namespace, char hierarchy_sep)
+static struct mail_storage *mbox_create(const char *data, const char *user)
 {
 	struct index_storage *storage;
 	const char *root_dir, *inbox_file, *index_dir, *p;
@@ -224,10 +222,6 @@
 	storage = i_new(struct index_storage, 1);
 	storage->storage = mbox_storage;
 
-	if (hierarchy_sep != '\0')
-		storage->storage.hierarchy_sep = hierarchy_sep;
-	storage->storage.namespace = i_strdup(namespace);
-
 	storage->dir = i_strdup(home_expand(root_dir));
 	storage->inbox_path = i_strdup(home_expand(inbox_file));
 	storage->index_dir = i_strdup(home_expand(index_dir));
@@ -251,47 +245,6 @@
 	i_free(storage);
 }
 
-const char *mbox_fix_mailbox_name(struct index_storage *istorage,
-				  const char *name, int remove_namespace)
-{
-        struct mail_storage *storage = &istorage->storage;
-	char *dup, *p, sep;
-	size_t len;
-
-	if (strncasecmp(name, "INBOX", 5) == 0 &&
-	    (name[5] == '\0' || name[5] == storage->hierarchy_sep)) {
-		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 == '/')
-		return name;
-
-	dup = t_strdup_noconst(name);
-	for (p = dup; *p != '\0'; p++) {
-		if (*p == sep)
-			*p = '/';
-	}
-
-	return dup;
-}
-
 int mbox_is_valid_mask(const char *mask)
 {
 	const char *p;
@@ -390,8 +343,8 @@
 	if (fd != -1)
 		(void)close(fd);
 	else if (errno != EEXIST) {
-		mail_storage_set_critical(storage,
-			"open(%s, O_CREAT) failed: %m", storage->inbox_file);
+		mail_storage_set_critical(&storage->storage,
+			"open(%s, O_CREAT) failed: %m", storage->inbox_path);
 	}
 
 	/* make sure the index directories exist */
@@ -404,7 +357,7 @@
 static const char *
 mbox_get_path(struct index_storage *storage, const char *name)
 {
-	if (strcasecmp(name, "INBOX") == 0)
+	if (strcmp(name, "INBOX") == 0)
 		return storage->inbox_path;
 	if (full_filesystem_access && (*name == '/' || *name == '~'))
 		return home_expand(name);
@@ -434,7 +387,7 @@
 	const char *path, *index_dir;
 	uint32_t mbox_extra_idx;
 
-	if (strcasecmp(name, "INBOX") == 0) {
+	if (strcmp(name, "INBOX") == 0) {
 		/* name = "INBOX"
 		   path = "<inbox_file>/INBOX"
 		   index_dir = "/mail/.imap/INBOX" */
@@ -487,11 +440,8 @@
 
 	mail_storage_clear_error(_storage);
 
-	name = mbox_fix_mailbox_name(storage, name, TRUE);
-
-	/* INBOX is always case-insensitive */
-	if (strcasecmp(name, "INBOX") == 0) {
-		/* make sure inbox exists */
+	if (strcmp(name, "INBOX") == 0) {
+		/* make sure INBOX exists */
 		if (verify_inbox(storage) < 0)
 			return NULL;
 		return mbox_open(storage, "INBOX", flags);
@@ -538,8 +488,6 @@
 
 	mail_storage_clear_error(_storage);
 
-	name = mbox_fix_mailbox_name(storage, name, TRUE);
-
 	if (!mbox_is_valid_create_name(name)) {
 		mail_storage_set_error(_storage, "Invalid mailbox name");
 		return -1;
@@ -607,9 +555,7 @@
 
 	mail_storage_clear_error(_storage);
 
-	name = mbox_fix_mailbox_name(storage, name, TRUE);
-
-	if (strcasecmp(name, "INBOX") == 0) {
+	if (strcmp(name, "INBOX") == 0) {
 		mail_storage_set_error(_storage, "INBOX can't be deleted.");
 		return -1;
 	}
@@ -701,9 +647,6 @@
 
 	mail_storage_clear_error(_storage);
 
-	oldname = mbox_fix_mailbox_name(storage, oldname, TRUE);
-	newname = mbox_fix_mailbox_name(storage, newname, TRUE);
-
 	if (!mbox_is_valid_existing_name(oldname) ||
 	    !mbox_is_valid_create_name(newname)) {
 		mail_storage_set_error(_storage, "Invalid mailbox name");
@@ -780,7 +723,6 @@
 	const char *path;
 
 	path = t_strconcat(storage->dir, "/" SUBSCRIPTION_FILE_NAME, NULL);
-	name = mbox_fix_mailbox_name(storage, name, FALSE);
 	return subsfile_set_subscribed(_storage, path, storage->temp_prefix,
 				       name, set);
 }
@@ -795,8 +737,6 @@
 
 	mail_storage_clear_error(_storage);
 
-	name = mbox_fix_mailbox_name(storage, name, TRUE);
-
 	if (!mbox_is_valid_existing_name(name)) {
 		*status = MAILBOX_NAME_INVALID;
 		return 0;
@@ -853,9 +793,8 @@
 
 struct mail_storage mbox_storage = {
 	"mbox", /* name */
-	NULL, /* namespace */
 
-	'/', /* default hierarchy separator */
+	'/', /* hierarchy separator */
 
 	mbox_create,
 	mbox_free,

Index: mbox-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mbox-storage.h	12 Jul 2004 11:35:51 -0000	1.25
+++ mbox-storage.h	22 Jul 2004 21:20:01 -0000	1.26
@@ -24,7 +24,8 @@
 int mbox_set_syscall_error(struct index_mailbox *ibox, const char *function);
 
 struct mailbox_list_context *
-mbox_mailbox_list_init(struct mail_storage *storage, const char *mask,
+mbox_mailbox_list_init(struct mail_storage *storage,
+		       const char *ref, const char *mask,
 		       enum mailbox_list_flags flags);
 int mbox_mailbox_list_deinit(struct mailbox_list_context *ctx);
 struct mailbox_list *mbox_mailbox_list_next(struct mailbox_list_context *ctx);
@@ -45,8 +46,6 @@
 int mbox_save_commit(struct mbox_save_context *ctx);
 void mbox_save_rollback(struct mbox_save_context *ctx);
 
-const char *mbox_fix_mailbox_name(struct index_storage *istorage,
-				  const char *name, int remove_namespace);
 int mbox_is_valid_mask(const char *mask);
 
 #endif



More information about the dovecot-cvs mailing list