changeset 21878:e78a42ead488

global: Add mailbox_set_reason() calls Added to the most important places.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sat, 01 Apr 2017 21:43:16 +0300
parents d703b0fde204
children 313601eae9a8
files src/doveadm/doveadm-mail-copymove.c src/doveadm/doveadm-mail-import.c src/doveadm/doveadm-mail-index.c src/doveadm/doveadm-mail-iter.c src/doveadm/doveadm-mail-mailbox-metadata.c src/doveadm/doveadm-mail-mailbox-status.c src/doveadm/doveadm-mail-mailbox.c src/doveadm/doveadm-mail-save.c src/doveadm/doveadm-mail.c src/imap/cmd-create.c src/imap/cmd-delete.c src/imap/cmd-getmetadata.c src/imap/cmd-notify.c src/imap/cmd-rename.c src/imap/cmd-resetkey.c src/imap/cmd-select.c src/imap/cmd-setmetadata.c src/imap/cmd-subscribe.c src/imap/imap-commands-util.c src/imap/imap-notify.c src/imap/imap-state.c src/imap/imap-status.c src/indexer/master-connection.c src/lib-imap-storage/imap-metadata.c src/lib-imap-storage/imap-msgpart-url.c src/lib-imap-urlauth/imap-urlauth-backend.c src/lib-lda/mail-deliver.c src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c src/lib-storage/mail-autoexpunge.c src/lib-storage/mail-storage.c src/lmtp/commands.c src/plugins/lazy-expunge/lazy-expunge-plugin.c src/plugins/pop3-migration/pop3-migration-plugin.c src/plugins/quota/quota-count.c src/plugins/quota/quota-status.c src/plugins/trash/trash-plugin.c src/plugins/virtual/virtual-config.c src/plugins/virtual/virtual-storage.c src/pop3/pop3-client.c
diffstat 39 files changed, 57 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-mail-copymove.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-copymove.c	Sat Apr 01 21:43:16 2017 +0300
@@ -108,6 +108,7 @@
 
 	ns = mail_namespace_find(user->namespaces, ctx->destname);
 	destbox = mailbox_alloc(ns->list, ctx->destname, MAILBOX_FLAG_SAVEONLY);
+	mailbox_set_reason(destbox, _ctx->cmd->name);
 	if (mailbox_open(destbox) < 0) {
 		i_error("Can't open mailbox '%s': %s", ctx->destname,
 			mailbox_get_last_internal_error(destbox, NULL));
--- a/src/doveadm/doveadm-mail-import.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-import.c	Sat Apr 01 21:43:16 2017 +0300
@@ -63,6 +63,7 @@
 	}
 
 	box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY);
+	mailbox_set_reason(*box_r, ctx->ctx.cmd->name);
 	if (mailbox_create(box, NULL, FALSE) < 0) {
 		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error != MAIL_ERROR_EXISTS) {
--- a/src/doveadm/doveadm-mail-index.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-index.c	Sat Apr 01 21:43:16 2017 +0300
@@ -106,6 +106,7 @@
 
 	box = mailbox_alloc(info->ns->list, info->vname,
 			    MAILBOX_FLAG_IGNORE_ACLS);
+	mailbox_set_reason(box, ctx->ctx.cmd->name);
 	if (ctx->max_recent_msgs != 0) {
 		/* index only if there aren't too many recent messages.
 		   don't bother syncing the mailbox, that alone can take a
--- a/src/doveadm/doveadm-mail-iter.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-iter.c	Sat Apr 01 21:43:16 2017 +0300
@@ -37,6 +37,7 @@
 	iter->ctx = ctx;
 	iter->box = mailbox_alloc(info->ns->list, info->vname,
 				  MAILBOX_FLAG_IGNORE_ACLS | readonly_flag);
+	mailbox_set_reason(iter->box, ctx->cmd->name);
 	iter->search_args = search_args;
 
 	if (mailbox_sync(iter->box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
--- a/src/doveadm/doveadm-mail-mailbox-metadata.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-mailbox-metadata.c	Sat Apr 01 21:43:16 2017 +0300
@@ -46,6 +46,7 @@
 		*ns_r = mail_namespace_find(user->namespaces, mctx->mailbox);
 		*box_r = mailbox_alloc((*ns_r)->list, mctx->mailbox, 0);
 	}
+	mailbox_set_reason(*box_r, mctx->ctx.cmd->name);
 
 	if (mailbox_open(*box_r) < 0) {
 		i_error("Failed to open mailbox: %s",
--- a/src/doveadm/doveadm-mail-mailbox-status.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-mailbox-status.c	Sat Apr 01 21:43:16 2017 +0300
@@ -127,6 +127,7 @@
 	struct mailbox_metadata metadata;
 
 	box = doveadm_mailbox_find(ctx->ctx.cur_mail_user, info->vname);
+	mailbox_set_reason(box, ctx->ctx.cmd->name);
 	if (mailbox_get_status(box, ctx->status_items, &status) < 0 ||
 	    mailbox_get_metadata(box, ctx->metadata_items, &metadata) < 0) {
 		i_error("Mailbox %s: Failed to lookup mailbox status: %s",
--- a/src/doveadm/doveadm-mail-mailbox.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-mailbox.c	Sat Apr 01 21:43:16 2017 +0300
@@ -242,6 +242,7 @@
 		}
 
 		box = mailbox_alloc(ns->list, name, 0);
+		mailbox_set_reason(box, _ctx->cmd->name);
 		if (mailbox_create(box, &ctx->update, directory) < 0) {
 			i_error("Can't create mailbox %s: %s", name,
 				mailbox_get_last_internal_error(box, NULL));
@@ -372,6 +373,7 @@
 
 		ns = mail_namespace_find(user->namespaces, name);
 		box = mailbox_alloc(ns->list, name, mailbox_flags);
+		mailbox_set_reason(box, _ctx->cmd->name);
 		storage = mailbox_get_storage(box);
 		ret2 = ctx->require_empty ? mailbox_delete_empty(box) :
 			mailbox_delete(box);
@@ -464,6 +466,8 @@
 	newns = mail_namespace_find(user->namespaces, newname);
 	oldbox = mailbox_alloc(oldns->list, oldname, 0);
 	newbox = mailbox_alloc(newns->list, newname, 0);
+	mailbox_set_reason(oldbox, _ctx->cmd->name);
+	mailbox_set_reason(newbox, _ctx->cmd->name);
 	if (mailbox_rename(oldbox, newbox) < 0) {
 		i_error("Can't rename mailbox %s to %s: %s", oldname, newname,
 			mailbox_get_last_internal_error(oldbox, NULL));
@@ -528,6 +532,7 @@
 
 		ns = mail_namespace_find(user->namespaces, name);
 		box = mailbox_alloc(ns->list, name, 0);
+		mailbox_set_reason(box, _ctx->cmd->name);
 		if (mailbox_set_subscribed(box, ctx->ctx.subscriptions) < 0) {
 			i_error("Can't %s mailbox %s: %s", name,
 				ctx->ctx.subscriptions ? "subscribe to" :
@@ -655,6 +660,7 @@
 
 	ns = mail_namespace_find(user->namespaces, ctx->mailbox);
 	box = mailbox_alloc(ns->list, ctx->mailbox, 0);
+	mailbox_set_reason(box, _ctx->cmd->name);
 
 	if ((ret = mailbox_update(box, &(ctx->update))) != 0) {
 		i_error("Cannot update %s: %s",
--- a/src/doveadm/doveadm-mail-save.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail-save.c	Sat Apr 01 21:43:16 2017 +0300
@@ -90,6 +90,7 @@
 
 	ns = mail_namespace_find(user->namespaces, ctx->mailbox);
 	box = mailbox_alloc(ns->list, ctx->mailbox, MAILBOX_FLAG_SAVEONLY);
+	mailbox_set_reason(box, _ctx->cmd->name);
 	ret = cmd_save_to_mailbox(ctx, box, _ctx->cmd_input);
 	mailbox_free(&box);
 	return ret;
--- a/src/doveadm/doveadm-mail.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/doveadm/doveadm-mail.c	Sat Apr 01 21:43:16 2017 +0300
@@ -285,6 +285,7 @@
 
 	box = mailbox_alloc(info->ns->list, info->vname,
 			    MAILBOX_FLAG_IGNORE_ACLS);
+	mailbox_set_reason(box, ctx->cmd->name);
 	if (mailbox_open(box) < 0) {
 		i_error("Opening mailbox %s failed: %s", info->vname,
 			mailbox_get_last_internal_error(box, NULL));
--- a/src/imap/cmd-create.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-create.c	Sat Apr 01 21:43:16 2017 +0300
@@ -38,6 +38,7 @@
 	}
 
 	box = mailbox_alloc(ns->list, mailbox, 0);
+	mailbox_set_reason(box, "CREATE");
 	if (mailbox_create(box, NULL, directory) < 0)
 		client_send_box_error(cmd, box);
 	else
--- a/src/imap/cmd-delete.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-delete.c	Sat Apr 01 21:43:16 2017 +0300
@@ -21,6 +21,7 @@
 		return TRUE;
 
 	box = mailbox_alloc(ns->list, name, 0);
+	mailbox_set_reason(box, "DELETE");
 	if (mailbox_is_any_inbox(box)) {
 		/* IMAP protocol allows this, but I think it's safer to
 		   not allow it. */
--- a/src/imap/cmd-getmetadata.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-getmetadata.c	Sat Apr 01 21:43:16 2017 +0300
@@ -410,6 +410,7 @@
 			    struct mail_namespace *ns, const char *mailbox)
 {
 	ctx->box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_READONLY);
+	mailbox_set_reason(ctx->box, "GETMETADATA");
 	if (mailbox_open(ctx->box) < 0)
 		return -1;
 
--- a/src/imap/cmd-notify.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-notify.c	Sat Apr 01 21:43:16 2017 +0300
@@ -417,6 +417,7 @@
 		items.status |= STATUS_HIGHESTMODSEQ;
 
 	box = mailbox_alloc(info->ns->list, info->vname, MAILBOX_FLAG_READONLY);
+	mailbox_set_reason(box, "NOTIFY send STATUS");
 	if (ctx->client->enabled_features != 0)
 		(void)mailbox_enable(box, ctx->client->enabled_features);
 
--- a/src/imap/cmd-rename.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-rename.c	Sat Apr 01 21:43:16 2017 +0300
@@ -37,6 +37,8 @@
 
 	old_box = mailbox_alloc(old_ns->list, oldname, 0);
 	new_box = mailbox_alloc(new_ns->list, newname, 0);
+	mailbox_set_reason(old_box, "RENAME from");
+	mailbox_set_reason(new_box, "RENAME to");
 	if (mailbox_rename(old_box, new_box) < 0)
 		client_send_box_error(cmd, old_box);
 	else
--- a/src/imap/cmd-resetkey.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-resetkey.c	Sat Apr 01 21:43:16 2017 +0300
@@ -49,6 +49,7 @@
 
 	/* open mailbox */
 	box = mailbox_alloc(ns->list, mailbox, flags);
+	mailbox_set_reason(box, "RESETKEY");
 	if (mailbox_open(box) < 0) {
 		client_send_box_error(cmd, box);
 		mailbox_free(&box);
--- a/src/imap/cmd-select.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-select.c	Sat Apr 01 21:43:16 2017 +0300
@@ -291,6 +291,7 @@
 	else
 		flags |= MAILBOX_FLAG_DROP_RECENT;
 	ctx->box = mailbox_alloc(ctx->ns->list, mailbox, flags);
+	mailbox_set_reason(ctx->box, readonly ? "EXAMINE" : "SELECT");
 	if (mailbox_open(ctx->box) < 0) {
 		client_send_box_error(ctx->cmd, ctx->box);
 		mailbox_free(&ctx->box);
--- a/src/imap/cmd-setmetadata.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-setmetadata.c	Sat Apr 01 21:43:16 2017 +0300
@@ -304,6 +304,7 @@
 		ctx->box = client->mailbox;
 	else {
 		ctx->box = mailbox_alloc(ns->list, mailbox, 0);
+		mailbox_set_reason(ctx->box, "SETMETADATA");
 		if (mailbox_open(ctx->box) < 0) {
 			client_send_box_error(cmd, ctx->box);
 			mailbox_free(&ctx->box);
--- a/src/imap/cmd-subscribe.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/cmd-subscribe.c	Sat Apr 01 21:43:16 2017 +0300
@@ -49,6 +49,7 @@
 		return TRUE;
 
 	box = mailbox_alloc(ns->list, mailbox, 0);
+	mailbox_set_reason(box, subscribe ? "SUBSCRIBE" : "UNSUBSCRIBE");
 	if (subscribe) {
 		if (!subscribe_is_valid_name(cmd, box)) {
 			mailbox_free(&box);
@@ -64,6 +65,7 @@
 		/* try to unsubscribe both "box" and "box/" */
 		const char *name2 = t_strdup_printf("%s%c", mailbox, sep);
 		box2 = mailbox_alloc(ns->list, name2, 0);
+		mailbox_set_reason(box2, "UNSUBSCRIBE");
 		if (mailbox_set_subscribed(box2, FALSE) == 0)
 			unsubscribed_mailbox2 = TRUE;
 		mailbox_free(&box2);
--- a/src/imap/imap-commands-util.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/imap-commands-util.c	Sat Apr 01 21:43:16 2017 +0300
@@ -109,6 +109,7 @@
 		return 0;
 	}
 	box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY);
+	mailbox_set_reason(box, cmd->name);
 	if (mailbox_open(box) < 0) {
 		error_string = mailbox_get_last_error(box, &error);
 		if (error == MAIL_ERROR_NOTFOUND) {
--- a/src/imap/imap-notify.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/imap-notify.c	Sat Apr 01 21:43:16 2017 +0300
@@ -57,6 +57,7 @@
 		items.status |= STATUS_HIGHESTMODSEQ;
 
 	box = mailbox_alloc(notify_ns->ns->list, rec->vname, 0);
+	mailbox_set_reason(box, "NOTIFY STATUS");
 	if ((rec->events & MAILBOX_LIST_NOTIFY_UIDVALIDITY) != 0) {
 		items.status |= STATUS_UIDVALIDITY | STATUS_UIDNEXT |
 			STATUS_MESSAGES | STATUS_UNSEEN;
@@ -197,6 +198,7 @@
 	switch (notify_boxes->type) {
 	case IMAP_NOTIFY_TYPE_SUBSCRIBED:
 		box = mailbox_alloc(notify_ns->ns->list, vname, 0);
+		mailbox_set_reason(box, "NOTIFY is subscribed");
 		ret = mailbox_is_subscribed(box);
 		mailbox_free(&box);
 		return ret;
--- a/src/imap/imap-state.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/imap-state.c	Sat Apr 01 21:43:16 2017 +0300
@@ -573,6 +573,7 @@
 	else
 		flags |= MAILBOX_FLAG_DROP_RECENT;
 	box = mailbox_alloc(ns->list, state->vname, flags);
+	mailbox_set_reason(box, "unhibernate");
 	if (mailbox_open(box) < 0) {
 		*error_r = t_strdup_printf("Couldn't open mailbox: %s",
 			mailbox_get_last_internal_error(box, NULL));
--- a/src/imap/imap-status.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/imap/imap-status.c	Sat Apr 01 21:43:16 2017 +0300
@@ -74,6 +74,7 @@
 	} else {
 		/* open the mailbox */
 		box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_READONLY);
+		mailbox_set_reason(box, "STATUS");
 		if (client->enabled_features != 0)
 			(void)mailbox_enable(box, client->enabled_features);
 	}
--- a/src/indexer/master-connection.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/indexer/master-connection.c	Sat Apr 01 21:43:16 2017 +0300
@@ -142,6 +142,7 @@
 
 	ns = mail_namespace_find(user->namespaces, mailbox);
 	box = mailbox_alloc(ns->list, mailbox, 0);
+	mailbox_set_reason(box, "indexing");
 	ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path);
 	if (ret < 0) {
 		i_error("Getting path to mailbox %s failed: %s",
--- a/src/lib-imap-storage/imap-metadata.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lib-imap-storage/imap-metadata.c	Sat Apr 01 21:43:16 2017 +0300
@@ -244,6 +244,7 @@
 
 	ns = mail_namespace_find_inbox(user->namespaces);
 	box = mailbox_alloc(ns->list, "INBOX", 0);
+	mailbox_set_reason(box, "Server METADATA");
 	imtrans = imap_metadata_transaction_begin(box);
 	imtrans->server = TRUE;
 	return imtrans;
--- a/src/lib-imap-storage/imap-msgpart-url.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lib-imap-storage/imap-msgpart-url.c	Sat Apr 01 21:43:16 2017 +0300
@@ -129,8 +129,10 @@
 	if (mpurl->selected_box != NULL &&
 	    mailbox_equals(mpurl->selected_box, ns, mpurl->mailbox))
 		box = mpurl->selected_box;
-	else
+	else {
 		box = mailbox_alloc(ns->list, mpurl->mailbox, flags);
+		mailbox_set_reason(box, "Read IMAP URL");
+	}
 	if (mailbox_open(box) < 0) {
 		*error_r = mail_storage_get_last_error(mailbox_get_storage(box),
 						       error_code_r);
--- a/src/lib-imap-urlauth/imap-urlauth-backend.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth-backend.c	Sat Apr 01 21:43:16 2017 +0300
@@ -132,6 +132,7 @@
 						 MAILBOX_LIST_ITER_RETURN_NO_FLAGS);
 	while ((info = mailbox_list_iter_next(iter)) != NULL) {
 		box = mailbox_alloc(info->ns->list, info->vname, 0);
+		mailbox_set_reason(box, "URLAUTH reset all keys");
 		if (imap_urlauth_backend_mailbox_reset_key(box) < 0)
 			ret = -1;
 		mailbox_free(&box);
--- a/src/lib-lda/mail-deliver.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lib-lda/mail-deliver.c	Sat Apr 01 21:43:16 2017 +0300
@@ -230,6 +230,7 @@
 	}
 
 	*box_r = box = mailbox_alloc(ns->list, name, flags);
+	mailbox_set_reason(box, "lib-lda delivery");
 	/* flag that this mailbox is used for delivering the mail.
 	   the context isn't set in pigeonhole testuite. */
 	struct mail_deliver_mailbox *mbox = MAIL_DELIVER_STORAGE_CONTEXT(box);
@@ -574,6 +575,7 @@
 	   synced, so it'll contain the newly written mail. this is racy, so
 	   it's possible another process has already deleted the mail. */
 	box = mailbox_alloc(orig_box->list, orig_box->vname, 0);
+	mailbox_set_reason(box, "lib-lda storage-id");
 
 	mail = mail_deliver_open_mail(box, uid, MAIL_FETCH_STORAGE_ID, &t);
 	if (mail != NULL) {
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Sat Apr 01 21:43:16 2017 +0300
@@ -551,6 +551,7 @@
 
 	box = mailbox_alloc(ns->list, vname, MAILBOX_FLAG_READONLY |
 			    MAILBOX_FLAG_IGNORE_ACLS);
+	mailbox_set_reason(box, "mdbox rebuild");
 	if (box->storage != &ctx->storage->storage.storage) {
 		/* the namespace has multiple storages. */
 		mailbox_free(&box);
@@ -703,6 +704,7 @@
 		box = mailbox_alloc(ctx->default_list, mailbox,
 				    MAILBOX_FLAG_READONLY |
 				    MAILBOX_FLAG_IGNORE_ACLS);
+		mailbox_set_reason(box, "mdbox rebuild restore");
 		i_assert(box->storage == storage);
 		if (mailbox_open(box) == 0)
 			break;
--- a/src/lib-storage/mail-autoexpunge.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lib-storage/mail-autoexpunge.c	Sat Apr 01 21:43:16 2017 +0300
@@ -156,6 +156,7 @@
 	   any ACLs the user might normally have against expunging in
 	   the mailbox. */
 	box = mailbox_alloc(ns->list, vname, MAILBOX_FLAG_IGNORE_ACLS);
+	mailbox_set_reason(box, "autoexpunge");
 	if (mailbox_autoexpunge(box, autoexpunge, autoexpunge_max_mails,
 				expunged_count) < 0) {
 		i_error("Failed to autoexpunge mailbox '%s': %s",
--- a/src/lib-storage/mail-storage.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lib-storage/mail-storage.c	Sat Apr 01 21:43:16 2017 +0300
@@ -1389,6 +1389,7 @@
 
 	/* this should be NoSelect but since inbox can never be
 	   NoSelect we use EXISTENCE_NONE to avoid creating inbox by accident */
+	mailbox_set_reason(inbox, "copy caching decisions");
 	if (mailbox_exists(inbox, FALSE, &existence) == 0 &&
 	    existence != MAILBOX_EXISTENCE_NONE &&
 	    mailbox_open(inbox) == 0 &&
--- a/src/lmtp/commands.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/lmtp/commands.c	Sat Apr 01 21:43:16 2017 +0300
@@ -583,6 +583,7 @@
 
 	ns = mail_namespace_find_inbox(user->namespaces);
 	box = mailbox_alloc(ns->list, "INBOX", 0);
+	mailbox_set_reason(box, "over-quota check");
 	ret = mailbox_get_status(box, STATUS_CHECK_OVER_QUOTA, &status);
 	if (ret < 0) {
 		errstr = mailbox_get_last_error(box, &error);
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Sat Apr 01 21:43:16 2017 +0300
@@ -119,6 +119,7 @@
 
 	box = mailbox_alloc(list, name, MAILBOX_FLAG_NO_INDEX_FILES |
 			    MAILBOX_FLAG_SAVEONLY | MAILBOX_FLAG_IGNORE_ACLS);
+	mailbox_set_reason(box, "lazy_expunge");
 	if (mailbox_open(box) == 0) {
 		*error_r = NULL;
 		return box;
--- a/src/plugins/pop3-migration/pop3-migration-plugin.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/plugins/pop3-migration/pop3-migration-plugin.c	Sat Apr 01 21:43:16 2017 +0300
@@ -311,12 +311,15 @@
 	struct pop3_migration_mail_storage *mstorage =
 		POP3_MIGRATION_CONTEXT(storage);
 	struct mail_namespace *ns;
+	struct mailbox *box;
 
 	ns = mail_namespace_find(storage->user->namespaces,
 				 mstorage->pop3_box_vname);
 	i_assert(ns != NULL);
-	return mailbox_alloc(ns->list, mstorage->pop3_box_vname,
-			     MAILBOX_FLAG_READONLY | MAILBOX_FLAG_POP3_SESSION);
+	box = mailbox_alloc(ns->list, mstorage->pop3_box_vname,
+			    MAILBOX_FLAG_READONLY | MAILBOX_FLAG_POP3_SESSION);
+	mailbox_set_reason(box, "pop3_migration");
+	return box;
 }
 
 static int pop3_map_read(struct mail_storage *storage, struct mailbox *pop3_box)
--- a/src/plugins/quota/quota-count.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/plugins/quota/quota-count.c	Sat Apr 01 21:43:16 2017 +0300
@@ -42,6 +42,7 @@
 	}
 
 	box = mailbox_alloc(ns->list, vname, MAILBOX_FLAG_READONLY);
+	mailbox_set_reason(box, "quota count");
 	if ((box->storage->class_flags & MAIL_STORAGE_CLASS_FLAG_NOQUOTA) != 0) {
 		/* quota doesn't exist for this mailbox/storage */
 		ret = 0;
@@ -295,6 +296,7 @@
 	iter = quota_mailbox_iter_begin(root);
 	while ((info = quota_mailbox_iter_next(iter)) != NULL) {
 		box = mailbox_alloc(info->ns->list, info->vname, 0);
+		mailbox_set_reason(box, "quota recalculate");
 		if (quota_count_recalculate_box(box) < 0)
 			ret = -1;
 		mailbox_free(&box);
--- a/src/plugins/quota/quota-status.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/plugins/quota/quota-status.c	Sat Apr 01 21:43:16 2017 +0300
@@ -61,6 +61,7 @@
 
 	ns = mail_namespace_find_inbox(user->namespaces);
 	box = mailbox_alloc(ns->list, "INBOX", MAILBOX_FLAG_POST_SESSION);
+	mailbox_set_reason(box, "quota status");
 
 	ctx = quota_transaction_begin(box);
 	ret = quota_test_alloc(ctx, I_MAX(1, mail_size));
--- a/src/plugins/trash/trash-plugin.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/plugins/trash/trash-plugin.c	Sat Apr 01 21:43:16 2017 +0300
@@ -52,6 +52,7 @@
 	struct mail_search_args *search_args;
 
 	trash->box = mailbox_alloc(trash->ns->list, trash->name, 0);
+	mailbox_set_reason(trash->box, "trash plugin");
 	if (mailbox_open(trash->box) < 0) {
 		mailbox_free(&trash->box);
 		return 0;
--- a/src/plugins/virtual/virtual-config.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/plugins/virtual/virtual-config.c	Sat Apr 01 21:43:16 2017 +0300
@@ -373,6 +373,7 @@
 		return 1;
 
 	box = mailbox_alloc(info->ns->list, info->vname, MAILBOX_FLAG_READONLY);
+	mailbox_set_reason(box, "virtual mailbox metadata match");
 	for (i = 0; i < count; i++) {
 		if ((ret = virtual_config_box_metadata_match(box, boxes[i], error_r)) <= 0)
 			break;
--- a/src/plugins/virtual/virtual-storage.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/plugins/virtual/virtual-storage.c	Sat Apr 01 21:43:16 2017 +0300
@@ -192,6 +192,8 @@
 	ns = mail_namespace_find(user->namespaces, mailbox);
 	bbox->box = mailbox_alloc(ns->list, mailbox, flags);
 	MODULE_CONTEXT_SET(bbox->box, virtual_storage_module, bbox);
+	mailbox_set_reason(bbox->box, mbox->box.reason == NULL ? "virtual mailbox" :
+		t_strdup_printf("virtual mailbox: %s", mbox->box.reason));
 
 	if (mailbox_exists(bbox->box, TRUE, &existence) < 0)
 		return virtual_backend_box_open_failed(mbox, bbox);
--- a/src/pop3/pop3-client.c	Sat Apr 01 21:16:37 2017 +0300
+++ b/src/pop3/pop3-client.c	Sat Apr 01 21:43:16 2017 +0300
@@ -466,6 +466,7 @@
 	if (!client->set->pop3_no_flag_updates)
 		flags |= MAILBOX_FLAG_DROP_RECENT;
 	client->mailbox = mailbox_alloc(client->inbox_ns->list, "INBOX", flags);
+	mailbox_set_reason(client->mailbox, "POP3 INBOX");
 	if (mailbox_open(client->mailbox) < 0) {
 		*error_r = t_strdup_printf("Couldn't open INBOX: %s",
 			mailbox_get_last_internal_error(client->mailbox, NULL));