array_foreach(&ctx->fields, field) {
ctx->cur_field = field;
if (field->print(ctx) < 0) {
- struct mail_storage *storage =
- mailbox_get_storage(mail->box);
-
i_error("fetch(%s) failed for box=%s uid=%u: %s",
field->name, mailbox_get_vname(mail->box),
- mail->uid, mail_storage_get_last_error(storage, NULL));
+ mail->uid, mailbox_get_last_error(mail->box, NULL));
}
}
}
box = mailbox_alloc(ns->list, storage_name, MAILBOX_FLAG_SAVEONLY |
MAILBOX_FLAG_KEEP_RECENT);
if (mailbox_create(box, NULL, FALSE) < 0) {
- errstr = mail_storage_get_last_error(mailbox_get_storage(box),
- &error);
+ errstr = mailbox_get_last_error(box, &error);
if (error != MAIL_ERROR_EXISTS) {
i_error("Couldn't create mailbox %s: %s", name, errstr);
mailbox_free(&box);
}
if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
i_error("Syncing mailbox %s failed: %s", name,
- mail_storage_get_last_error(mailbox_get_storage(box),
- NULL));
+ mailbox_get_last_error(box, NULL));
mailbox_free(&box);
return -1;
}
cmd_import_box_contents(struct doveadm_mail_iter *iter, struct mail *src_mail,
struct mailbox *dest_box)
{
- struct mail_storage *dest_storage = mailbox_get_storage(dest_box);
struct mail_save_context *save_ctx;
struct mailbox_transaction_context *dest_trans;
const char *mailbox = mailbox_get_vname(dest_box);
if (mailbox_copy(&save_ctx, src_mail) < 0) {
i_error("Copying box=%s uid=%u failed: %s",
mailbox, src_mail->uid,
- mail_storage_get_last_error(dest_storage, NULL));
+ mailbox_get_last_error(dest_box, NULL));
ret = -1;
}
} while (doveadm_mail_iter_next(iter, src_mail));
if (mailbox_transaction_commit(&dest_trans) < 0) {
i_error("Committing copied mails to %s failed: %s", mailbox,
- mail_storage_get_last_error(dest_storage, NULL));
+ mailbox_get_last_error(dest_box, NULL));
ret = -1;
}
return ret;
struct mail_search_args *search_args;
struct mailbox *box;
- struct mail_storage *storage;
struct mailbox_transaction_context *t;
struct mail_search_context *search_ctx;
};
iter->box = mailbox_alloc(info->ns->list, storage_name,
MAILBOX_FLAG_KEEP_RECENT |
MAILBOX_FLAG_IGNORE_ACLS);
- iter->storage = mailbox_get_storage(iter->box);
iter->search_args = search_args;
if (mailbox_sync(iter->box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
i_error("Syncing mailbox %s failed: %s", info->name,
- mail_storage_get_last_error(iter->storage, NULL));
+ mailbox_get_last_error(iter->box, NULL));
mailbox_free(&iter->box);
i_free(iter);
return -1;
if (mailbox_search_deinit(&iter->search_ctx) < 0) {
i_error("Searching mailbox %s failed: %s",
mailbox_get_vname(iter->box),
- mail_storage_get_last_error(iter->storage, NULL));
+ mailbox_get_last_error(iter->box, NULL));
ret = -1;
}
if (mailbox_transaction_commit(&iter->t) < 0) {
i_error("Commiting mailbox %s failed: %s",
mailbox_get_vname(iter->box),
- mail_storage_get_last_error(iter->storage, NULL));
+ mailbox_get_last_error(iter->box, NULL));
ret = -1;
}
mail_search_args_deinit(iter->search_args);
box = mailbox_alloc(ns->list, storage_name, 0);
if (mailbox_create(box, NULL, directory) < 0) {
- struct mail_storage *storage = mailbox_get_storage(box);
-
i_error("Can't create mailbox %s: %s", *namep,
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(box, NULL));
}
if (ctx->ctx.subscriptions) {
if (mailbox_list_set_subscribed(ns->list, storage_name,
box = mailbox_alloc(ns->list, storage_name, 0);
if (mailbox_delete(box) < 0) {
- struct mail_storage *storage = mailbox_get_storage(box);
-
i_error("Can't delete mailbox %s: %s", *namep,
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(box, NULL));
}
if (ctx->ctx.subscriptions) {
if (mailbox_list_set_subscribed(ns->list, storage_name,
oldbox = mailbox_alloc(oldns->list, oldname, 0);
newbox = mailbox_alloc(newns->list, newname, 0);
if (mailbox_rename(oldbox, newbox, TRUE) < 0) {
- struct mail_storage *storage = mailbox_get_storage(oldbox);
-
i_error("Can't rename mailbox %s to %s: %s", oldname, newname,
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(oldbox, NULL));
}
if (ctx->ctx.subscriptions) {
if (mailbox_list_set_subscribed(oldns->list, oldname, FALSE) < 0) {
box = doveadm_mailbox_find(user, mailbox);
if (mailbox_open(box) < 0) {
i_error("Opening mailbox %s failed: %s", mailbox,
- mail_storage_get_last_error(mailbox_get_storage(box),
- NULL));
+ mailbox_get_last_error(box, NULL));
mailbox_free(&box);
return -1;
}
return -1;
if (mailbox_sync(*box_r, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
i_error("Syncing mailbox %s failed: %s", mailbox,
- mail_storage_get_last_error(mailbox_get_storage(*box_r),
- NULL));
+ mailbox_get_last_error(*box_r, NULL));
mailbox_free(box_r);
return -1;
}
{
struct force_resync_cmd_context *ctx =
(struct force_resync_cmd_context *)_ctx;
- struct mail_storage *storage;
struct mailbox *box;
if (doveadm_mailbox_find_and_open(user, ctx->mailbox, &box) < 0) {
_ctx->failed = TRUE;
return;
}
- storage = mailbox_get_storage(box);
if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC |
MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) < 0) {
i_error("Forcing a resync on mailbox %s failed: %s",
- ctx->mailbox,
- mail_storage_get_last_error(storage, NULL));
+ ctx->mailbox, mailbox_get_last_error(box, NULL));
_ctx->failed = TRUE;
}
mailbox_free(&box);
box = mailbox_alloc(info->ns->list, storage_name, flags);
if (mailbox_get_status(box, status_items, &status) < 0 ||
mailbox_get_metadata(box, metadata_items, &metadata) < 0) {
- struct mail_storage *storage = mailbox_get_storage(box);
-
i_error("Failed to sync mailbox %s: %s", info->name,
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(box, NULL));
mailbox_free(&box);
_iter->failed = TRUE;
return -1;
box = mailbox_alloc(lbox->ns->list, lbox->storage_name, flags);
if (mailbox_sync(box, 0) < 0 ||
mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
- struct mail_storage *storage = mailbox_get_storage(box);
-
i_error("Failed to sync mailbox %s: %s", lbox->storage_name,
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(box, NULL));
mailbox_free(&box);
return -1;
}
iter->expunges_set = FALSE;
mail_free(&iter->mail);
if (mailbox_search_deinit(&iter->search_ctx) < 0) {
- struct mail_storage *storage =
- mailbox_get_storage(iter->mail->box);
-
i_error("msg search failed: %s",
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(iter->mail->box, NULL));
iter->iter.failed = TRUE;
}
(void)mailbox_transaction_commit(&trans);
if (mail_get_special(iter->mail, MAIL_FETCH_GUID, &guid) < 0) {
if (!iter->mail->expunged) {
- struct mail_storage *storage =
- mailbox_get_storage(iter->mail->box);
-
i_error("msg guid lookup failed: %s",
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(iter->mail->box, NULL));
_iter->failed = TRUE;
return -1;
}
}
if (mailbox_create(box, &update, FALSE) < 0) {
- errstr = mail_storage_get_last_error(mailbox_get_storage(box),
- &error);
+ errstr = mailbox_get_last_error(box, &error);
if (error == MAIL_ERROR_EXISTS) {
/* mailbox already exists */
return 0;
dsync_box->last_change);
box = mailbox_alloc(lbox->ns->list, lbox->storage_name, 0);
if (mailbox_delete(box) < 0) {
- struct mail_storage *storage = mailbox_get_storage(box);
-
i_error("Can't delete mailbox %s: %s", lbox->storage_name,
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(box, NULL));
dsync_worker_set_failure(_worker);
}
mailbox_free(&box);
old_box = mailbox_alloc(list, lbox->storage_name, 0);
new_box = mailbox_alloc(list, newname, 0);
if (mailbox_rename(old_box, new_box, FALSE) < 0) {
- struct mail_storage *storage = mailbox_get_storage(old_box);
-
i_error("Can't rename mailbox %s to %s: %s", lbox->storage_name,
- newname, mail_storage_get_last_error(storage, NULL));
+ newname, mailbox_get_last_error(old_box, NULL));
dsync_worker_set_failure(_worker);
} else {
lbox->storage_name = p_strdup(worker->pool, newname);
if (mailbox_update(box, &update) < 0) {
dsync_worker_set_failure(_worker);
i_error("Can't update mailbox %s: %s", dsync_box->name,
- mail_storage_get_last_error(mailbox_get_storage(box),
- NULL));
+ mailbox_get_last_error(box, NULL));
}
mailbox_free(&box);
} else {
i_assert(worker->save_input->eof);
if (mailbox_save_finish(&worker->save_ctx) < 0) {
- struct mail_storage *storage =
- mailbox_get_storage(dest_box);
-
i_error("Can't save message to mailbox %s: %s",
mailbox_get_vname(dest_box),
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(dest_box, NULL));
dsync_worker_set_failure(&worker->worker);
}
}
mailbox_save_set_received_date(save_ctx, data->received_date, 0);
if (mailbox_save_begin(&save_ctx, data->input) < 0) {
- struct mail_storage *storage = mailbox_get_storage(dest_box);
i_error("Can't save message to mailbox %s: %s",
mailbox_get_vname(dest_box),
- mail_storage_get_last_error(storage, NULL));
+ mailbox_get_last_error(dest_box, NULL));
mailbox_save_cancel(&save_ctx);
dsync_worker_set_failure(_worker);
callback(context);
ctx->failed = TRUE;
if (ctx->failed) {
- struct mail_storage *storage;
- const char *error_string;
- enum mail_error error;
+ const char *errstr;
if (ctx->client->output->closed) {
client_disconnect(cmd->client, "Disconnected");
return TRUE;
}
- storage = mailbox_get_storage(cmd->client->mailbox);
- error_string = mail_storage_get_last_error(storage, &error);
+ errstr = mailbox_get_last_error(cmd->client->mailbox, NULL);
/* We never want to reply NO to FETCH requests,
BYE is preferrable (see imap-ml for reasons). */
- client_disconnect_with_error(cmd->client, error_string);
+ client_disconnect_with_error(cmd->client, errstr);
return TRUE;
}
box = mailbox_alloc(ns->list, storage_name,
MAILBOX_FLAG_SAVEONLY | MAILBOX_FLAG_KEEP_RECENT);
if (mailbox_open(box) < 0) {
- struct mail_storage *storage = mailbox_get_storage(box);
-
- error_string = mail_storage_get_last_error(storage, &error);
+ error_string = mailbox_get_last_error(box, &error);
if (error == MAIL_ERROR_NOTFOUND) {
client_send_tagline(cmd, t_strdup_printf(
"NO [TRYCREATE] %s", error_string));
} else {
- client_send_storage_error(cmd, storage);
+ client_send_storage_error(cmd, mailbox_get_storage(box));
}
mailbox_free(&box);
return -1;
}
if (ret < 0) {
- struct mail_storage *storage = mailbox_get_storage(box);
-
- *error_r = mail_storage_get_last_error(storage, &error);
+ *error_r = mailbox_get_last_error(box, &error);
*error_r = imap_get_error_string(cmd, *error_r, error);
}
if (box != client->mailbox)
MAILBOX_FLAG_NO_INDEX_FILES);
if (mailbox_open_stream(box, input) < 0) {
i_fatal("Can't open delivery mail as raw: %s",
- mail_storage_get_last_error(box->storage, &error));
+ mailbox_get_last_error(box, &error));
}
i_stream_unref(&input);
} else {
MAILBOX_FLAG_NO_INDEX_FILES);
if (mailbox_open(box) < 0) {
i_fatal("Can't open delivery mail as raw: %s",
- mail_storage_get_last_error(box->storage, &error));
+ mailbox_get_last_error(box, &error));
}
}
if (mailbox_sync(box, 0) < 0) {
i_fatal("Can't sync delivery mail: %s",
- mail_storage_get_last_error(box->storage, &error));
+ mailbox_get_last_error(box, &error));
}
raw_box = (struct raw_mailbox *)box;
raw_box->envelope_sender = ctx.src_envelope_sender != NULL ?
enum mail_error *error_r, const char **error_str_r)
{
struct mail_namespace *ns;
- struct mail_storage *storage;
struct mailbox *box;
enum mailbox_flags flags =
MAILBOX_FLAG_KEEP_RECENT | MAILBOX_FLAG_SAVEONLY |
if (mailbox_open(box) == 0)
return 0;
- storage = mailbox_get_storage(box);
- *error_str_r = mail_storage_get_last_error(storage, error_r);
+ *error_str_r = mailbox_get_last_error(box, error_r);
if (!ctx->lda_mailbox_autocreate || *error_r != MAIL_ERROR_NOTFOUND)
return -1;
/* try creating it. */
if (mailbox_create(box, NULL, FALSE) < 0) {
- *error_str_r = mail_storage_get_last_error(storage, error_r);
+ *error_str_r = mailbox_get_last_error(box, error_r);
if (*error_r != MAIL_ERROR_EXISTS)
return -1;
/* someone else just created it */
/* and try opening again */
if (mailbox_sync(box, 0) < 0) {
- *error_str_r = mail_storage_get_last_error(storage, error_r);
+ *error_str_r = mailbox_get_last_error(box, error_r);
return -1;
}
return 0;
MAILBOX_FLAG_IGNORE_ACLS);
i_assert(box->storage == &ctx->storage->storage.storage);
if (dbox_mailbox_open(box) < 0) {
- (void)mail_storage_get_last_error(box->storage, &error);
+ error = mailbox_get_last_mail_error(box);
mailbox_free(&box);
if (error == MAIL_ERROR_TEMP)
return -1;
if (dbox_mailbox_open(box) == 0)
break;
- (void)mail_storage_get_last_error(box->storage, &error);
+ error = mailbox_get_last_mail_error(box);
if (error == MAIL_ERROR_NOTFOUND && !created) {
/* mailbox doesn't exist currently? see if creating
it helps. */
if (mkdir_verify(box->storage, box->list->ns, path,
perm->dir_create_mode, perm->file_create_gid,
perm->file_create_gid_origin, verify) < 0) {
- (void)mail_storage_get_last_error(box->storage, &error);
+ error = mailbox_get_last_mail_error(box);
if (error != MAIL_ERROR_EXISTS)
return -1;
/* try to create all of the directories in case one
return storage->error_string;
}
+const char *mailbox_get_last_error(struct mailbox *box,
+ enum mail_error *error_r)
+{
+ return mail_storage_get_last_error(box->storage, error_r);
+}
+
+enum mail_error mailbox_get_last_mail_error(struct mailbox *box)
+{
+ enum mail_error error;
+
+ (void)mail_storage_get_last_error(box->storage, &error);
+ return error;
+}
+
bool mail_storage_is_mailbox_file(struct mail_storage *storage)
{
return (storage->class_flags &
if (ret < 0 && !box->storage->user->inbox_open_error_logged) {
box->storage->user->inbox_open_error_logged = TRUE;
i_error("Opening INBOX failed: %s",
- mail_storage_get_last_error(box->storage, NULL));
+ mailbox_get_last_error(box, NULL));
}
} T_END;
int mailbox_delete(struct mailbox *box)
{
- enum mail_error error;
int ret;
if (*box->name == '\0') {
box->deleting = TRUE;
if (mailbox_open(box) < 0) {
- (void)mail_storage_get_last_error(box->storage, &error);
- if (error != MAIL_ERROR_NOTFOUND)
+ if (mailbox_get_last_mail_error(box) != MAIL_ERROR_NOTFOUND)
return -1;
if (!box->mailbox_deleted) {
/* \noselect mailbox */
ret = box->v.sync_deinit(ctx, status_r);
if (ret < 0 && box->inbox_user &&
!box->storage->user->inbox_open_error_logged) {
- errormsg = mail_storage_get_last_error(box->storage, &error);
+ errormsg = mailbox_get_last_error(box, &error);
if (error == MAIL_ERROR_NOTPOSSIBLE) {
box->storage->user->inbox_open_error_logged = TRUE;
i_error("Syncing INBOX failed: %s", errormsg);
/* Returns the error message of last occurred error. */
const char *mail_storage_get_last_error(struct mail_storage *storage,
enum mail_error *error_r);
+/* Wrapper for mail_storage_get_last_error(); */
+const char *mailbox_get_last_error(struct mailbox *box,
+ enum mail_error *error_r);
+/* Wrapper for mail_storage_get_last_error(); */
+enum mail_error mailbox_get_last_mail_error(struct mailbox *box);
/* Returns TRUE if mailboxes are files. */
bool mail_storage_is_mailbox_file(struct mail_storage *storage) ATTR_PURE;
if (mailbox_open_stream(box, input) < 0 ||
mailbox_sync(box, 0) < 0) {
i_error("Can't open delivery mail as raw: %s",
- mail_storage_get_last_error(box->storage, &error));
+ mailbox_get_last_error(box, &error));
mailbox_free(&box);
client_rcpt_fail_all(client);
return -1;
box = mailbox_alloc(ns->list, name, 0);
if (mailbox_create(box, NULL, FALSE) < 0) {
- str = mail_storage_get_last_error(mailbox_get_storage(box),
- &error);
+ str = mailbox_get_last_error(box, &error);
if (error != MAIL_ERROR_EXISTS && ns->mail_set->mail_debug) {
i_debug("autocreate: Failed to create mailbox %s: %s",
name, str);
return box;
}
- *error_r = mail_storage_get_last_error(mailbox_get_storage(box),
- &error);
+ *error_r = mailbox_get_last_error(box, &error);
if (error != MAIL_ERROR_NOTFOUND) {
mailbox_free(&box);
return NULL;
/* try creating and re-opening it. */
if (mailbox_create(box, NULL, FALSE) < 0 ||
mailbox_open(box) < 0) {
- *error_r = mail_storage_get_last_error(mailbox_get_storage(box),
- NULL);
+ *error_r = mailbox_get_last_error(box, NULL);
mailbox_free(&box);
return NULL;
}
break;
mailbox_free(&dest_box);
- mail_storage_get_last_error(src_box->storage, &error);
+ error = mailbox_get_last_mail_error(src_box);
switch (error) {
case MAIL_ERROR_EXISTS:
break;
struct mail_save_context *save_ctx;
struct mail *mail;
const char *errstr;
- enum mail_error error;
int ret;
dest_box = mailbox_alloc(src_box->list, dest_name, 0);
if (mailbox_open(dest_box) < 0) {
- errstr = mail_storage_get_last_error(dest_box->storage, &error);
+ errstr = mailbox_get_last_error(dest_box, NULL);
i_error("lazy_expunge: Couldn't open DELETE dest mailbox "
"%s: %s", dest_name, errstr);
mailbox_free(&dest_box);
struct mail_namespace *expunge_ns, *dest_ns;
struct mailbox *expunge_box;
const char *destname, *str;
- enum mail_error error;
struct tm *tm;
char timestamp[256];
int ret;
since it's not really deleted in the lazy-expunge namespace,
we might want to change it again. so mark the index undeleted. */
if (mailbox_open(expunge_box) < 0) {
- str = mail_storage_get_last_error(expunge_box->storage, &error);
+ str = mailbox_get_last_error(expunge_box, NULL);
i_error("lazy_expunge: Couldn't open DELETEd mailbox "
"%s: %s", expunge_box->name, str);
mailbox_free(&expunge_box);
box = mailbox_alloc(ns->list, storage_name,
MAILBOX_FLAG_READONLY | MAILBOX_FLAG_KEEP_RECENT);
if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
- mail_storage_get_last_error(mailbox_get_storage(box), &error);
+ error = mailbox_get_last_mail_error(box);
mailbox_free(&box);
if (error == MAIL_ERROR_TEMP)
return -1;
save_ctx = mailbox_save_alloc(dest_trans);
if (mailbox_copy(&save_ctx, mail) < 0 && !mail->expunged) {
- (void)mail_storage_get_last_error(destbox->storage,
- &error);
+ error = mailbox_get_last_mail_error(destbox);
/* if we failed because of out of disk space, just
move those messages we managed to move so far. */
if (error != MAIL_ERROR_NOSPACE)
enum mail_error error;
name = get_user_visible_mailbox_name(src);
- str = mail_storage_get_last_error(src->storage, &error);
+ str = mailbox_get_last_error(src, &error);
str = t_strdup_printf("%s (for backend mailbox %s)", str, name);
mail_storage_set_error(dest->storage, error, str);
enum mail_error error;
const char *str, *name;
- str = mail_storage_get_last_error(mailbox_get_storage(bbox->box),
- &error);
+ str = mailbox_get_last_error(bbox->box, &error);
name = t_strdup(get_user_visible_mailbox_name(bbox->box));
mailbox_free(&bbox->box);
if (error == MAIL_ERROR_NOTFOUND) {
static int
pop3_mail_get_size(struct client *client, struct mail *mail, uoff_t *size_r)
{
- struct mail_storage *storage;
enum mail_error error;
int ret;
if (ret == 0)
return 0;
- storage = mailbox_get_storage(mail->box);
- (void)mail_storage_get_last_error(storage, &error);
+ (void)mailbox_get_last_error(mail->box, &error);
if (error != MAIL_ERROR_NOTPOSSIBLE)
return -1;
if (ret == 0)
return 0;
- (void)mail_storage_get_last_error(storage, &error);
+ (void)mailbox_get_last_error(mail->box, &error);
if (error != MAIL_ERROR_NOTPOSSIBLE)
return -1;
}
if (ret < 0) {
- struct mail_storage *storage;
- enum mail_error error;
-
- storage = mailbox_get_storage(client->mailbox);
- *error_r = mail_storage_get_last_error(storage, &error);
+ *error_r = mailbox_get_last_error(client->mailbox, NULL);
client_send_storage_error(client);
} else {
if (failed_uid == last_failed_uid && failed_uid != 0) {
storage = mailbox_get_storage(client->mailbox);
if (mailbox_open(client->mailbox) < 0) {
errmsg = t_strdup_printf("Couldn't open INBOX: %s",
- mail_storage_get_last_error(storage,
- &error));
+ mailbox_get_last_error(client->mailbox,
+ &error));
i_error("%s", errmsg);
client_send_line(client, "-ERR [IN-USE] %s", errmsg);
client_destroy(client, "Couldn't open INBOX");
void client_send_storage_error(struct client *client)
{
- struct mail_storage *storage;
- enum mail_error error;
-
if (mailbox_is_inconsistent(client->mailbox)) {
client_send_line(client, "-ERR Mailbox is in inconsistent "
"state, please relogin.");
return;
}
- storage = mailbox_get_storage(client->mailbox);
client_send_line(client, "-ERR %s",
- mail_storage_get_last_error(storage, &error));
+ mailbox_get_last_error(client->mailbox, NULL));
}
bool client_handle_input(struct client *client)