changeset 10662:8b138b29dc01 HEAD

lib-storage: Split mailbox_close() and mailbox_free() functionality.
author Timo Sirainen <tss@iki.fi>
date Sun, 07 Feb 2010 17:50:08 +0200
parents bd06d9b159fa
children c919c72033f8
files src/doveadm/doveadm-mail.c src/dsync/dsync-worker-local.c src/imap/cmd-append.c src/imap/cmd-close.c src/imap/cmd-copy.c src/imap/cmd-create.c src/imap/cmd-delete.c src/imap/cmd-logout.c src/imap/cmd-select.c src/imap/cmd-unselect.c src/imap/imap-client.c src/imap/imap-status.c src/lda/main.c src/lib-index/mail-index-alloc-cache.c src/lib-index/mail-index-alloc-cache.h src/lib-lda/mail-deliver.c src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c src/lib-storage/index/dbox-multi/mdbox-storage.c src/lib-storage/index/index-storage.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/lmtp/client.c src/lmtp/commands.c src/plugins/autocreate/autocreate-plugin.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/pop3-client.c
diffstat 35 files changed, 116 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-mail.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/doveadm/doveadm-mail.c	Sun Feb 07 17:50:08 2010 +0200
@@ -72,7 +72,7 @@
 		i_fatal("Forcing a resync on mailbox %s failed: %s", mailbox,
 			mail_storage_get_last_error(storage, NULL));
 	}
-	mailbox_close(&box);
+	mailbox_free(&box);
 }
 
 static void
--- a/src/dsync/dsync-worker-local.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/dsync/dsync-worker-local.c	Sun Feb 07 17:50:08 2010 +0200
@@ -510,7 +510,7 @@
 
 		i_error("Failed to sync mailbox %s: %s", info->name,
 			mail_storage_get_last_error(storage, NULL));
-		mailbox_close(&box);
+		mailbox_free(&box);
 		_iter->failed = TRUE;
 		return -1;
 	}
@@ -541,7 +541,7 @@
 
 	local_dsync_worker_add_mailbox(worker, info->ns, storage_name,
 				       &dsync_box_r->mailbox_guid);
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return 1;
 }
 
@@ -706,7 +706,7 @@
 
 		i_error("Failed to sync mailbox %s: %s", lbox->storage_name,
 			mail_storage_get_last_error(storage, NULL));
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return -1;
 	}
 
@@ -716,7 +716,7 @@
 			lbox->storage_name, dsync_guid_to_str(guid),
 			binary_to_hex(status.mailbox_guid,
 				      sizeof(status.mailbox_guid)));
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return -1;
 	}
 	*box_r = box;
@@ -771,7 +771,7 @@
 		iter->iter.failed = TRUE;
 	}
 	(void)mailbox_transaction_commit(&trans);
-	mailbox_close(&box);
+	mailbox_free(&box);
 }
 
 static struct dsync_worker_msg_iter *
@@ -1078,7 +1078,7 @@
 
 	ret = local_worker_create_allocated_mailbox(worker, box, dsync_box);
 	if (ret != 0) {
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return;
 	}
 
@@ -1088,13 +1088,13 @@
 			       dsync_guid_to_str(&dsync_box->mailbox_guid),
 			       NULL);
 	ns = mailbox_get_namespace(box);
-	mailbox_close(&box);
+	mailbox_free(&box);
 
 	local_dsync_worker_add_mailbox(worker, ns, new_name,
 				       &dsync_box->mailbox_guid);
 	box = mailbox_alloc(ns->list, new_name, NULL, 0);
 	(void)local_worker_create_allocated_mailbox(worker, box, dsync_box);
-	mailbox_close(&box);
+	mailbox_free(&box);
 }
 
 static void
@@ -1217,7 +1217,7 @@
 	    mailbox_sync(worker->selected_box, MAILBOX_SYNC_FLAG_FULL_WRITE) < 0)
 		dsync_worker_set_failure(&worker->worker);
 
-	mailbox_close(&worker->selected_box);
+	mailbox_free(&worker->selected_box);
 }
 
 static void
@@ -1251,7 +1251,7 @@
 			mail_storage_get_last_error(mailbox_get_storage(box),
 						    NULL));
 	}
-	mailbox_close(&box);
+	mailbox_free(&box);
 
 	if (selected)
 		dsync_worker_select_mailbox(_worker, dsync_box);
@@ -1412,7 +1412,7 @@
 
 	mail_free(&src_mail);
 	(void)mailbox_transaction_commit(&src_trans);
-	mailbox_close(&src_box);
+	mailbox_free(&src_box);
 
 	callback(ret == 0, context);
 }
@@ -1528,7 +1528,7 @@
 
 	mail_free(&worker->get_mail);
 	(void)mailbox_transaction_commit(&trans);
-	mailbox_close(&box);
+	mailbox_free(&box);
 	memset(&worker->get_mailbox, 0, sizeof(worker->get_mailbox));
 }
 
--- a/src/imap/cmd-append.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-append.c	Sun Feb 07 17:50:08 2010 +0200
@@ -148,7 +148,7 @@
 	if (ctx->t != NULL)
 		mailbox_transaction_rollback(&ctx->t);
 	if (ctx->box != ctx->cmd->client->mailbox && ctx->box != NULL)
-		mailbox_close(&ctx->box);
+		mailbox_free(&ctx->box);
 }
 
 static bool cmd_append_continue_cancel(struct client_command_context *cmd)
@@ -468,7 +468,7 @@
 			    MAILBOX_FLAG_KEEP_RECENT);
 	if (mailbox_open(box) < 0) {
 		client_send_storage_error(cmd, mailbox_get_storage(box));
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return NULL;
 	}
 	if (cmd->client->enabled_features != 0)
--- a/src/imap/cmd-close.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-close.c	Sun Feb 07 17:50:08 2010 +0200
@@ -23,7 +23,7 @@
 	if (mailbox_sync(mailbox, 0) < 0)
 		client_send_untagged_storage_error(client, storage);
 
-	mailbox_close(&mailbox);
+	mailbox_free(&mailbox);
 	client_update_mailbox_flags(client, NULL);
 
 	client_send_tagline(cmd, "OK Close completed.");
--- a/src/imap/cmd-copy.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-copy.c	Sun Feb 07 17:50:08 2010 +0200
@@ -124,7 +124,7 @@
 		if (mailbox_open(destbox) < 0) {
 			client_send_storage_error(cmd,
 				mailbox_get_storage(destbox));
-			mailbox_close(&destbox);
+			mailbox_free(&destbox);
 			return TRUE;
 		}
 		if (client->enabled_features != 0)
@@ -163,7 +163,7 @@
 	if (destbox != client->mailbox) {
 		sync_flags |= MAILBOX_SYNC_FLAG_FAST;
 		imap_flags |= IMAP_SYNC_FLAG_SAFE;
-		mailbox_close(&destbox);
+		mailbox_free(&destbox);
 	}
 
 	if (ret > 0)
--- a/src/imap/cmd-create.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-create.c	Sun Feb 07 17:50:08 2010 +0200
@@ -49,6 +49,6 @@
 		client_send_storage_error(cmd, mailbox_get_storage(box));
 	else
 		client_send_tagline(cmd, "OK Create completed.");
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return TRUE;
 }
--- a/src/imap/cmd-delete.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-delete.c	Sun Feb 07 17:50:08 2010 +0200
@@ -30,9 +30,9 @@
 	    mailbox_backends_equal(mailbox, client->mailbox)) {
 		/* deleting selected mailbox. close it first */
 		client_search_updates_free(client);
-		mailbox_close(&client->mailbox);
+		mailbox_free(&client->mailbox);
 	}
-	mailbox_close(&mailbox);
+	mailbox_free(&mailbox);
 
 	if (mailbox_list_delete_mailbox(ns->list, name) < 0)
 		client_send_list_error(cmd, ns->list);
--- a/src/imap/cmd-logout.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-logout.c	Sun Feb 07 17:50:08 2010 +0200
@@ -16,7 +16,7 @@
 		/* this could be done at client_disconnect() as well,
 		   but eg. mbox rewrite takes a while so the waiting is
 		   better to happen before "OK" message. */
-		mailbox_close(&client->mailbox);
+		mailbox_free(&client->mailbox);
 	}
 
 	client_send_tagline(cmd, "OK Logout completed.");
--- a/src/imap/cmd-select.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-select.c	Sun Feb 07 17:50:08 2010 +0200
@@ -187,7 +187,7 @@
 {
 	if (ret < 0) {
 		if (ctx->box != NULL)
-			mailbox_close(&ctx->box);
+			mailbox_free(&ctx->box);
 		ctx->cmd->client->mailbox = NULL;
 	} else {
 		client_send_tagline(ctx->cmd, mailbox_is_readonly(ctx->box) ?
@@ -271,7 +271,7 @@
 	if (mailbox_open(ctx->box) < 0) {
 		client_send_storage_error(ctx->cmd,
 					  mailbox_get_storage(ctx->box));
-		mailbox_close(&ctx->box);
+		mailbox_free(&ctx->box);
 		return -1;
 	}
 
@@ -377,7 +377,7 @@
 		box = client->mailbox;
 		client->mailbox = NULL;
 
-		mailbox_close(&box);
+		mailbox_free(&box);
 		/* CLOSED response is required by QRESYNC */
 		client_send_line(client,
 				 "* OK [CLOSED] Previous mailbox closed.");
--- a/src/imap/cmd-unselect.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/cmd-unselect.c	Sun Feb 07 17:50:08 2010 +0200
@@ -18,7 +18,7 @@
 	client->mailbox = NULL;
 
 	storage = mailbox_get_storage(mailbox);
-	mailbox_close(&mailbox);
+	mailbox_free(&mailbox);
 	client_update_mailbox_flags(client, NULL);
 
 	client_send_tagline(cmd, "OK Unselect completed.");
--- a/src/imap/imap-client.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/imap-client.c	Sun Feb 07 17:50:08 2010 +0200
@@ -186,7 +186,7 @@
 
 	if (client->mailbox != NULL) {
 		client_search_updates_free(client);
-		mailbox_close(&client->mailbox);
+		mailbox_free(&client->mailbox);
 	}
 	if (client->anvil_sent) {
 		master_service_anvil_send(master_service, t_strconcat(
--- a/src/imap/imap-status.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/imap/imap-status.c	Sun Feb 07 17:50:08 2010 +0200
@@ -84,7 +84,7 @@
 		*error_r = mail_storage_get_last_error(storage, &error);
 		*error_r = imap_get_error_string(cmd, *error_r, error);
 	}
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return ret;
 }
 
--- a/src/lda/main.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lda/main.c	Sun Feb 07 17:50:08 2010 +0200
@@ -476,7 +476,7 @@
 
 	mail_free(&ctx.src_mail);
 	mailbox_transaction_rollback(&t);
-	mailbox_close(&box);
+	mailbox_free(&box);
 
 	mail_user_unref(&ctx.dest_user);
 	mail_user_unref(&raw_mail_user);
--- a/src/lib-index/mail-index-alloc-cache.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-index/mail-index-alloc-cache.c	Sun Feb 07 17:50:08 2010 +0200
@@ -161,10 +161,12 @@
 	destroy_unrefed(FALSE);
 }
 
-void mail_index_alloc_cache_unref(struct mail_index *index)
+void mail_index_alloc_cache_unref(struct mail_index **_index)
 {
+	struct mail_index *index = *_index;
 	struct mail_index_alloc_cache_list *list;
 
+	*_index = NULL;
 	for (list = indexes; list != NULL; list = list->next) {
 		if (list->index == index)
 			break;
--- a/src/lib-index/mail-index-alloc-cache.h	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-index/mail-index-alloc-cache.h	Sun Feb 07 17:50:08 2010 +0200
@@ -5,7 +5,7 @@
 struct mail_index *
 mail_index_alloc_cache_get(const char *mailbox_path,
 			   const char *index_dir, const char *prefix);
-void mail_index_alloc_cache_unref(struct mail_index *index);
+void mail_index_alloc_cache_unref(struct mail_index **index);
 
 void mail_index_alloc_cache_destroy_unrefed(void);
 
--- a/src/lib-lda/mail-deliver.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-lda/mail-deliver.c	Sun Feb 07 17:50:08 2010 +0200
@@ -113,14 +113,14 @@
 	storage = mailbox_get_storage(box);
 	*error_r = mail_storage_get_last_error(storage, &error);
 	if (!ctx->set->lda_mailbox_autocreate || error != MAIL_ERROR_NOTFOUND) {
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return NULL;
 	}
 
 	/* try creating it. */
 	if (mailbox_create(box, NULL, FALSE) < 0) {
 		*error_r = mail_storage_get_last_error(storage, &error);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return NULL;
 	}
 	if (ctx->set->lda_mailbox_autosubscribe) {
@@ -131,7 +131,7 @@
 	/* and try opening again */
 	if (mailbox_sync(box, 0) < 0) {
 		*error_r = mail_storage_get_last_error(storage, &error);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return NULL;
 	}
 	return box;
@@ -230,7 +230,7 @@
 	}
 
 	if (ctx->dest_mail == NULL)
-		mailbox_close(&box);
+		mailbox_free(&box);
 	return ret;
 }
 
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Sun Feb 07 17:50:08 2010 +0200
@@ -412,7 +412,7 @@
 				  MAILBOX_FLAG_IGNORE_ACLS);
 	if (dbox_mailbox_open(box) < 0) {
 		(void)mail_storage_get_last_error(box->storage, &error);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		if (error == MAIL_ERROR_TEMP)
 			return -1;
 		/* non-temporary error, ignore */
@@ -425,7 +425,7 @@
 	if (ret <= 0) {
 		i_assert(ret != 0);
 		mail_storage_set_index_error(box);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return -1;
 	}
 
@@ -438,7 +438,7 @@
 		ret = -1;
 	}
 
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return ret < 0 ? -1 : 0;
 }
 
@@ -492,7 +492,7 @@
 {
 	if (mail_index_sync_commit(&msg->sync_ctx) < 0)
 		return -1;
-	mailbox_close(&msg->box);
+	mailbox_free(&msg->box);
 	memset(msg, 0, sizeof(*msg));
 	return 0;
 }
@@ -556,11 +556,11 @@
 			   it helps. */
 			created = TRUE;
 			(void)mailbox_create(box, NULL, FALSE);
-			mailbox_close(&box);
+			mailbox_free(&box);
 			continue;
 		}
 
-		mailbox_close(&box);
+		mailbox_free(&box);
 		if (error == MAIL_ERROR_TEMP)
 			return -1;
 
@@ -587,7 +587,7 @@
 		if (ret <= 0) {
 			i_assert(ret != 0);
 			mail_storage_set_index_error(box);
-			mailbox_close(&box);
+			mailbox_free(&box);
 			return -1;
 		}
 		ctx->prev_msg.box = box;
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c	Sun Feb 07 17:50:08 2010 +0200
@@ -320,7 +320,7 @@
 	ret = mailbox_open(box);
 	list->mail_set = old_set;
 	if (ret < 0) {
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return -1;
 	}
 	mbox = (struct mdbox_mailbox *)box;
@@ -347,7 +347,7 @@
 		ret = dbox_map_transaction_commit(map_trans);
 	dbox_map_transaction_free(&map_trans);
 	array_free(&map_uids);
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return ret;
 }
 
--- a/src/lib-storage/index/index-storage.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-storage/index/index-storage.c	Sun Feb 07 17:50:08 2010 +0200
@@ -320,19 +320,23 @@
 {
 	struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
 
-	if (box->view != NULL)
-		mail_index_view_close(&box->view);
-
 	index_mailbox_check_remove_all(box);
 	if (box->input != NULL)
 		i_stream_unref(&box->input);
-	if (box->index != NULL)
-		mail_index_alloc_cache_unref(box->index);
+
+	mail_index_view_close(&box->view);
+	mail_index_close(box->index);
+	box->cache = NULL;
+
+	ibox->keyword_names = NULL;
+	i_free_and_null(ibox->cache_fields);
+
 	if (array_is_created(&ibox->recent_flags))
 		array_free(&ibox->recent_flags);
-	i_free(ibox->cache_fields);
+	ibox->recent_flags_prev_uid = 0;
+	ibox->recent_flags_count = 0;
 
-	pool_unref(&box->pool);
+	ibox->sync_last_check = 0;
 }
 
 static void
--- a/src/lib-storage/index/maildir/maildir-storage.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Sun Feb 07 17:50:08 2010 +0200
@@ -692,7 +692,7 @@
 		mailbox_get_status(box, STATUS_GUID, &status);
 		memcpy(mailbox_guid, status.mailbox_guid, MAIL_GUID_128_SIZE);
 	}
-	mailbox_close(&box);
+	mailbox_free(&box);
 }
 
 static int
--- a/src/lib-storage/mail-storage.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-storage/mail-storage.c	Sun Feb 07 17:50:08 2010 +0200
@@ -511,17 +511,32 @@
 	return box->enabled_features;
 }
 
-void mailbox_close(struct mailbox **_box)
+void mailbox_close(struct mailbox *box)
 {
-	struct mailbox *box = *_box;
+	if (!box->opened)
+		return;
 
 	if (box->transaction_count != 0) {
 		i_panic("Trying to close mailbox %s with open transactions",
 			box->name);
 	}
+	box->v.close(box);
+
+	box->opened = FALSE;
+	box->mailbox_deleted = FALSE;
+	box->backend_readonly = FALSE;
+	array_clear(&box->search_results);
+}
+
+void mailbox_free(struct mailbox **_box)
+{
+	struct mailbox *box = *_box;
 
 	*_box = NULL;
-	box->v.close(box);
+
+	mailbox_close(box);
+	mail_index_alloc_cache_unref(&box->index);
+	pool_unref(&box->pool);
 }
 
 int mailbox_create(struct mailbox *box, const struct mailbox_update *update,
--- a/src/lib-storage/mail-storage.h	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lib-storage/mail-storage.h	Sun Feb 07 17:50:08 2010 +0200
@@ -329,8 +329,10 @@
 /* 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);
-/* Close the box. */
-void mailbox_close(struct mailbox **box);
+/* Close mailbox. Same as if mailbox was freed and re-allocated. */
+void mailbox_close(struct mailbox *box);
+/* Close and free the mailbox. */
+void mailbox_free(struct mailbox **box);
 
 /* Create a mailbox. Returns failure if it already exists. Mailbox name is
    allowed to contain multiple new non-existing hierarchy levels. If directory
--- a/src/lmtp/client.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lmtp/client.c	Sun Feb 07 17:50:08 2010 +0200
@@ -309,7 +309,7 @@
 	if (client->state.raw_trans != NULL)
 		mailbox_transaction_rollback(&client->state.raw_trans);
 	if (client->state.raw_box != NULL)
-		mailbox_close(&client->state.raw_box);
+		mailbox_free(&client->state.raw_box);
 
 	if (client->state.mail_data != NULL)
 		buffer_free(&client->state.mail_data);
--- a/src/lmtp/commands.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/lmtp/commands.c	Sun Feb 07 17:50:08 2010 +0200
@@ -585,7 +585,7 @@
 	if (mailbox_sync(box, 0) < 0) {
 		i_error("Can't open delivery mail as raw: %s",
 			mail_storage_get_last_error(box->storage, &error));
-		mailbox_close(&box);
+		mailbox_free(&box);
 		client_rcpt_fail_all(client);
 		return -1;
 	}
@@ -633,7 +633,7 @@
 
 		mail_free(&mail);
 		mailbox_transaction_rollback(&trans);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		mail_user_unref(&user);
 	}
 }
--- a/src/plugins/autocreate/autocreate-plugin.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/autocreate/autocreate-plugin.c	Sun Feb 07 17:50:08 2010 +0200
@@ -34,7 +34,7 @@
 				name, str);
 		}
 	}
-	mailbox_close(&box);
+	mailbox_free(&box);
 }
 
 static void autocreate_mailboxes(struct mail_namespace *namespaces)
--- a/src/plugins/expire/expire-tool.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/expire/expire-tool.c	Sun Feb 07 17:50:08 2010 +0200
@@ -109,7 +109,7 @@
 	if (mailbox_open(box) < 0) {
 		errstr = mail_storage_get_last_error(mailbox_get_storage(box),
 						     &error);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		if (error != MAIL_ERROR_NOTFOUND) {
 			i_error("%s: Opening mailbox %s failed: %s",
 				user, mailbox, errstr);
@@ -185,7 +185,7 @@
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FAST) < 0)
 		ret = -1;
 
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return ret;
 }
 
--- a/src/plugins/imap-acl/imap-acl-plugin.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/imap-acl/imap-acl-plugin.c	Sun Feb 07 17:50:08 2010 +0200
@@ -84,7 +84,7 @@
 	} else {
 		client_send_tagline(cmd, "NO "ERROR_NOT_ADMIN);
 	}
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return NULL;
 }
 
@@ -273,7 +273,7 @@
 	} else {
 		client_send_tagline(cmd, "NO "MAIL_ERRSTR_CRITICAL_MSG);
 	}
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return TRUE;
 }
 
@@ -304,7 +304,7 @@
 	if (acl_object_get_my_rights(acl_mailbox_get_aclobj(box),
 				     pool_datastack_create(), &rights) < 0) {
 		client_send_tagline(cmd, "NO "MAIL_ERRSTR_CRITICAL_MSG);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return TRUE;
 	}
 	/* Post right alone doesn't give permissions to see if the mailbox
@@ -314,7 +314,7 @@
 		client_send_tagline(cmd, t_strdup_printf(
 			"NO ["IMAP_RESP_CODE_NONEXISTENT"] "
 			MAIL_ERRSTR_MAILBOX_NOT_FOUND, real_mailbox));
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return TRUE;
 	}
 
@@ -326,7 +326,7 @@
 
 	client_send_line(cmd->client, str_c(str));
 	client_send_tagline(cmd, "OK Myrights completed.");
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return TRUE;
 }
 
@@ -353,7 +353,7 @@
 
 	client_send_line(cmd->client, str_c(str));
 	client_send_tagline(cmd, "OK Listrights completed.");
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return TRUE;
 }
 
@@ -547,7 +547,7 @@
 	backend = acl_mailbox_list_get_backend(ns->list);
 	if (ns->type == NAMESPACE_PUBLIC && r->id_type == ACL_ID_OWNER) {
 		client_send_tagline(cmd, "NO Public namespaces have no owner");
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return TRUE;
 	}
 
@@ -571,7 +571,7 @@
 		client_send_tagline(cmd, "NO "MAIL_ERRSTR_CRITICAL_MSG);
 	else
 		client_send_tagline(cmd, "OK Setacl complete.");
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return TRUE;
 }
 
@@ -610,7 +610,7 @@
 		client_send_tagline(cmd, "NO "MAIL_ERRSTR_CRITICAL_MSG);
 	else
 		client_send_tagline(cmd, "OK Deleteacl complete.");
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return TRUE;
 }
 
--- a/src/plugins/imap-quota/imap-quota-plugin.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/imap-quota/imap-quota-plugin.c	Sun Feb 07 17:50:08 2010 +0200
@@ -118,7 +118,7 @@
 	while ((root = quota_root_iter_next(iter)) != NULL)
 		quota_send(cmd, ns->owner, root);
 	quota_root_iter_deinit(&iter);
-	mailbox_close(&box);
+	mailbox_free(&box);
 
 	client_send_tagline(cmd, "OK Getquotaroot completed.");
 	return TRUE;
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Sun Feb 07 17:50:08 2010 +0200
@@ -87,7 +87,7 @@
 	*error_r = mail_storage_get_last_error(mailbox_get_storage(box),
 					       &error);
 	if (error != MAIL_ERROR_NOTFOUND) {
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return NULL;
 	}
 
@@ -97,7 +97,7 @@
 	    mailbox_open(box) < 0) {
 		*error_r = mail_storage_get_last_error(mailbox_get_storage(box),
 						       NULL);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return NULL;
 	}
 	return box;
@@ -136,7 +136,7 @@
 		if (mailbox_sync(lt->dest_box, 0) < 0) {
 			mail_storage_set_critical(_mail->box->storage,
 				"lazy_expunge: Couldn't sync expunge mailbox");
-			mailbox_close(&lt->dest_box);
+			mailbox_free(&lt->dest_box);
 			lt->failed = TRUE;
 			return;
 		}
@@ -173,7 +173,7 @@
 	if (lt->dest_trans != NULL)
 		mailbox_transaction_rollback(&lt->dest_trans);
 	if (lt->dest_box != NULL)
-		mailbox_close(&lt->dest_box);
+		mailbox_free(&lt->dest_box);
 	i_free(lt);
 }
 
@@ -309,15 +309,15 @@
 		errstr = mail_storage_get_last_error(dest_box->storage, &error);
 		i_error("lazy_expunge: Couldn't open DELETE dest mailbox "
 			"%s: %s", dest_name, errstr);
-		mailbox_close(&dest_box);
+		mailbox_free(&dest_box);
 		return -1;
 	}
 
 	src_box = mailbox_alloc(list, src_name, NULL, MAILBOX_FLAG_KEEP_LOCKED);
 	if (mailbox_open(src_box) < 0) {
 		errstr = mail_storage_get_last_error(src_box->storage, &error);
-		mailbox_close(&src_box);
-		mailbox_close(&dest_box);
+		mailbox_free(&src_box);
+		mailbox_free(&dest_box);
 
 		if (error == MAIL_ERROR_NOTFOUND)
 			return 0;
@@ -357,8 +357,8 @@
 	else
 		mailbox_transaction_rollback(&dest_trans);
 
-	mailbox_close(&src_box);
-	mailbox_close(&dest_box);
+	mailbox_free(&src_box);
+	mailbox_free(&dest_box);
 
 	if (ret == 0)
 		ret = mailbox_list_delete_mailbox(list, src_name);
--- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Sun Feb 07 17:50:08 2010 +0200
@@ -116,7 +116,7 @@
 	(void)mbox_snarf(spool_mbox, box);
 
 	ctx = mbox->module_ctx.super.sync_init(box, flags);
-	mailbox_close(&spool_mbox);
+	mailbox_free(&spool_mbox);
 	return ctx;
 }
 
--- a/src/plugins/quota/quota-count.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/quota/quota-count.c	Sun Feb 07 17:50:08 2010 +0200
@@ -31,7 +31,7 @@
 			    MAILBOX_FLAG_READONLY | MAILBOX_FLAG_KEEP_RECENT);
 	if (mailbox_open(box) < 0) {
 		mail_storage_get_last_error(mailbox_get_storage(box), &error);
-		mailbox_close(&box);
+		mailbox_free(&box);
 		if (error == MAIL_ERROR_TEMP)
 			return -1;
 		/* non-temporary error, e.g. ACLs denied access. */
@@ -39,7 +39,7 @@
 	}
 
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
-		mailbox_close(&box);
+		mailbox_free(&box);
 		return -1;
 	}
 
@@ -65,7 +65,7 @@
 	else
 		(void)mailbox_transaction_commit(&trans);
 
-	mailbox_close(&box);
+	mailbox_free(&box);
 	return ret;
 }
 
--- a/src/plugins/quota/quota-storage.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/quota/quota-storage.c	Sun Feb 07 17:50:08 2010 +0200
@@ -441,7 +441,7 @@
 		}
 	}
 	if (box != NULL)
-		mailbox_close(&box);
+		mailbox_free(&box);
 
 	/* FIXME: here's an unfortunate race condition */
 	return ret < 0 ? -1 :
--- a/src/plugins/trash/trash-plugin.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/trash/trash-plugin.c	Sun Feb 07 17:50:08 2010 +0200
@@ -55,7 +55,7 @@
 	trash->box = mailbox_alloc(trash->ns->list, trash->name, NULL,
 				   MAILBOX_FLAG_KEEP_RECENT);
 	if (mailbox_open(trash->box) < 0) {
-		mailbox_close(&trash->box);
+		mailbox_free(&trash->box);
 		return 0;
 	}
 
@@ -168,7 +168,7 @@
                         mailbox_transaction_rollback(&trash->trans);
 		}
 
-		mailbox_close(&trash->box);
+		mailbox_free(&trash->box);
 	}
 
 	if (size_expunged < size_needed) {
--- a/src/plugins/virtual/virtual-storage.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/plugins/virtual/virtual-storage.c	Sun Feb 07 17:50:08 2010 +0200
@@ -136,7 +136,7 @@
 	if (mailbox_open(bbox->box) < 0) {
 		storage = mailbox_get_storage(bbox->box);
 		str = mail_storage_get_last_error(storage, &error);
-		mailbox_close(&bbox->box);
+		mailbox_free(&bbox->box);
 		if (bbox->wildcard && (error == MAIL_ERROR_PERM ||
 				       error == MAIL_ERROR_NOTFOUND)) {
 			/* this mailbox wasn't explicitly specified.
@@ -179,7 +179,7 @@
 	else {
 		/* failed */
 		for (; i > 0; i--) {
-			mailbox_close(&bboxes[i-1]->box);
+			mailbox_free(&bboxes[i-1]->box);
 			array_free(&bboxes[i-1]->uids);
 		}
 		return -1;
@@ -274,7 +274,7 @@
 		if (bboxes[i]->box == NULL)
 			continue;
 
-		mailbox_close(&bboxes[i]->box);
+		mailbox_free(&bboxes[i]->box);
 		if (array_is_created(&bboxes[i]->sync_outside_expunges))
 			array_free(&bboxes[i]->sync_outside_expunges);
 		array_free(&bboxes[i]->sync_pending_removes);
--- a/src/pop3/pop3-client.c	Sun Feb 07 17:37:48 2010 +0200
+++ b/src/pop3/pop3-client.c	Sun Feb 07 17:50:08 2010 +0200
@@ -352,7 +352,7 @@
 		(void)mailbox_transaction_commit(&client->trans);
 	}
 	if (client->mailbox != NULL)
-		mailbox_close(&client->mailbox);
+		mailbox_free(&client->mailbox);
 	if (client->anvil_sent) {
 		master_service_anvil_send(master_service, t_strconcat(
 			"DISCONNECT\t", my_pid, "\tpop3/",