Added to the most important places.
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));
}
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) {
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
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) {
*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",
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",
}
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));
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);
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));
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" :
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",
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;
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));
}
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
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. */
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;
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);
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
/* 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);
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);
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);
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);
/* 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);
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) {
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;
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;
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));
} 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);
}
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",
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;
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);
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);
}
*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);
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) {
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);
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;
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",
/* 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 &&
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);
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;
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)
}
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;
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);
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));
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;
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;
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);
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));