changeset 13125:4dca25ea4a1c

lib-storage: Added auto_boxes parameter to mailbox_exists().
author Timo Sirainen <tss@iki.fi>
date Fri, 29 Jul 2011 14:29:01 +0300
parents 45e3d5be6ed8
children 0a0f962c1a6f
files src/imap/cmd-subscribe.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/list/mailbox-list-fs-iter.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/lib-storage/test-mailbox.c src/plugins/acl/acl-mailbox.c src/plugins/autocreate/autocreate-plugin.c src/plugins/virtual/virtual-storage.c
diffstat 12 files changed, 37 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-subscribe.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/imap/cmd-subscribe.c	Fri Jul 29 14:29:01 2011 +0300
@@ -11,7 +11,7 @@
 	enum mailbox_existence existence;
 	int ret;
 
-	if ((ret = mailbox_exists(box, &existence)) < 0) {
+	if ((ret = mailbox_exists(box, TRUE, &existence)) < 0) {
 		client_send_storage_error(cmd, mailbox_get_storage(box));
 		return FALSE;
 	}
--- a/src/lib-storage/index/index-storage.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/index/index-storage.c	Fri Jul 29 14:29:01 2011 +0300
@@ -151,20 +151,23 @@
 					  box->index_prefix);
 }
 
-int index_storage_mailbox_exists(struct mailbox *box,
+int index_storage_mailbox_exists(struct mailbox *box, bool auto_boxes,
 				 enum mailbox_existence *existence_r)
 {
-	return index_storage_mailbox_exists_full(box, NULL, existence_r);
+	return index_storage_mailbox_exists_full(box, auto_boxes,
+						 NULL, existence_r);
 }
 
-int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir,
+int index_storage_mailbox_exists_full(struct mailbox *box, bool auto_boxes,
+				      const char *subdir,
 				      enum mailbox_existence *existence_r)
 {
 	struct stat st;
 	const char *path, *path2;
 
 	if (strcmp(box->name, "INBOX") == 0 &&
-	    (box->list->ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0) {
+	    (box->list->ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 &&
+	    auto_boxes) {
 		/* INBOX always exists */
 		*existence_r = MAILBOX_EXISTENCE_SELECT;
 		return 0;
--- a/src/lib-storage/index/index-storage.h	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/index/index-storage.h	Fri Jul 29 14:29:01 2011 +0300
@@ -57,9 +57,10 @@
 void index_storage_mailbox_alloc(struct mailbox *box, const char *vname,
 				 enum mailbox_flags flags,
 				 const char *index_prefix);
-int index_storage_mailbox_exists(struct mailbox *box,
+int index_storage_mailbox_exists(struct mailbox *box, bool auto_boxes,
 				 enum mailbox_existence *existence_r);
-int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir,
+int index_storage_mailbox_exists_full(struct mailbox *box, bool auto_boxes,
+				      const char *subdir,
 				      enum mailbox_existence *existence_r);
 int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory);
 int index_storage_mailbox_enable(struct mailbox *box,
--- a/src/lib-storage/index/maildir/maildir-storage.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Fri Jul 29 14:29:01 2011 +0300
@@ -323,10 +323,11 @@
 	return FALSE;
 }
 
-static int maildir_mailbox_exists(struct mailbox *box,
+static int maildir_mailbox_exists(struct mailbox *box, bool auto_boxes,
 				  enum mailbox_existence *existence_r)
 {
-	return index_storage_mailbox_exists_full(box, "cur", existence_r);
+	return index_storage_mailbox_exists_full(box, auto_boxes,
+						 "cur", existence_r);
 }
 
 static int maildir_mailbox_open(struct mailbox *box)
--- a/src/lib-storage/list/mailbox-list-fs-iter.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/list/mailbox-list-fs-iter.c	Fri Jul 29 14:29:01 2011 +0300
@@ -563,10 +563,12 @@
 	if (!MAILBOX_INFO_FLAGS_FINISHED(ctx->info.flags)) {
 		struct mailbox *box;
 		enum mailbox_existence existence;
+		bool auto_boxes =
+			(ctx->ctx.flags & MAILBOX_LIST_ITER_NO_AUTO_BOXES) == 0;
 
 		box = mailbox_alloc(ctx->ctx.list, list_path,
 				    MAILBOX_FLAG_KEEP_RECENT);
-		ret = mailbox_exists(box, &existence);
+		ret = mailbox_exists(box, auto_boxes, &existence);
 		mailbox_free(&box);
 
 		if (ret < 0) {
--- a/src/lib-storage/mail-storage-private.h	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/mail-storage-private.h	Fri Jul 29 14:29:01 2011 +0300
@@ -107,7 +107,8 @@
 	bool (*is_readonly)(struct mailbox *box);
 
 	int (*enable)(struct mailbox *box, enum mailbox_feature features);
-	int (*exists)(struct mailbox *box, enum mailbox_existence *existence_r);
+	int (*exists)(struct mailbox *box, bool auto_boxes,
+		      enum mailbox_existence *existence_r);
 	int (*open)(struct mailbox *box);
 	void (*close)(struct mailbox *box);
 	void (*free)(struct mailbox *box);
--- a/src/lib-storage/mail-storage.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/mail-storage.c	Fri Jul 29 14:29:01 2011 +0300
@@ -622,7 +622,8 @@
 	return FALSE;
 }
 
-int mailbox_exists(struct mailbox *box, enum mailbox_existence *existence_r)
+int mailbox_exists(struct mailbox *box, bool auto_boxes,
+		   enum mailbox_existence *existence_r)
 {
 	if (!mailbox_list_is_valid_existing_name(box->list, box->name)) {
 		/* report it as not selectable, since it exists but we won't
@@ -638,7 +639,7 @@
 		return 0;
 	}
 
-	return box->v.exists(box, existence_r);
+	return box->v.exists(box, auto_boxes, existence_r);
 }
 
 static int mailbox_check_mismatching_separators(struct mailbox *box)
--- a/src/lib-storage/mail-storage.h	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/mail-storage.h	Fri Jul 29 14:29:01 2011 +0300
@@ -365,8 +365,11 @@
    with possibly different readonly-state. */
 struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname,
 			      enum mailbox_flags flags);
-/* Get mailbox existence state */
-int mailbox_exists(struct mailbox *box, enum mailbox_existence *existence_r);
+/* Get mailbox existence state. If auto_boxes=FALSE, return
+   MAILBOX_EXISTENCE_NONE for autocreated mailboxes that haven't been
+   physically created yet */
+int mailbox_exists(struct mailbox *box, bool auto_boxes,
+		   enum mailbox_existence *existence_r);
 /* Open the mailbox. If this function isn't called explicitly, it's also called
    internally by lib-storage when necessary. */
 int mailbox_open(struct mailbox *box);
--- a/src/lib-storage/test-mailbox.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/lib-storage/test-mailbox.c	Fri Jul 29 14:29:01 2011 +0300
@@ -21,6 +21,7 @@
 }
 
 static int test_mailbox_exists(struct mailbox *box ATTR_UNUSED,
+			       bool auto_boxes ATTR_UNUSED,
 			       enum mailbox_existence *existence_r)
 {
 	*existence_r = MAILBOX_EXISTENCE_SELECT;
--- a/src/plugins/acl/acl-mailbox.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/plugins/acl/acl-mailbox.c	Fri Jul 29 14:29:01 2011 +0300
@@ -412,7 +412,7 @@
 	return abox->module_ctx.super.transaction_commit(ctx, changes_r);
 }
 
-static int acl_mailbox_exists(struct mailbox *box,
+static int acl_mailbox_exists(struct mailbox *box, bool auto_boxes,
 			      enum mailbox_existence *existence_r)
 {
 	struct acl_mailbox *abox = ACL_CONTEXT(box);
@@ -432,7 +432,8 @@
 		if (strcmp(rights[i], MAIL_ACL_LOOKUP) == 0 ||
 		    strcmp(rights[i], MAIL_ACL_READ) == 0 ||
 		    strcmp(rights[i], MAIL_ACL_INSERT) == 0)
-			return abox->module_ctx.super.exists(box, existence_r);
+			return abox->module_ctx.super.exists(box, auto_boxes,
+							     existence_r);
 	}
 	*existence_r = MAILBOX_EXISTENCE_NONE;
 	return 0;
--- a/src/plugins/autocreate/autocreate-plugin.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/plugins/autocreate/autocreate-plugin.c	Fri Jul 29 14:29:01 2011 +0300
@@ -133,17 +133,17 @@
 	return ret;
 }
 
-static int autocreate_mailbox_exists(struct mailbox *box,
+static int autocreate_mailbox_exists(struct mailbox *box, bool auto_boxes,
 				     enum mailbox_existence *existence_r)
 {
 	union mailbox_module_context *abox = AUTOCREATE_CONTEXT(box);
 
-	if (is_autocreated(box->storage->user, box->vname)) {
+	if (auto_boxes && is_autocreated(box->storage->user, box->vname)) {
 		*existence_r = MAILBOX_EXISTENCE_SELECT;
 		return 0;
 	}
 
-	return abox->super.exists(box, existence_r);
+	return abox->super.exists(box, auto_boxes, existence_r);
 }
 
 static int
--- a/src/plugins/virtual/virtual-storage.c	Fri Jul 29 14:21:13 2011 +0300
+++ b/src/plugins/virtual/virtual-storage.c	Fri Jul 29 14:29:01 2011 +0300
@@ -259,10 +259,11 @@
 	}
 }
 
-static int virtual_mailbox_exists(struct mailbox *box,
+static int virtual_mailbox_exists(struct mailbox *box, bool auto_boxes,
 				  enum mailbox_existence *existence_r)
 {
-	return index_storage_mailbox_exists_full(box, VIRTUAL_CONFIG_FNAME,
+	return index_storage_mailbox_exists_full(box, auto_boxes,
+						 VIRTUAL_CONFIG_FNAME,
 						 existence_r);
 }