doveadm-mail.c revision e6825aad56997fb86f9ff5638639393aeb9eab59
b9f30617c2c96d54acbc4f85ed17b939c4f28916Timo Sirainen/* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo SirainenARRAY_TYPE(doveadm_mail_cmd) doveadm_mail_cmds;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenvoid (*hook_doveadm_mail_init)(struct doveadm_mail_cmd_context *ctx);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenvoid doveadm_mail_failed_error(struct doveadm_mail_cmd_context *ctx,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* tempfail overrides all other exit codes, otherwise use whatever
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen error happened first */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen if (ctx->exit_code == 0 || exit_code == EX_TEMPFAIL)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenvoid doveadm_mail_failed_storage(struct doveadm_mail_cmd_context *ctx,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen (void)mail_storage_get_last_error(storage, &error);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenvoid doveadm_mail_failed_mailbox(struct doveadm_mail_cmd_context *ctx,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen doveadm_mail_failed_storage(ctx, mailbox_get_storage(box));
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_assert(size >= sizeof(struct doveadm_mail_cmd_context));
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen pool = pool_alloconly_create("doveadm mail cmd", 1024);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainencmd_purge_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen for (ns = user->namespaces; ns != NULL; ns = ns->next) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (ns->type != NAMESPACE_PRIVATE || ns->alias_for != NULL)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_error("Purging namespace '%s' failed: %s", ns->prefix,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen mail_storage_get_last_error(ns->storage, NULL));
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainen doveadm_mail_failed_storage(ctx, ns->storage);
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainenstatic struct doveadm_mail_cmd_context *cmd_purge_alloc(void)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainendoveadm_mailbox_find(struct mail_user *user, const char *mailbox)
57d2429fae575e96ca276355af675deb66b76d00Timo Sirainen ns = mail_namespace_find(user->namespaces, mailbox);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen "Can't find namespace for mailbox %s", mailbox);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen return mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_IGNORE_ACLS);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainendoveadm_mailbox_find_and_open(struct mail_user *user, const char *mailbox,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_error("Opening mailbox %s failed: %s", mailbox,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenint doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (doveadm_mailbox_find_and_open(user, mailbox, box_r) < 0)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (mailbox_sync(*box_r, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_error("Syncing mailbox %s failed: %s", mailbox,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainendoveadm_mail_build_search_args(const char *const args[])
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen parser = mail_search_parser_init_cmdline(args);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (mail_search_build(mail_search_register_get_human(),
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstatic int cmd_force_resync_box(struct doveadm_mail_cmd_context *ctx,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen box = mailbox_alloc(info->ns->list, info->name,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen i_error("Opening mailbox %s failed: %s", info->name,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen } else if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC |
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen i_error("Forcing a resync on mailbox %s failed: %s",
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen info->name, mailbox_get_last_error(box, NULL));
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainenstatic int cmd_force_resync_run(struct doveadm_mail_cmd_context *ctx,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const enum mailbox_list_iter_flags iter_flags =
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen NAMESPACE_PRIVATE | NAMESPACE_SHARED | NAMESPACE_PUBLIC;
15f526e5ac611b4532568d131fcd0abf664abe41Timo Sirainen iter = mailbox_list_iter_init_namespaces(user->namespaces, ctx->args,
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen while ((info = mailbox_list_iter_next(iter)) != NULL) {
b215a8a123623782554a83f3025ef4e771bd8f01Timo Sirainencmd_force_resync_init(struct doveadm_mail_cmd_context *_ctx ATTR_UNUSED,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen const char *const args[])
return ctx;
const char **error_r)
const char *error;
int ret;
if (ret != 0)
return ret;
if (ret <= 0) {
if (ret < 0) {
error);
return ret;
if (ret < 0) {
return ret;
const char *error;
int ret;
if (ret < 0)
else if (ret == 0)
const char *wildcard_user)
int ret;
user_idx = 0;
T_BEGIN {
if (ret < 0)
else if (ret == 0)
} T_END;
if (doveadm_verbose) {
if (killed_signo != 0) {
if (doveadm_verbose)
if (ret < 0) {
const char **username_r)
struct doveadm_mail_cmd_context *
return ctx;
if (doveadm_debug)
unsigned int len;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
unsigned int cmd_name_len;
return TRUE;
return TRUE;
return FALSE;
return cmd;
return NULL;
return TRUE;
return FALSE;
&cmd_move,
void doveadm_mail_init(void)
&mod_set);
void doveadm_mail_deinit(void)