dovecot-1.2: mailbox_open() now takes struct mail_storage ** so ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 21 19:46:23 EET 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/d4eab639c253
changeset: 8468:d4eab639c253
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 21 19:24:04 2008 +0200
description:
mailbox_open() now takes struct mail_storage ** so it can be changed.

diffstat:

18 files changed, 49 insertions(+), 33 deletions(-)
src/deliver/deliver.c                          |   12 ++++++------
src/imap/cmd-append.c                          |    2 +-
src/imap/cmd-copy.c                            |    2 +-
src/imap/cmd-select.c                          |    2 +-
src/imap/imap-status.c                         |    2 +-
src/lib-storage/mail-storage.c                 |    6 +++++-
src/lib-storage/mail-storage.h                 |    7 +++++--
src/plugins/convert/convert-storage.c          |    4 ++--
src/plugins/expire/expire-tool.c               |    6 ++++--
src/plugins/imap-acl/imap-acl-plugin.c         |    6 +++---
src/plugins/imap-quota/imap-quota-plugin.c     |    6 +++---
src/plugins/lazy-expunge/lazy-expunge-plugin.c |    4 ++--
src/plugins/mbox-snarf/mbox-snarf-plugin.c     |    4 +++-
src/plugins/quota/quota-count.c                |    2 +-
src/plugins/quota/quota-storage.c              |    4 +++-
src/plugins/trash/trash-plugin.c               |    3 ++-
src/plugins/virtual/virtual-storage.c          |    8 +++++---
src/pop3/client.c                              |    2 +-

diffs (truncated from 352 to 300 lines):

diff -r 03c418eadc8b -r d4eab639c253 src/deliver/deliver.c
--- 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 @@ mailbox_open_or_create_synced(struct mai
 		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 @@ mailbox_open_or_create_synced(struct mai
 	}
 
 	/* 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 @@ int main(int argc, char *argv[])
 		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)
diff -r 03c418eadc8b -r d4eab639c253 src/imap/cmd-append.c
--- 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 @@ get_mailbox(struct client_command_contex
 	    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);
diff -r 03c418eadc8b -r d4eab639c253 src/imap/cmd-copy.c
--- 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 @@ bool cmd_copy(struct client_command_cont
 	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);
diff -r 03c418eadc8b -r d4eab639c253 src/imap/cmd-select.c
--- 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 @@ select_open(struct imap_select_context *
 
 	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;
 
diff -r 03c418eadc8b -r d4eab639c253 src/imap/imap-status.c
--- 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 @@ bool imap_status_get(struct client *clie
 	}
 
 	/* 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;
diff -r 03c418eadc8b -r d4eab639c253 src/lib-storage/mail-storage.c
--- 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 @@ bool mail_storage_set_error_from_errno(s
 	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 @@ struct mailbox *mailbox_open(struct mail
 		if (hook_mailbox_opened != NULL && box != NULL)
 			hook_mailbox_opened(box);
 	} T_END;
+
+	if (box != NULL)
+		*_storage = box->storage;
 	return box;
 }
 
diff -r 03c418eadc8b -r d4eab639c253 src/lib-storage/mail-storage.h
--- 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 @@ const char *mail_storage_get_mailbox_ind
    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
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/convert/convert-storage.c
--- 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 @@ static int mailbox_convert_list_item(str
 
 	/* 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 @@ static int mailbox_convert_list_item(str
 		}
 	}
 
-	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",
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/expire/expire-tool.c
--- 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 @@ mailbox_delete_old_mails(struct expire_c
 			 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 @@ mailbox_delete_old_mails(struct expire_c
 		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);
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/imap-acl/imap-acl-plugin.c
--- 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 @@ acl_mailbox_open_as_admin(struct client_
 
 	/* 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 @@ static bool cmd_myrights(struct client_c
 	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;
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/imap-quota/imap-quota-plugin.c
--- 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 @@ static bool cmd_getquotaroot(struct clie
 	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;
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/lazy-expunge/lazy-expunge-plugin.c
--- 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 @@ mailbox_open_or_create(struct mail_stora
 	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 @@ mailbox_open_or_create(struct mail_stora
 		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;
 }
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/mbox-snarf/mbox-snarf-plugin.c
--- 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 @@ mbox_snarf_sync_init(struct mailbox *box
 {
 	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;
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/quota/quota-count.c
--- 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 @@ quota_count_mailbox(struct quota_root *r
 		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;
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/quota/quota-storage.c
--- 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
 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 @@ quota_mailbox_list_delete(struct mailbox
 	   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);
diff -r 03c418eadc8b -r d4eab639c253 src/plugins/trash/trash-plugin.c
--- 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_next_quota_test_alloc


More information about the dovecot-cvs mailing list