changeset 8468:d4eab639c253 HEAD

mailbox_open() now takes struct mail_storage ** so it can be changed.
author Timo Sirainen <tss@iki.fi>
date Fri, 21 Nov 2008 19:24:04 +0200
parents 03c418eadc8b
children e2ec45b71119
files src/deliver/deliver.c src/imap/cmd-append.c src/imap/cmd-copy.c src/imap/cmd-select.c src/imap/imap-status.c src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/plugins/convert/convert-storage.c src/plugins/expire/expire-tool.c src/plugins/imap-acl/imap-acl-plugin.c src/plugins/imap-quota/imap-quota-plugin.c src/plugins/lazy-expunge/lazy-expunge-plugin.c src/plugins/mbox-snarf/mbox-snarf-plugin.c src/plugins/quota/quota-count.c src/plugins/quota/quota-storage.c src/plugins/trash/trash-plugin.c src/plugins/virtual/virtual-storage.c src/pop3/client.c
diffstat 18 files changed, 49 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/deliver/deliver.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/deliver/deliver.c	Fri Nov 21 19:24:04 2008 +0200
@@ -172,16 +172,16 @@
 		return NULL;
 	}
 
-	box = mailbox_open(ns->storage, name, NULL, open_flags);
+	box = mailbox_open(storage_r, name, NULL, open_flags);
 	if (box != NULL || !deliver_set->mailbox_autocreate)
 		return box;
 
-	(void)mail_storage_get_last_error(ns->storage, &error);
+	(void)mail_storage_get_last_error(*storage_r, &error);
 	if (error != MAIL_ERROR_NOTFOUND)
 		return NULL;
 
 	/* try creating it. */
-	if (mail_storage_mailbox_create(ns->storage, name, FALSE) < 0)
+	if (mail_storage_mailbox_create(*storage_r, name, FALSE) < 0)
 		return NULL;
 	if (deliver_set->mailbox_autosubscribe) {
 		/* (try to) subscribe to it */
@@ -189,7 +189,7 @@
 	}
 
 	/* and try opening again */
-	box = mailbox_open(ns->storage, name, NULL, open_flags);
+	box = mailbox_open(storage_r, name, NULL, open_flags);
 	if (box == NULL)
 		return NULL;
 
@@ -1082,12 +1082,12 @@
 		i_fatal("Couldn't create internal raw storage: %s", errstr);
 	if (path == NULL) {
 		input = create_raw_stream(0, &mtime);
-		box = mailbox_open(raw_ns->storage, "Dovecot Delivery Mail",
+		box = mailbox_open(&raw_ns->storage, "Dovecot Delivery Mail",
 				   input, MAILBOX_OPEN_NO_INDEX_FILES);
 		i_stream_unref(&input);
 	} else {
 		mtime = (time_t)-1;
-		box = mailbox_open(raw_ns->storage, path, NULL,
+		box = mailbox_open(&raw_ns->storage, path, NULL,
 				   MAILBOX_OPEN_NO_INDEX_FILES);
 	}
 	if (box == NULL)
--- a/src/imap/cmd-append.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/imap/cmd-append.c	Fri Nov 21 19:24:04 2008 +0200
@@ -445,7 +445,7 @@
 	    mailbox_equals(cmd->client->mailbox, storage, name))
 		return cmd->client->mailbox;
 
-	box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_SAVEONLY |
+	box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_SAVEONLY |
 			   MAILBOX_OPEN_FAST | MAILBOX_OPEN_KEEP_RECENT);
 	if (box == NULL) {
 		client_send_storage_error(cmd, storage);
--- a/src/imap/cmd-copy.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/imap/cmd-copy.c	Fri Nov 21 19:24:04 2008 +0200
@@ -121,7 +121,7 @@
 	if (mailbox_equals(client->mailbox, storage, mailbox))
 		destbox = client->mailbox;
 	else {
-		destbox = mailbox_open(storage, mailbox, NULL,
+		destbox = mailbox_open(&storage, mailbox, NULL,
 				       MAILBOX_OPEN_SAVEONLY |
 				       MAILBOX_OPEN_FAST |
 				       MAILBOX_OPEN_KEEP_RECENT);
--- a/src/imap/cmd-select.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/imap/cmd-select.c	Fri Nov 21 19:24:04 2008 +0200
@@ -264,7 +264,7 @@
 
 	if (readonly)
 		open_flags |= MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT;
-	ctx->box = mailbox_open(ctx->storage, mailbox, NULL, open_flags);
+	ctx->box = mailbox_open(&ctx->storage, mailbox, NULL, open_flags);
 	if (ctx->box == NULL)
 		return -1;
 
--- a/src/imap/imap-status.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/imap/imap-status.c	Fri Nov 21 19:24:04 2008 +0200
@@ -61,7 +61,7 @@
 	}
 
 	/* open the mailbox */
-	box = mailbox_open(storage, mailbox, NULL, MAILBOX_OPEN_FAST |
+	box = mailbox_open(&storage, mailbox, NULL, MAILBOX_OPEN_FAST |
 			   MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
 	if (box == NULL)
 		return FALSE;
--- a/src/lib-storage/mail-storage.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/lib-storage/mail-storage.c	Fri Nov 21 19:24:04 2008 +0200
@@ -441,10 +441,11 @@
 	return TRUE;
 }
 
-struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
+struct mailbox *mailbox_open(struct mail_storage **_storage, const char *name,
 			     struct istream *input,
 			     enum mailbox_open_flags flags)
 {
+	struct mail_storage *storage = *_storage;
 	struct mailbox *box;
 
 	mail_storage_clear_error(storage);
@@ -460,6 +461,9 @@
 		if (hook_mailbox_opened != NULL && box != NULL)
 			hook_mailbox_opened(box);
 	} T_END;
+
+	if (box != NULL)
+		*_storage = box->storage;
 	return box;
 }
 
--- a/src/lib-storage/mail-storage.h	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/lib-storage/mail-storage.h	Fri Nov 21 19:24:04 2008 +0200
@@ -305,8 +305,11 @@
    tried to be used, NULL is returned.
 
    Note that append and copy may open the selected mailbox again
-   with possibly different readonly-state. */
-struct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
+   with possibly different readonly-state.
+
+   Given storage is a pointer-to-pointer because it may change as a result of
+   a new namespace being created for shared mailboxes. */
+struct mailbox *mailbox_open(struct mail_storage **storage, const char *name,
 			     struct istream *input,
 			     enum mailbox_open_flags flags);
 /* Close the box. Returns -1 if some cleanup errors occurred, but
--- a/src/plugins/convert/convert-storage.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/convert/convert-storage.c	Fri Nov 21 19:24:04 2008 +0200
@@ -282,7 +282,7 @@
 
 	/* First open the source mailbox. If we can't open it, don't create
 	   the destination mailbox either. */
-	srcbox = mailbox_open(source_storage, name, NULL,
+	srcbox = mailbox_open(&source_storage, name, NULL,
 			      MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
 	if (srcbox == NULL) {
 		if (set->skip_broken_mailboxes)
@@ -306,7 +306,7 @@
 		}
 	}
 
-	destbox = mailbox_open(dest_storage, dest_name, NULL,
+	destbox = mailbox_open(&dest_storage, dest_name, NULL,
 			       MAILBOX_OPEN_KEEP_RECENT);
 	if (destbox == NULL) {
 		i_error("Mailbox conversion: Couldn't open dest mailbox %s: %s",
--- a/src/plugins/expire/expire-tool.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/expire/expire-tool.c	Fri Nov 21 19:24:04 2008 +0200
@@ -64,6 +64,7 @@
 			 time_t *oldest_r)
 {
 	struct mail_namespace *ns;
+	struct mail_storage *storage;
 	struct mailbox *box;
 	struct mail_search_context *search_ctx;
 	struct mailbox_transaction_context *t;
@@ -97,9 +98,10 @@
 		return 0;
 	}
 
-	box = mailbox_open(ns->storage, ns_mailbox, NULL, 0);
+	storage = ns->storage;
+	box = mailbox_open(&storage, ns_mailbox, NULL, 0);
 	if (box == NULL) {
-		errstr = mail_storage_get_last_error(ns->storage, &error);
+		errstr = mail_storage_get_last_error(storage, &error);
 		if (error != MAIL_ERROR_NOTFOUND) {
 			i_error("%s: Opening mailbox %s failed: %s",
 				user, mailbox, errstr);
--- a/src/plugins/imap-acl/imap-acl-plugin.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/imap-acl/imap-acl-plugin.c	Fri Nov 21 19:24:04 2008 +0200
@@ -61,7 +61,7 @@
 
 	/* Force opening the mailbox so that we can give a nicer error message
 	   if mailbox isn't selectable but is listable. */
-	box = mailbox_open(storage, name, NULL, ACL_MAILBOX_OPEN_FLAGS |
+	box = mailbox_open(&storage, name, NULL, ACL_MAILBOX_OPEN_FLAGS |
 			   MAILBOX_OPEN_IGNORE_ACLS);
 	if (box == NULL) {
 		client_send_storage_error(cmd, storage);
@@ -232,8 +232,8 @@
 	if (storage == NULL)
 		return TRUE;
 
-	box = mailbox_open(storage, real_mailbox, NULL, ACL_MAILBOX_OPEN_FLAGS |
-			   MAILBOX_OPEN_IGNORE_ACLS);
+	box = mailbox_open(&storage, real_mailbox, NULL,
+			   ACL_MAILBOX_OPEN_FLAGS | MAILBOX_OPEN_IGNORE_ACLS);
 	if (box == NULL) {
 		client_send_storage_error(cmd, storage);
 		return TRUE;
--- a/src/plugins/imap-quota/imap-quota-plugin.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/imap-quota/imap-quota-plugin.c	Fri Nov 21 19:24:04 2008 +0200
@@ -63,9 +63,9 @@
 	if (storage == NULL)
 		return TRUE;
 
-	box = mailbox_open(storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
-						    MAILBOX_OPEN_FAST |
-						    MAILBOX_OPEN_KEEP_RECENT));
+	box = mailbox_open(&storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
+						     MAILBOX_OPEN_FAST |
+						     MAILBOX_OPEN_KEEP_RECENT));
 	if (box == NULL) {
 		client_send_storage_error(cmd, storage);
 		return TRUE;
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Fri Nov 21 19:24:04 2008 +0200
@@ -82,7 +82,7 @@
 	struct mailbox *box;
 	enum mail_error error;
 
-	box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
+	box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
 			   MAILBOX_OPEN_KEEP_RECENT |
 			   MAILBOX_OPEN_NO_INDEX_FILES);
 	if (box != NULL)
@@ -97,7 +97,7 @@
 		return NULL;
 
 	/* and try opening again */
-	box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST |
+	box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
 			   MAILBOX_OPEN_KEEP_RECENT);
 	return box;
 }
--- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Fri Nov 21 19:24:04 2008 +0200
@@ -100,13 +100,15 @@
 {
 	struct mbox_snarf_mail_storage *mstorage =
 		MBOX_SNARF_CONTEXT(box->storage);
+	struct mail_storage *storage;
 	struct mbox_snarf_mailbox *mbox = MBOX_SNARF_CONTEXT(box);
 
 	if (mbox->spool_mbox == NULL) {
 		/* try to open the spool mbox */
 		mstorage->open_spool_inbox = TRUE;
+		storage = box->storage;
 		mbox->spool_mbox =
-			mailbox_open(box->storage, "INBOX", NULL,
+			mailbox_open(&storage, "INBOX", NULL,
 				     MAILBOX_OPEN_KEEP_RECENT |
 				     MAILBOX_OPEN_NO_INDEX_FILES);
 		mstorage->open_spool_inbox = FALSE;
--- a/src/plugins/quota/quota-count.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/quota/quota-count.c	Fri Nov 21 19:24:04 2008 +0200
@@ -25,7 +25,7 @@
 		return 0;
 	}
 
-	box = mailbox_open(storage, name, NULL,
+	box = mailbox_open(&storage, name, NULL,
 			   MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
 	if (box == NULL)
 		return -1;
--- a/src/plugins/quota/quota-storage.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/quota/quota-storage.c	Fri Nov 21 19:24:04 2008 +0200
@@ -433,6 +433,7 @@
 quota_mailbox_list_delete(struct mailbox_list *list, const char *name)
 {
 	struct quota_mailbox_list *qlist = QUOTA_LIST_CONTEXT(list);
+	struct mail_storage *storage;
 	struct mailbox *box;
 	enum mail_error error;
 	const char *str;
@@ -442,7 +443,8 @@
 	   and free the quota for all the messages existing in it. Open the
 	   mailbox locked so that other processes can't mess up the quota
 	   calculations by adding/removing mails while we're doing this. */
-	box = mailbox_open(qlist->storage, name, NULL, MAILBOX_OPEN_FAST |
+	storage = qlist->storage;
+	box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_FAST |
 			   MAILBOX_OPEN_KEEP_RECENT | MAILBOX_OPEN_KEEP_LOCKED);
 	if (box == NULL) {
 		str = mail_storage_get_last_error(qlist->storage, &error);
--- a/src/plugins/trash/trash-plugin.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/trash/trash-plugin.c	Fri Nov 21 19:24:04 2008 +0200
@@ -52,9 +52,10 @@
 
 static int trash_clean_mailbox_open(struct trash_mailbox *trash)
 {
+	struct mail_storage *storage = trash->storage;
 	struct mail_search_args *search_args;
 
-	trash->box = mailbox_open(trash->storage, trash->name, NULL,
+	trash->box = mailbox_open(&storage, trash->name, NULL,
 				  MAILBOX_OPEN_KEEP_RECENT);
 	if (trash->box == NULL)
 		return 0;
--- a/src/plugins/virtual/virtual-storage.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/plugins/virtual/virtual-storage.c	Fri Nov 21 19:24:04 2008 +0200
@@ -200,6 +200,7 @@
 	struct mail_user *user = mbox->storage->storage.ns->user;
 	struct virtual_backend_box *const *bboxes;
 	struct mail_namespace *ns;
+	struct mail_storage *storage;
 	unsigned int i, count;
 	enum mail_error error;
 	const char *str, *mailbox;
@@ -210,13 +211,14 @@
 	for (i = 0; i < count; i++) {
 		mailbox = bboxes[i]->name;
 		ns = mail_namespace_find(user->namespaces, &mailbox);
-		bboxes[i]->box = mailbox_open(ns->storage, mailbox,
+		storage = ns->storage;
+		bboxes[i]->box = mailbox_open(&storage, mailbox,
 					      NULL, open_flags);
 
 		if (bboxes[i]->box == NULL) {
-			if (ns->storage != mbox->ibox.box.storage) {
+			if (storage != mbox->ibox.box.storage) {
 				/* copy the error */
-				str = mail_storage_get_last_error(ns->storage,
+				str = mail_storage_get_last_error(storage,
 								  &error);
 				mail_storage_set_error(mbox->ibox.box.storage,
 						       error, str);
--- a/src/pop3/client.c	Fri Nov 21 18:32:02 2008 +0200
+++ b/src/pop3/client.c	Fri Nov 21 19:24:04 2008 +0200
@@ -180,7 +180,7 @@
 		flags |= MAILBOX_OPEN_KEEP_RECENT;
 	if (lock_session)
 		flags |= MAILBOX_OPEN_KEEP_LOCKED;
-	client->mailbox = mailbox_open(storage, "INBOX", NULL, flags);
+	client->mailbox = mailbox_open(&storage, "INBOX", NULL, flags);
 	if (client->mailbox == NULL) {
 		errmsg = t_strdup_printf("Couldn't open INBOX: %s",
 				mail_storage_get_last_error(storage,