doveadm-mail.c revision 8b7feed47b94d484b3e7e0aef2b78ea09433aeaa
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2009-2014 Dovecot authors, see the included COPYING file */
d1414c09cf0d58ac983054e2f4e1a1f329272dcfTimo SirainenARRAY_TYPE(doveadm_mail_cmd) doveadm_mail_cmds;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenvoid (*hook_doveadm_mail_init)(struct doveadm_mail_cmd_context *ctx);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenvoid doveadm_mail_failed_error(struct doveadm_mail_cmd_context *ctx,
1ddec6312bc6882aeb17d4d46d19cbca1723b68bTimo Sirainen /* tempfail overrides all other exit codes, otherwise use whatever
1ddec6312bc6882aeb17d4d46d19cbca1723b68bTimo Sirainen error happened first */
15cb9549422ccee416b21d26fec97a556ad0fa36Florian Zeitz if (ctx->exit_code == 0 || exit_code == EX_TEMPFAIL)
0469ed17dafcc56589ce00960a23f4f06817dfb5Timo Sirainenvoid doveadm_mail_failed_storage(struct doveadm_mail_cmd_context *ctx,
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainenvoid doveadm_mail_failed_mailbox(struct doveadm_mail_cmd_context *ctx,
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen doveadm_mail_failed_storage(ctx, mailbox_get_storage(box));
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen i_assert(size >= sizeof(struct doveadm_mail_cmd_context));
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen pool = pool_alloconly_create("doveadm mail cmd", 1024);
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainencmd_purge_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen for (ns = user->namespaces; ns != NULL; ns = ns->next) {
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen if (ns->type != MAIL_NAMESPACE_TYPE_PRIVATE ||
0cc875d28852d15005cff2a77252e7836c862a01Timo Sirainen storage = mail_namespace_get_default_storage(ns);
0cc875d28852d15005cff2a77252e7836c862a01Timo Sirainen i_error("Purging namespace '%s' failed: %s", ns->prefix,
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainenstatic struct doveadm_mail_cmd_context *cmd_purge_alloc(void)
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainendoveadm_mailbox_find(struct mail_user *user, const char *mailbox)
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen ns = mail_namespace_find(user->namespaces, mailbox);
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen return mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_IGNORE_ACLS);
966cb0c1aa58578339cea6f79b4a423a851ab074Timo Sirainendoveadm_mailbox_find_and_open(struct mail_user *user, const char *mailbox,
966cb0c1aa58578339cea6f79b4a423a851ab074Timo Sirainen i_error("Opening mailbox %s failed: %s", mailbox,
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainenint doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox,
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen if (doveadm_mailbox_find_and_open(user, mailbox, box_r) < 0)
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen if (mailbox_sync(*box_r, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
21c317a20c4c3784b54fb3e90ee3751870afdcc3Timo Sirainen i_error("Syncing mailbox %s failed: %s", mailbox,
4ac2e38bdb450d13b62be41638b12df9e0658009Stephan Boschdoveadm_mail_build_search_args(const char *const args[])
97c339398f1aba6f315b55a9b6ee6b020e33bea4Timo Sirainen parser = mail_search_parser_init_cmdline(args);
97c339398f1aba6f315b55a9b6ee6b020e33bea4Timo Sirainen if (mail_search_build(mail_search_register_get_human(),
6e873f135368bcfdd1de4458dded791d0c4d00cdTimo Sirainenstatic int cmd_force_resync_box(struct doveadm_mail_cmd_context *ctx,
6e873f135368bcfdd1de4458dded791d0c4d00cdTimo Sirainen box = mailbox_alloc(info->ns->list, info->vname,
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen i_error("Opening mailbox %s failed: %s", info->vname,
0469ed17dafcc56589ce00960a23f4f06817dfb5Timo Sirainen } else if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC |
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen i_error("Forcing a resync on mailbox %s failed: %s",
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen info->vname, mailbox_get_last_error(box, NULL));
59beb411159176b39e48a52d60dd3239732e67b4Timo Sirainenstatic int cmd_force_resync_run(struct doveadm_mail_cmd_context *ctx,
6e873f135368bcfdd1de4458dded791d0c4d00cdTimo Sirainen const enum mailbox_list_iter_flags iter_flags =
6e873f135368bcfdd1de4458dded791d0c4d00cdTimo Sirainen const enum mail_namespace_type ns_mask = MAIL_NAMESPACE_TYPE_MASK_ALL;
81419a8dd69d8cef0e93d1e04bda77d135202452Timo Sirainen iter = mailbox_list_iter_init_namespaces(user->namespaces, ctx->args,
a4ac325c2802693c6b761e5a8fda961e5d7490eaTimo Sirainen while ((info = mailbox_list_iter_next(iter)) != NULL) {
return ret;
const char *const args[])
return ctx;
const char **error_r)
int ret;
if (ret != 0)
return ret;
if (init_user) {
if (ret <= 0) {
if (ret < 0) {
error);
return ret;
if (ret < 0) {
return ret;
const char **error_r)
const char *wildcard_user)
unsigned int user_idx;
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;
int ret, c;
if (doveadm_debug)
if (ret < 0)
else if (ret == 0)
const char *const **argv)
unsigned int len;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
const struct doveadm_mail_cmd *
const char *const **argv)
unsigned int cmd_name_len;
const char *const *orig_argv;
int orig_argc;
return cmd;
return cmd;
return NULL;
return FALSE;
return TRUE;
return cmd;
return NULL;
return TRUE;
return FALSE;
&cmd_copy,
&cmd_move,
void doveadm_mail_init(void)
&mod_set);
void doveadm_mail_deinit(void)