From: Timo Sirainen Date: Thu, 20 Jan 2011 17:21:20 +0000 (+0200) Subject: lib-storage: Added mailbox_get_last_*error() wrappers and use them. X-Git-Tag: 2.1.alpha1~420 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11352dc3e4b29f3d2763c82f8ea4f99e8daf4fa3;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added mailbox_get_last_*error() wrappers and use them. --- diff --git a/src/doveadm/doveadm-mail-fetch.c b/src/doveadm/doveadm-mail-fetch.c index fd8fe171a2..c8d796f177 100644 --- a/src/doveadm/doveadm-mail-fetch.c +++ b/src/doveadm/doveadm-mail-fetch.c @@ -387,12 +387,9 @@ static void cmd_fetch_mail(struct fetch_cmd_context *ctx) 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)); } } } diff --git a/src/doveadm/doveadm-mail-import.c b/src/doveadm/doveadm-mail-import.c index 3f11b0cee0..3994279251 100644 --- a/src/doveadm/doveadm-mail-import.c +++ b/src/doveadm/doveadm-mail-import.c @@ -49,8 +49,7 @@ dest_mailbox_open_or_create(struct import_cmd_context *ctx, 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); @@ -59,8 +58,7 @@ dest_mailbox_open_or_create(struct import_cmd_context *ctx, } 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; } @@ -72,7 +70,6 @@ static int 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); @@ -89,14 +86,14 @@ cmd_import_box_contents(struct doveadm_mail_iter *iter, struct mail *src_mail, 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; diff --git a/src/doveadm/doveadm-mail-iter.c b/src/doveadm/doveadm-mail-iter.c index 26ba2fcdac..89e08c5ad4 100644 --- a/src/doveadm/doveadm-mail-iter.c +++ b/src/doveadm/doveadm-mail-iter.c @@ -10,7 +10,6 @@ struct doveadm_mail_iter { struct mail_search_args *search_args; struct mailbox *box; - struct mail_storage *storage; struct mailbox_transaction_context *t; struct mail_search_context *search_ctx; }; @@ -29,12 +28,11 @@ int doveadm_mail_iter_init(const struct mailbox_info *info, 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; @@ -57,13 +55,13 @@ doveadm_mail_iter_deinit_transaction(struct doveadm_mail_iter *iter) 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); diff --git a/src/doveadm/doveadm-mail-mailbox.c b/src/doveadm/doveadm-mail-mailbox.c index 5e7f8a43be..b0c4fc679e 100644 --- a/src/doveadm/doveadm-mail-mailbox.c +++ b/src/doveadm/doveadm-mail-mailbox.c @@ -203,10 +203,8 @@ cmd_mailbox_create_run(struct doveadm_mail_cmd_context *_ctx, 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, @@ -265,10 +263,8 @@ cmd_mailbox_delete_run(struct doveadm_mail_cmd_context *_ctx, 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, @@ -329,10 +325,8 @@ cmd_mailbox_rename_run(struct doveadm_mail_cmd_context *_ctx, 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) { diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index 53a6d442b7..721cc6b0a3 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -99,8 +99,7 @@ doveadm_mailbox_find_and_open(struct mail_user *user, const char *mailbox, 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; } @@ -115,8 +114,7 @@ int doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox, 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; } @@ -148,19 +146,16 @@ static void cmd_force_resync_run(struct doveadm_mail_cmd_context *_ctx, { 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); diff --git a/src/dsync/dsync-worker-local.c b/src/dsync/dsync-worker-local.c index a434156e48..52ee4e6196 100644 --- a/src/dsync/dsync-worker-local.c +++ b/src/dsync/dsync-worker-local.c @@ -561,10 +561,8 @@ local_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *_iter, 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; @@ -801,10 +799,8 @@ static int local_mailbox_open(struct local_dsync_worker *worker, 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; } @@ -861,11 +857,8 @@ iter_local_mailbox_close(struct local_dsync_worker_msg_iter *iter) 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); @@ -985,11 +978,8 @@ local_worker_msg_iter_next(struct dsync_worker_msg_iter *_iter, 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; } @@ -1195,8 +1185,7 @@ local_worker_create_allocated_mailbox(struct local_dsync_worker *worker, } 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; @@ -1274,10 +1263,8 @@ local_worker_delete_mailbox(struct dsync_worker *_worker, 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); @@ -1338,10 +1325,8 @@ local_worker_rename_mailbox(struct dsync_worker *_worker, 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); @@ -1445,8 +1430,7 @@ local_worker_update_mailbox(struct dsync_worker *_worker, 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); @@ -1668,12 +1652,9 @@ local_worker_save_msg_continue(struct local_dsync_worker *worker) } 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); } } @@ -1712,10 +1693,9 @@ local_worker_msg_save(struct dsync_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); diff --git a/src/imap/cmd-fetch.c b/src/imap/cmd-fetch.c index ded2533e3f..2e9efd5f0a 100644 --- a/src/imap/cmd-fetch.c +++ b/src/imap/cmd-fetch.c @@ -145,21 +145,18 @@ static bool cmd_fetch_finish(struct imap_fetch_context *ctx) 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; } diff --git a/src/imap/imap-commands-util.c b/src/imap/imap-commands-util.c index fd148e937e..0c2281696b 100644 --- a/src/imap/imap-commands-util.c +++ b/src/imap/imap-commands-util.c @@ -90,14 +90,12 @@ int client_open_save_dest_box(struct client_command_context *cmd, 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; diff --git a/src/imap/imap-status.c b/src/imap/imap-status.c index 6f30372e70..f0db5f3859 100644 --- a/src/imap/imap-status.c +++ b/src/imap/imap-status.c @@ -92,9 +92,7 @@ int imap_status_get(struct client_command_context *cmd, } 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) diff --git a/src/lda/main.c b/src/lda/main.c index 66cd33a6a9..a3754d23bb 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -387,7 +387,7 @@ int main(int argc, char *argv[]) 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 { @@ -396,12 +396,12 @@ int main(int argc, char *argv[]) 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 ? diff --git a/src/lib-lda/mail-deliver.c b/src/lib-lda/mail-deliver.c index 5b71477f3f..ed3d398ade 100644 --- a/src/lib-lda/mail-deliver.c +++ b/src/lib-lda/mail-deliver.c @@ -131,7 +131,6 @@ int mail_deliver_save_open(struct mail_deliver_save_open_context *ctx, 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 | @@ -166,14 +165,13 @@ int mail_deliver_save_open(struct mail_deliver_save_open_context *ctx, 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 */ @@ -185,7 +183,7 @@ int mail_deliver_save_open(struct mail_deliver_save_open_context *ctx, /* 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; 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 68c2efe0e3..2ea487d43f 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -504,7 +504,7 @@ rebuild_mailbox(struct mdbox_storage_rebuild_context *ctx, 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; @@ -649,7 +649,7 @@ static int rebuild_restore_msg(struct mdbox_storage_rebuild_context *ctx, 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. */ diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 688766e49b..670b9e9a6e 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -245,7 +245,7 @@ static int create_maildir(struct mailbox *box, bool verify) 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 diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 37bffd0ada..ed96649370 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -522,6 +522,20 @@ const char *mail_storage_get_last_error(struct mail_storage *storage, 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 & @@ -616,7 +630,7 @@ static int mailbox_open_full(struct mailbox *box, struct istream *input) 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; @@ -763,7 +777,6 @@ static bool mailbox_try_undelete(struct mailbox *box) int mailbox_delete(struct mailbox *box) { - enum mail_error error; int ret; if (*box->name == '\0') { @@ -779,8 +792,7 @@ int mailbox_delete(struct mailbox *box) 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 */ @@ -990,7 +1002,7 @@ int mailbox_sync_deinit(struct mailbox_sync_context **_ctx, 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); diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 87036f709f..9b9e0db225 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -329,6 +329,11 @@ int mail_storage_purge(struct mail_storage *storage); /* 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; diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index 211abbf900..5f2ce1b762 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -596,7 +596,7 @@ static int client_open_raw_mail(struct client *client, struct istream *input) 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; diff --git a/src/plugins/autocreate/autocreate-plugin.c b/src/plugins/autocreate/autocreate-plugin.c index 17de7a0ce4..9ab143d6b1 100644 --- a/src/plugins/autocreate/autocreate-plugin.c +++ b/src/plugins/autocreate/autocreate-plugin.c @@ -27,8 +27,7 @@ autocreate_mailbox(struct mail_namespace *namespaces, const char *name) 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); diff --git a/src/plugins/lazy-expunge/lazy-expunge-plugin.c b/src/plugins/lazy-expunge/lazy-expunge-plugin.c index e6069d9ace..9e35d8bf28 100644 --- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c @@ -83,8 +83,7 @@ mailbox_open_or_create(struct mailbox_list *list, const char *name, 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; @@ -93,8 +92,7 @@ mailbox_open_or_create(struct mailbox_list *list, const char *name, /* 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; } @@ -263,7 +261,7 @@ mailbox_move(struct mailbox *src_box, struct mailbox_list *dest_list, 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; @@ -292,12 +290,11 @@ mailbox_move_all_mails(struct mailbox *src_box, const char *dest_name) 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); @@ -366,7 +363,6 @@ static int lazy_expunge_mailbox_delete(struct mailbox *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; @@ -412,7 +408,7 @@ static int lazy_expunge_mailbox_delete(struct mailbox *box) 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); diff --git a/src/plugins/quota/quota-count.c b/src/plugins/quota/quota-count.c index 6a11e3ccc2..aca2b406af 100644 --- a/src/plugins/quota/quota-count.c +++ b/src/plugins/quota/quota-count.c @@ -33,7 +33,7 @@ quota_count_mailbox(struct quota_root *root, struct mail_namespace *ns, 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; diff --git a/src/plugins/snarf/snarf-plugin.c b/src/plugins/snarf/snarf-plugin.c index 0210cedcdc..e576cfcec3 100644 --- a/src/plugins/snarf/snarf-plugin.c +++ b/src/plugins/snarf/snarf-plugin.c @@ -62,8 +62,7 @@ static int snarf(struct mailbox *srcbox, struct mailbox *destbox) 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) diff --git a/src/plugins/virtual/virtual-storage.c b/src/plugins/virtual/virtual-storage.c index 32835d64a7..3dab618094 100644 --- a/src/plugins/virtual/virtual-storage.c +++ b/src/plugins/virtual/virtual-storage.c @@ -59,7 +59,7 @@ void virtual_box_copy_error(struct mailbox *dest, struct mailbox *src) 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); @@ -139,8 +139,7 @@ static int virtual_backend_box_open_failed(struct virtual_mailbox *mbox, 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) { diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index 11b703fbf3..09a6c7ffda 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -67,7 +67,6 @@ static void client_idle_timeout(struct client *client) 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; @@ -81,8 +80,7 @@ pop3_mail_get_size(struct client *client, struct mail *mail, uoff_t *size_r) 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; @@ -94,7 +92,7 @@ pop3_mail_get_size(struct client *client, struct mail *mail, uoff_t *size_r) 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; @@ -187,11 +185,7 @@ static int init_mailbox(struct client *client, const char **error_r) } 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) { @@ -293,8 +287,8 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user, 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"); @@ -555,9 +549,6 @@ int client_send_line(struct client *client, const char *fmt, ...) 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."); @@ -565,9 +556,8 @@ void client_send_storage_error(struct client *client) 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)