doveadm-mail.c revision ad58b50aef8125981ebdbc89513236558bcccf60
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
4e8e7a93628b4ed60aaaa47c6f72c1433f21e81dTimo SirainenARRAY_TYPE(doveadm_mail_cmd) doveadm_mail_cmds;
2d6c6f1d06d6d2e7b2ab0d46f7decdcf1cc80cd6Timo Sirainenvoid (*hook_doveadm_mail_init)(struct doveadm_mail_cmd_context *ctx);
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen i_assert(size >= sizeof(struct doveadm_mail_cmd_context));
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen pool = pool_alloconly_create("doveadm mail cmd", 1024);
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainencmd_purge_run(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED,
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen for (ns = user->namespaces; ns != NULL; ns = ns->next) {
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen if (ns->type != NAMESPACE_PRIVATE || ns->alias_for != NULL)
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen i_error("Purging namespace '%s' failed: %s", ns->prefix,
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen mail_storage_get_last_error(ns->storage, NULL));
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainenstatic struct doveadm_mail_cmd_context *cmd_purge_alloc(void)
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainendoveadm_mailbox_find(struct mail_user *user, const char *mailbox)
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainen i_fatal("Mailbox name not valid UTF-8: %s", mailbox);
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainen ns = mail_namespace_find(user->namespaces, mailbox);
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainen i_fatal("Can't find namespace for mailbox %s", mailbox);
86bdb644d147a73df85abce4325254d694217a5fTimo Sirainen return mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_IGNORE_ACLS);
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainendoveadm_mailbox_find_and_open(struct mail_user *user, const char *mailbox,
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen i_error("Opening mailbox %s failed: %s", mailbox,
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainenint doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox,
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen if (doveadm_mailbox_find_and_open(user, mailbox, box_r) < 0)
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen if (mailbox_sync(*box_r, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen i_error("Syncing mailbox %s failed: %s", mailbox,
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainendoveadm_mail_build_search_args(const char *const args[])
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainen parser = mail_search_parser_init_cmdline(args);
791fb70b3255a11a91ce0c2dc3ae1460d4cf8459Timo Sirainen if (mail_search_build(mail_search_register_get_human(),
7877db7b5daad125b6cb3e015574f33871c9a51bTimo Sirainenstatic void cmd_force_resync_run(struct doveadm_mail_cmd_context *_ctx,
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen if (doveadm_mailbox_find_and_open(user, ctx->mailbox, &box) < 0) {
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC |
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen i_error("Forcing a resync on mailbox %s failed: %s",
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen ctx->mailbox, mailbox_get_last_error(box, NULL));
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainenstatic void cmd_force_resync_init(struct doveadm_mail_cmd_context *_ctx,
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainen const char *const args[])
10972f2a15f5538860fcc1d4adda227d59d2d757Timo Sirainen ctx->mailbox = p_strdup(ctx->ctx.pool, mailbox);
ae9691f7ef36d5272d72c90fa51393dfea5dd126Timo Sirainenstatic struct doveadm_mail_cmd_context *cmd_force_resync_alloc(void)
10972f2a15f5538860fcc1d4adda227d59d2d757Timo Sirainen ctx = doveadm_mail_cmd_alloc(struct force_resync_cmd_context);
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)