doveadm-mail-expunge.c revision bcb4e51a409d94ae670de96afb8483a4f7855294
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "lib.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "array.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "mail-index.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "mail-storage.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "mail-search.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "doveadm-mailbox-list-iter.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "doveadm-mail-iter.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#include "doveadm-mail.h"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstruct expunge_cmd_context {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct doveadm_mail_cmd_context ctx;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync bool delete_empty_mailbox;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync};
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic int
f78b12e570284aa8291f4ca1add24937fd107403vboxsynccmd_expunge_box(struct doveadm_mail_cmd_context *_ctx,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync const struct mailbox_info *info,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct mail_search_args *search_args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct expunge_cmd_context *ctx = (struct expunge_cmd_context *)_ctx;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct doveadm_mail_iter *iter;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct mailbox *box;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct mail *mail;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync enum mail_error error;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int ret = 0;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (doveadm_mail_iter_init(_ctx, info, search_args, 0, NULL, FALSE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync &iter) < 0)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return -1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while (doveadm_mail_iter_next(iter, &mail)) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (doveadm_debug) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i_debug("expunge: box=%s uid=%u",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync info->vname, mail->uid);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mail_expunge(mail);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (doveadm_mail_iter_deinit_keep_box(&iter, &box) < 0)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ret = -1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync else if (mailbox_sync(box, 0) < 0) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i_error("Syncing mailbox '%s' failed: %s",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox_get_vname(box),
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox_get_last_internal_error(box, NULL));
f78b12e570284aa8291f4ca1add24937fd107403vboxsync doveadm_mail_failed_mailbox(_ctx, box);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ret = -1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (ctx->delete_empty_mailbox && ret == 0) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (mailbox_delete_empty(box) < 0) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync error = mailbox_get_last_mail_error(box);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (error != MAIL_ERROR_EXISTS) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i_error("Deleting mailbox '%s' failed: %s",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox_get_vname(box),
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox_get_last_internal_error(box, NULL));
f78b12e570284aa8291f4ca1add24937fd107403vboxsync doveadm_mail_failed_mailbox(_ctx, box);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ret = -1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync } else {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (mailbox_set_subscribed(box, FALSE) < 0) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i_error("Unsubscribing mailbox '%s' failed: %s",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox_get_vname(box),
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox_get_last_internal_error(box, NULL));
f78b12e570284aa8291f4ca1add24937fd107403vboxsync doveadm_mail_failed_mailbox(_ctx, box);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ret = -1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox_free(&box);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return ret;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_mailbox_ok(struct mail_search_arg *args);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_mailbox_or_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct mail_search_arg *arg;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync for (arg = args; arg != NULL; arg = arg->next) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync switch (arg->type) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_OR:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_mailbox_or_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_SUB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_INTHREAD:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_mailbox_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GUID:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GLOB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync default:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_mailbox_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct mail_search_arg *arg;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync bool have_or = FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* a) we find one mailbox here in the SUB block */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync for (arg = args; arg != NULL; arg = arg->next) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync switch (arg->type) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GUID:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GLOB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_OR:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync have_or = TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_SUB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_INTHREAD:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (expunge_search_args_is_mailbox_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync default:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* b) there is at least one OR block, and all of the ORs must have
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mailbox */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!have_or)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync for (arg = args; arg != NULL; arg = arg->next) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (arg->type == SEARCH_OR &&
f78b12e570284aa8291f4ca1add24937fd107403vboxsync !expunge_search_args_is_mailbox_or_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_msgset_ok(struct mail_search_arg *args);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_msgset_or_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct mail_search_arg *arg;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* we're done if all OR branches contain something else besides
f78b12e570284aa8291f4ca1add24937fd107403vboxsync MAILBOXes */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync for (arg = args; arg != NULL; arg = arg->next) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync switch (arg->type) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GUID:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GLOB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_OR:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_msgset_or_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_SUB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_msgset_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync default:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncexpunge_search_args_is_msgset_ok(struct mail_search_arg *args)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct mail_search_arg *arg;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* all args can't be just MAILBOXes */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync for (arg = args; arg != NULL; arg = arg->next) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync switch (arg->type) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GUID:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_MAILBOX_GLOB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_OR:
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 return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case SEARCH_SUB:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (expunge_search_args_is_msgset_ok(arg->value.subargs))
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync default:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic int
f78b12e570284aa8291f4ca1add24937fd107403vboxsynccmd_expunge_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync const enum mailbox_list_iter_flags iter_flags =
f78b12e570284aa8291f4ca1add24937fd107403vboxsync MAILBOX_LIST_ITER_NO_AUTO_BOXES |
f78b12e570284aa8291f4ca1add24937fd107403vboxsync MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct doveadm_mailbox_list_iter *iter;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync const struct mailbox_info *info;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync int ret = 0;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync iter = doveadm_mailbox_list_iter_init(ctx, user, ctx->search_args,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync iter_flags);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) T_BEGIN {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (cmd_expunge_box(ctx, info, ctx->search_args) < 0)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ret = -1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync } T_END;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ret = -1;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return ret;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncvoid expunge_search_args_check(struct mail_search_args *args, const char *cmd)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_mailbox_ok(args->args)) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i_fatal_status(EX_USAGE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "%s: To avoid accidents, search query "
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "must contain MAILBOX in all search branches", cmd);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (!expunge_search_args_is_msgset_ok(args->args)) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync i_fatal_status(EX_USAGE,
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);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync mail_search_args_simplify(args);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic void cmd_expunge_init(struct doveadm_mail_cmd_context *ctx,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync const char *const args[])
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (args[0] == NULL)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync doveadm_mail_help_name("expunge");
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx->search_args = doveadm_mail_build_search_args(args);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync expunge_search_args_check(ctx->search_args, "expunge");
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool cmd_expunge_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct expunge_cmd_context *ctx = (struct expunge_cmd_context *)_ctx;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync switch (c) {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync case 'd':
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx->delete_empty_mailbox = TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync break;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync default:
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return FALSE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return TRUE;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic struct doveadm_mail_cmd_context *cmd_expunge_alloc(void)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync{
f78b12e570284aa8291f4ca1add24937fd107403vboxsync struct expunge_cmd_context *ctx;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx = doveadm_mail_cmd_alloc(struct expunge_cmd_context);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx->ctx.getopt_args = "d";
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx->ctx.v.parse_arg = cmd_expunge_parse_arg;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx->ctx.v.init = cmd_expunge_init;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ctx->ctx.v.run = cmd_expunge_run;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync return &ctx->ctx;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync}
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstruct doveadm_cmd_ver2 doveadm_cmd_expunge_ver2 = {
f78b12e570284aa8291f4ca1add24937fd107403vboxsync .name = "expunge",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync .mail_cmd = cmd_expunge_alloc,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync .usage = DOVEADM_CMD_MAIL_USAGE_PREFIX "[-m] <search query>",
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncDOVEADM_CMD_PARAMS_START
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncDOVEADM_CMD_MAIL_COMMON
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncDOVEADM_CMD_PARAM('d', "delete-empty-mailbox", CMD_PARAM_BOOL, 0)
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncDOVEADM_CMD_PARAM('\0', "query", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncDOVEADM_CMD_PARAMS_END
f78b12e570284aa8291f4ca1add24937fd107403vboxsync};
f78b12e570284aa8291f4ca1add24937fd107403vboxsync