struct mailbox_status status;
uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
- box = doveadm_mailbox_find_and_sync(ctx->ctx.cur_mail_user, info->name);
+ if (doveadm_mailbox_find_and_sync(ctx->ctx.cur_mail_user,
+ info->name, &box) < 0) {
+ ctx->ctx.failed = TRUE;
+ return;
+ }
mailbox_get_status(box, ctx->items, &status);
if (ctx->guid) {
if (mailbox_get_guid(box, mailbox_guid) < 0)
return ctx;
}
-static struct mailbox *
-mailbox_find_and_open(struct mail_user *user, const char *mailbox)
+static int mailbox_find_and_open(struct mail_user *user, const char *mailbox,
+ struct mailbox **box_r)
{
struct mail_namespace *ns;
struct mailbox *box;
box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_KEEP_RECENT |
MAILBOX_FLAG_IGNORE_ACLS);
if (mailbox_open(box) < 0) {
- i_fatal("Opening mailbox %s failed: %s", orig_mailbox,
+ i_error("Opening mailbox %s failed: %s", orig_mailbox,
mail_storage_get_last_error(mailbox_get_storage(box),
NULL));
+ mailbox_free(&box);
+ return -1;
}
- return box;
+ *box_r = box;
+ return 0;
}
-struct mailbox *
-doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox)
+int doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox,
+ struct mailbox **box_r)
{
- struct mailbox *box;
-
- box = mailbox_find_and_open(user, mailbox);
- if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
- i_fatal("Syncing mailbox %s failed: %s", mailbox,
- mail_storage_get_last_error(mailbox_get_storage(box),
+ if (mailbox_find_and_open(user, mailbox, box_r) < 0)
+ 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));
+ return -1;
}
- return box;
+ return 0;
}
struct mail_search_args *
struct mail_storage *storage;
struct mailbox *box;
- box = mailbox_find_and_open(user, ctx->mailbox);
+ if (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_fatal("Forcing a resync on mailbox %s failed: %s",
+ i_error("Forcing a resync on mailbox %s failed: %s",
ctx->mailbox,
mail_storage_get_last_error(storage, NULL));
+ _ctx->failed = TRUE;
}
mailbox_free(&box);
}
doveadm_mail_all_users(ctx, wildcard_user, service_flags);
}
ctx->v.deinit(ctx);
+
+ if (ctx->failed)
+ exit(FATAL_DEFAULT);
}
void dm_printf(struct doveadm_mail_cmd_context *ctx, const char *format, ...)
#include "doveadm.h"
#include "module-context.h"
+struct mailbox;
struct mail_user;
struct mail_storage_service_ctx;
struct mail_storage_service_input;
unsigned int iterate_all_users:1;
unsigned int dm_printf_last_lf:1;
+ unsigned int failed:1;
};
struct doveadm_mail_cmd {
void doveadm_mail_init(void);
void doveadm_mail_deinit(void);
-struct mailbox *
-doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox);
+int doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox,
+ struct mailbox **box_r);
struct mail_search_args *
doveadm_mail_build_search_args(const char *const args[]);
const char *const *doveadm_mailbox_args_to_mutf7(const char *const args[]);