doveadm-mail-altmove.c revision c57ba1788a6598993a9625bbf26a4fedca23815e
89a126810703c666309310d0f3189e9834d70b5bTimo Sirainen/* Copyright (c) 2010-2013 Dovecot authors, see the included COPYING file */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainencmd_altmove_box(struct doveadm_mail_cmd_context *ctx,
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen struct mail_search_args *search_args, bool reverse)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen if (doveadm_mail_iter_init(ctx, info, search_args, 0, NULL,
6a9f9a5101b665fd2ef80c9e048a5eace78e01efTimo Sirainen (enum mail_flags)MAIL_INDEX_MAIL_FLAG_BACKEND);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainenns_purge(struct doveadm_mail_cmd_context *ctx, struct mail_namespace *ns)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen i_error("Purging namespace '%s' failed: %s", ns->prefix,
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen mail_storage_get_last_error(ns->storage, NULL));
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen doveadm_mail_failed_storage(ctx, ns->storage);
4b058f90f9e8a2c6b2eed275de4eb8cc5195a71dTimo Sirainencmd_altmove_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen struct altmove_cmd_context *ctx = (struct altmove_cmd_context *)_ctx;
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen const enum mailbox_list_iter_flags iter_flags =
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen unsigned int i, count;
1f57716285d4c5bc9bf2fd5569e3c85fd496afd9Timo Sirainen iter = doveadm_mailbox_list_iter_init(_ctx, user, _ctx->search_args,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) T_BEGIN {
a3ea111cfdbfd4f32baeb0bd7f1d72568c60a023Timo Sirainen if (cmd_altmove_box(_ctx, info, _ctx->search_args, ctx->reverse) < 0)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen array_append(&purged_storages, &prev_ns->storage, 1);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen /* make sure all private storages have been purged */
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen storages = array_get(&purged_storages, &count);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen for (ns = user->namespaces; ns != NULL; ns = ns->next) {
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen for (i = 0; i < count; i++) {
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen array_append(&purged_storages, &ns->storage, 1);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen storages = array_get(&purged_storages, &count);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainenstatic void cmd_altmove_init(struct doveadm_mail_cmd_context *ctx,
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen const char *const args[])
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen ctx->search_args = doveadm_mail_build_search_args(args);
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainencmd_mailbox_altmove_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen struct altmove_cmd_context *ctx = (struct altmove_cmd_context *)_ctx;
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainenstatic struct doveadm_mail_cmd_context *cmd_altmove_alloc(void)
b09be485e9373be4288f5615bbce6ebed65a425aTimo Sirainen ctx = doveadm_mail_cmd_alloc(struct altmove_cmd_context);
33ca6b017b6ebbd048651b5e3d16915001dbc291Timo Sirainen ctx->ctx.v.parse_arg = cmd_mailbox_altmove_parse_arg;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen cmd_altmove_alloc, "altmove", "[-r] <search query>"