doveadm-mail-expunge.c revision bcb4e51a409d94ae670de96afb8483a4f7855294
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
f78b12e570284aa8291f4ca1add24937fd107403vboxsynccmd_expunge_box(struct doveadm_mail_cmd_context *_ctx,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct expunge_cmd_context *ctx = (struct expunge_cmd_context *)_ctx;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (doveadm_mail_iter_init(_ctx, info, search_args, 0, NULL, FALSE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (doveadm_mail_iter_deinit_keep_box(&iter, &box) < 0)
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_mailbox_ok(struct mail_search_arg *args);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_mailbox_or_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_mailbox_or_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_mailbox_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_mailbox_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* a) we find one mailbox here in the SUB block */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (expunge_search_args_is_mailbox_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* b) there is at least one OR block, and all of the ORs must have
f78b12e570284aa8291f4ca1add24937fd107403vboxsync !expunge_search_args_is_mailbox_or_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_msgset_ok(struct mail_search_arg *args);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_msgset_or_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* we're done if all OR branches contain something else besides
f78b12e570284aa8291f4ca1add24937fd107403vboxsync MAILBOXes */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_msgset_or_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_msgset_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_msgset_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* all args can't be just MAILBOXes */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* if each OR branch has something else than just
f78b12e570284aa8291f4ca1add24937fd107403vboxsync MAILBOXes, we're ok */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (expunge_search_args_is_msgset_or_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (expunge_search_args_is_msgset_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsynccmd_expunge_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync iter = doveadm_mailbox_list_iter_init(ctx, user, ctx->search_args,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) T_BEGIN {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (cmd_expunge_box(ctx, info, ctx->search_args) < 0)
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncvoid expunge_search_args_check(struct mail_search_args *args, const char *cmd)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_mailbox_ok(args->args)) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "%s: To avoid accidents, search query "
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "must contain MAILBOX in all search branches", cmd);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_msgset_ok(args->args)) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "%s: To avoid accidents, each branch in search query "
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "must contain something else besides MAILBOX "
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "(e.g. just add \"all\" if you want everything)", cmd);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic void cmd_expunge_init(struct doveadm_mail_cmd_context *ctx,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync const char *const args[])
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx->search_args = doveadm_mail_build_search_args(args);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync expunge_search_args_check(ctx->search_args, "expunge");
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool cmd_expunge_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct expunge_cmd_context *ctx = (struct expunge_cmd_context *)_ctx;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync switch (c) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic struct doveadm_mail_cmd_context *cmd_expunge_alloc(void)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx = doveadm_mail_cmd_alloc(struct expunge_cmd_context);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstruct doveadm_cmd_ver2 doveadm_cmd_expunge_ver2 = {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync .usage = DOVEADM_CMD_MAIL_USAGE_PREFIX "[-m] <search query>",
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncDOVEADM_CMD_PARAM('d', "delete-empty-mailbox", CMD_PARAM_BOOL, 0)