]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
authorTimo Sirainen <tss@iki.fi>
Thu, 20 Jan 2011 17:21:20 +0000 (19:21 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 20 Jan 2011 17:21:20 +0000 (19:21 +0200)
22 files changed:
src/doveadm/doveadm-mail-fetch.c
src/doveadm/doveadm-mail-import.c
src/doveadm/doveadm-mail-iter.c
src/doveadm/doveadm-mail-mailbox.c
src/doveadm/doveadm-mail.c
src/dsync/dsync-worker-local.c
src/imap/cmd-fetch.c
src/imap/imap-commands-util.c
src/imap/imap-status.c
src/lda/main.c
src/lib-lda/mail-deliver.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h
src/lmtp/commands.c
src/plugins/autocreate/autocreate-plugin.c
src/plugins/lazy-expunge/lazy-expunge-plugin.c
src/plugins/quota/quota-count.c
src/plugins/snarf/snarf-plugin.c
src/plugins/virtual/virtual-storage.c
src/pop3/pop3-client.c

index fd8fe171a2e1de6b7f9a544514aa3172feae5fc5..c8d796f177f368de70a0fec793b9703ffdb13028 100644 (file)
@@ -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));
                }
        }
 }
index 3f11b0cee028fd1567469559a52d562aa4055bb5..3994279251fc2d74ffd8493fa5963dd64ab180f8 100644 (file)
@@ -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;
index 26ba2fcdac9e124256862fc2ffbe06056d63665b..89e08c5ad4cad259bbec7bdb6c9f6549144deffb 100644 (file)
@@ -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);
index 5e7f8a43be5c8bb55f80d8e9ed6645cac0e78e88..b0c4fc679ec6ca2e73af3071f9158deea271d77c 100644 (file)
@@ -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) {
index 53a6d442b713e26635989d828798e719458a50d9..721cc6b0a3062f8cdde064aaa9dd7d6503d9021f 100644 (file)
@@ -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);
index a434156e48dce3f84926099028d6327ee66097b4..52ee4e6196ee34649c3137e8deb3e29164ebb78a 100644 (file)
@@ -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);
index ded2533e3f29f9c19819e14f1ea4e286135b4991..2e9efd5f0a0b98f2956d59b4559fb32a892abab4 100644 (file)
@@ -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;
        }
 
index fd148e937e1247698c447af633f95838f2e56c0d..0c2281696b722bbef49b15a23db4dbda47cc95e6 100644 (file)
@@ -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;
index 6f30372e7014eada120b7bb0b249cc7104b6975e..f0db5f38592d58ad88c8cfd8bc8678a0793a3279 100644 (file)
@@ -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)
index 66cd33a6a9de0baa88416c114e6621105e7f70de..a3754d23bb38a2be7787e05d1e3fc1d4975f5139 100644 (file)
@@ -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 ?
index 5b71477f3f75890ac2a88c66b6d98c1172b91c38..ed3d398adedfbf668deea67746816204294de25b 100644 (file)
@@ -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;
index 68c2efe0e3a571c0c2c57a7ff3045fc9200405f1..2ea487d43f9baa812705b0820e3a4b97554963b0 100644 (file)
@@ -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. */
index 688766e49b9c211817069ec5e89326a083f7f138..670b9e9a6edb035bfe2217d9d56a8b36ea0fb510 100644 (file)
@@ -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
index 37bffd0ada2d7e56607009624a75a1a366eff75b..ed96649370e76e4c43b6a5b242f90c81a42026b0 100644 (file)
@@ -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);
index 87036f709faa0a47c786175201c368b94a107520..9b9e0db225d6e581b6959435d45ec028e2b11b9c 100644 (file)
@@ -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;
index 211abbf90069b7e320e8574c060f5ca155fc0bd6..5f2ce1b7628159648b4630488215cdfab1563716 100644 (file)
@@ -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;
index 17de7a0ce475ad2a408c65eae80dd1276ace69ab..9ab143d6b13f9efd3ea199b2fbeac77df953e379 100644 (file)
@@ -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);
index e6069d9aceb218b59db7d5da1f08f904217f7976..9e35d8bf28b2a7f3cef5833bbec8aa2275fdd9ff 100644 (file)
@@ -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);
index 6a11e3ccc24de39ce3194a979b3261cdc39d109b..aca2b406afa7f9f848ab89d956cfa4db69dc25f8 100644 (file)
@@ -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;
index 0210cedcdcf301c9b6c8646af9023ac9e8734aa3..e576cfcec35d5bda388ba8b91aa482e53be613c7 100644 (file)
@@ -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)
index 32835d64a77b7f2666a9a3089487e6c150bb76e6..3dab618094f6544abd4db23c248f6082332a44b3 100644 (file)
@@ -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) {
index 11b703fbf3bdb254e370c726e78190e29555eb02..09a6c7ffdac3d8f25be59e25911af061e6fd9a40 100644 (file)
@@ -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)