diff --git a/src/doveadm/doveadm-mail-copymove.c b/src/doveadm/doveadm-mail-copymove.c index 14b3d9d8ef..8e5b700912 100644 --- a/src/doveadm/doveadm-mail-copymove.c +++ b/src/doveadm/doveadm-mail-copymove.c @@ -108,6 +108,7 @@ cmd_copy_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) 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)); diff --git a/src/doveadm/doveadm-mail-import.c b/src/doveadm/doveadm-mail-import.c index cabd369ab4..302401e548 100644 --- a/src/doveadm/doveadm-mail-import.c +++ b/src/doveadm/doveadm-mail-import.c @@ -63,6 +63,7 @@ dest_mailbox_open_or_create(struct import_cmd_context *ctx, } 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) { diff --git a/src/doveadm/doveadm-mail-index.c b/src/doveadm/doveadm-mail-index.c index 2656dece8c..a16622436a 100644 --- a/src/doveadm/doveadm-mail-index.c +++ b/src/doveadm/doveadm-mail-index.c @@ -106,6 +106,7 @@ cmd_index_box(struct index_cmd_context *ctx, const struct mailbox_info *info) 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 diff --git a/src/doveadm/doveadm-mail-iter.c b/src/doveadm/doveadm-mail-iter.c index 44186aaab0..a348c285c0 100644 --- a/src/doveadm/doveadm-mail-iter.c +++ b/src/doveadm/doveadm-mail-iter.c @@ -37,6 +37,7 @@ int doveadm_mail_iter_init(struct doveadm_mail_cmd_context *ctx, 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) { diff --git a/src/doveadm/doveadm-mail-mailbox-metadata.c b/src/doveadm/doveadm-mail-mailbox-metadata.c index c3ed7482a8..357adef381 100644 --- a/src/doveadm/doveadm-mail-mailbox-metadata.c +++ b/src/doveadm/doveadm-mail-mailbox-metadata.c @@ -46,6 +46,7 @@ cmd_mailbox_metadata_open_mailbox(struct metadata_cmd_context *mctx, *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", diff --git a/src/doveadm/doveadm-mail-mailbox-status.c b/src/doveadm/doveadm-mail-mailbox-status.c index 316bbd47be..eb91542f5d 100644 --- a/src/doveadm/doveadm-mail-mailbox-status.c +++ b/src/doveadm/doveadm-mail-mailbox-status.c @@ -127,6 +127,7 @@ status_mailbox(struct status_cmd_context *ctx, const struct mailbox_info *info) 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", diff --git a/src/doveadm/doveadm-mail-mailbox.c b/src/doveadm/doveadm-mail-mailbox.c index c4dbca8a59..b7b5c52d11 100644 --- a/src/doveadm/doveadm-mail-mailbox.c +++ b/src/doveadm/doveadm-mail-mailbox.c @@ -242,6 +242,7 @@ cmd_mailbox_create_run(struct doveadm_mail_cmd_context *_ctx, } 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 @@ cmd_mailbox_delete_run(struct doveadm_mail_cmd_context *_ctx, 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 @@ cmd_mailbox_rename_run(struct doveadm_mail_cmd_context *_ctx, 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 @@ cmd_mailbox_subscribe_run(struct doveadm_mail_cmd_context *_ctx, 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 @@ int cmd_mailbox_update_run(struct doveadm_mail_cmd_context *_ctx, 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", diff --git a/src/doveadm/doveadm-mail-save.c b/src/doveadm/doveadm-mail-save.c index 5badfdb7c0..3481f619a2 100644 --- a/src/doveadm/doveadm-mail-save.c +++ b/src/doveadm/doveadm-mail-save.c @@ -90,6 +90,7 @@ cmd_save_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) 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; diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index 639ca4f7c7..5549f09c55 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -285,6 +285,7 @@ static int cmd_force_resync_box(struct doveadm_mail_cmd_context *ctx, 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)); diff --git a/src/imap/cmd-create.c b/src/imap/cmd-create.c index 36cfbc6b84..f581c30416 100644 --- a/src/imap/cmd-create.c +++ b/src/imap/cmd-create.c @@ -38,6 +38,7 @@ bool cmd_create(struct client_command_context *cmd) } 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 diff --git a/src/imap/cmd-delete.c b/src/imap/cmd-delete.c index 17b077851b..4e34c1d0d3 100644 --- a/src/imap/cmd-delete.c +++ b/src/imap/cmd-delete.c @@ -21,6 +21,7 @@ bool cmd_delete(struct client_command_context *cmd) 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. */ diff --git a/src/imap/cmd-getmetadata.c b/src/imap/cmd-getmetadata.c index 917979524d..9635a6cef4 100644 --- a/src/imap/cmd-getmetadata.c +++ b/src/imap/cmd-getmetadata.c @@ -410,6 +410,7 @@ cmd_getmetadata_try_mailbox(struct imap_getmetadata_context *ctx, 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; diff --git a/src/imap/cmd-notify.c b/src/imap/cmd-notify.c index 3d04873b3e..4c6aad975a 100644 --- a/src/imap/cmd-notify.c +++ b/src/imap/cmd-notify.c @@ -417,6 +417,7 @@ imap_notify_box_send_status(struct client_command_context *cmd, 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); diff --git a/src/imap/cmd-rename.c b/src/imap/cmd-rename.c index f9369e8f52..f74561bcc9 100644 --- a/src/imap/cmd-rename.c +++ b/src/imap/cmd-rename.c @@ -37,6 +37,8 @@ bool cmd_rename(struct client_command_context *cmd) 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 diff --git a/src/imap/cmd-resetkey.c b/src/imap/cmd-resetkey.c index bbac12c1c4..3ab164e487 100644 --- a/src/imap/cmd-resetkey.c +++ b/src/imap/cmd-resetkey.c @@ -49,6 +49,7 @@ cmd_resetkey_mailbox(struct client_command_context *cmd, /* 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); diff --git a/src/imap/cmd-select.c b/src/imap/cmd-select.c index bac30fc2e9..73dab9a0e5 100644 --- a/src/imap/cmd-select.c +++ b/src/imap/cmd-select.c @@ -291,6 +291,7 @@ select_open(struct imap_select_context *ctx, const char *mailbox, bool readonly) 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); diff --git a/src/imap/cmd-setmetadata.c b/src/imap/cmd-setmetadata.c index a89aab9e52..6182a8b63f 100644 --- a/src/imap/cmd-setmetadata.c +++ b/src/imap/cmd-setmetadata.c @@ -304,6 +304,7 @@ cmd_setmetadata_mailbox(struct imap_setmetadata_context *ctx, 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); diff --git a/src/imap/cmd-subscribe.c b/src/imap/cmd-subscribe.c index c8e1c02bcb..40b6a2d149 100644 --- a/src/imap/cmd-subscribe.c +++ b/src/imap/cmd-subscribe.c @@ -49,6 +49,7 @@ bool cmd_subscribe_full(struct client_command_context *cmd, bool subscribe) 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 @@ bool cmd_subscribe_full(struct client_command_context *cmd, bool subscribe) /* 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); diff --git a/src/imap/imap-commands-util.c b/src/imap/imap-commands-util.c index 8e8c04d8f1..d18361e40d 100644 --- a/src/imap/imap-commands-util.c +++ b/src/imap/imap-commands-util.c @@ -109,6 +109,7 @@ int client_open_save_dest_box(struct client_command_context *cmd, 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) { diff --git a/src/imap/imap-notify.c b/src/imap/imap-notify.c index 4eef79d381..c2020166db 100644 --- a/src/imap/imap-notify.c +++ b/src/imap/imap-notify.c @@ -57,6 +57,7 @@ static int imap_notify_status(struct imap_notify_namespace *notify_ns, 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 @@ bool imap_notify_match_mailbox(struct imap_notify_namespace *notify_ns, 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; diff --git a/src/imap/imap-state.c b/src/imap/imap-state.c index 02722aef64..e8bccb3fc3 100644 --- a/src/imap/imap-state.c +++ b/src/imap/imap-state.c @@ -573,6 +573,7 @@ import_state_mailbox_open(struct client *client, 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)); diff --git a/src/imap/imap-status.c b/src/imap/imap-status.c index b3ca1faa58..13e4512e85 100644 --- a/src/imap/imap-status.c +++ b/src/imap/imap-status.c @@ -74,6 +74,7 @@ int imap_status_get(struct client_command_context *cmd, } 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); } diff --git a/src/indexer/master-connection.c b/src/indexer/master-connection.c index 9ca4560501..a1be841f77 100644 --- a/src/indexer/master-connection.c +++ b/src/indexer/master-connection.c @@ -142,6 +142,7 @@ index_mailbox(struct master_connection *conn, struct mail_user *user, 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", diff --git a/src/lib-imap-storage/imap-metadata.c b/src/lib-imap-storage/imap-metadata.c index 38fa0e73b3..5097add7dd 100644 --- a/src/lib-imap-storage/imap-metadata.c +++ b/src/lib-imap-storage/imap-metadata.c @@ -244,6 +244,7 @@ imap_metadata_transaction_begin_server(struct mail_user *user) 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; diff --git a/src/lib-imap-storage/imap-msgpart-url.c b/src/lib-imap-storage/imap-msgpart-url.c index afb83b4999..319f74559f 100644 --- a/src/lib-imap-storage/imap-msgpart-url.c +++ b/src/lib-imap-storage/imap-msgpart-url.c @@ -129,8 +129,10 @@ int imap_msgpart_url_open_mailbox(struct imap_msgpart_url *mpurl, 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); diff --git a/src/lib-imap-urlauth/imap-urlauth-backend.c b/src/lib-imap-urlauth/imap-urlauth-backend.c index 783f9dcfd4..49bcc4580f 100644 --- a/src/lib-imap-urlauth/imap-urlauth-backend.c +++ b/src/lib-imap-urlauth/imap-urlauth-backend.c @@ -132,6 +132,7 @@ int imap_urlauth_backend_reset_all_keys(struct mail_user *user) 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); diff --git a/src/lib-lda/mail-deliver.c b/src/lib-lda/mail-deliver.c index fcca8c6edc..42822d4f20 100644 --- a/src/lib-lda/mail-deliver.c +++ b/src/lib-lda/mail-deliver.c @@ -230,6 +230,7 @@ int mail_deliver_save_open(struct mail_deliver_save_open_context *ctx, } *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 @@ mail_deliver_cache_update_post_commit(struct mailbox *orig_box, uint32_t uid) 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) { diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index 7c7e99b111..ffdafa2d1a 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -551,6 +551,7 @@ rebuild_mailbox(struct mdbox_storage_rebuild_context *ctx, 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 @@ static int rebuild_restore_msg(struct mdbox_storage_rebuild_context *ctx, 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; diff --git a/src/lib-storage/mail-autoexpunge.c b/src/lib-storage/mail-autoexpunge.c index eec43bb00a..1c4a626692 100644 --- a/src/lib-storage/mail-autoexpunge.c +++ b/src/lib-storage/mail-autoexpunge.c @@ -156,6 +156,7 @@ mailbox_autoexpunge_set(struct mail_namespace *ns, const char *vname, 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", diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 03eafb23ca..782056fb1d 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -1389,6 +1389,7 @@ static void mailbox_copy_cache_decisions_from_inbox(struct mailbox *box) /* 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 && diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index f0abf29dc8..d0a687304d 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -583,6 +583,7 @@ lmtp_rcpt_to_is_over_quota(struct client *client, 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); diff --git a/src/plugins/lazy-expunge/lazy-expunge-plugin.c b/src/plugins/lazy-expunge/lazy-expunge-plugin.c index b7dd0e297b..a9ed1d10de 100644 --- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c @@ -119,6 +119,7 @@ mailbox_open_or_create(struct mailbox_list *list, struct mailbox *src_box, 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; diff --git a/src/plugins/pop3-migration/pop3-migration-plugin.c b/src/plugins/pop3-migration/pop3-migration-plugin.c index 4197afd64b..80bead91c8 100644 --- a/src/plugins/pop3-migration/pop3-migration-plugin.c +++ b/src/plugins/pop3-migration/pop3-migration-plugin.c @@ -311,12 +311,15 @@ static struct mailbox *pop3_mailbox_alloc(struct mail_storage *storage) 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) diff --git a/src/plugins/quota/quota-count.c b/src/plugins/quota/quota-count.c index 9410b69099..21c2f08c62 100644 --- a/src/plugins/quota/quota-count.c +++ b/src/plugins/quota/quota-count.c @@ -42,6 +42,7 @@ quota_count_mailbox(struct quota_root *root, struct mail_namespace *ns, } 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 @@ static int quota_count_recalculate(struct quota_root *root) 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); diff --git a/src/plugins/quota/quota-status.c b/src/plugins/quota/quota-status.c index b1438ac0a7..762ef34a15 100644 --- a/src/plugins/quota/quota-status.c +++ b/src/plugins/quota/quota-status.c @@ -61,6 +61,7 @@ quota_check(struct mail_user *user, uoff_t mail_size, const char **error_r) 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)); diff --git a/src/plugins/trash/trash-plugin.c b/src/plugins/trash/trash-plugin.c index a851be90f2..de10b995df 100644 --- a/src/plugins/trash/trash-plugin.c +++ b/src/plugins/trash/trash-plugin.c @@ -52,6 +52,7 @@ static int trash_clean_mailbox_open(struct trash_mailbox *trash) 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; diff --git a/src/plugins/virtual/virtual-config.c b/src/plugins/virtual/virtual-config.c index cd5e7a170d..ed431cef91 100644 --- a/src/plugins/virtual/virtual-config.c +++ b/src/plugins/virtual/virtual-config.c @@ -373,6 +373,7 @@ virtual_config_metadata_match(const struct mailbox_info *info, 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; diff --git a/src/plugins/virtual/virtual-storage.c b/src/plugins/virtual/virtual-storage.c index d8d410af36..b05fc69dfc 100644 --- a/src/plugins/virtual/virtual-storage.c +++ b/src/plugins/virtual/virtual-storage.c @@ -192,6 +192,8 @@ static int virtual_backend_box_alloc(struct virtual_mailbox *mbox, 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); diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index c9b5eec247..22c9c768fd 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -466,6 +466,7 @@ int client_init_mailbox(struct client *client, const char **error_r) 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));