doveadm-mail-expunge.c revision 6971937a6f3e93844dbd43bdbe903628e21a9422
/* Copyright (c) 2010-2015 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "mail-index.h"
#include "mail-storage.h"
#include "mail-search.h"
#include "doveadm-mailbox-list-iter.h"
#include "doveadm-mail-iter.h"
#include "doveadm-mail.h"
struct expunge_cmd_context {
struct doveadm_mail_cmd_context ctx;
bool delete_empty_mailbox;
};
static int
const struct mailbox_info *info,
struct mail_search_args *search_args)
{
struct doveadm_mail_iter *iter;
enum mail_error error;
int ret = 0;
&iter) < 0)
return -1;
if (doveadm_debug) {
i_debug("expunge: box=%s uid=%u",
}
}
ret = -1;
else if (mailbox_sync(box, 0) < 0) {
i_error("Syncing mailbox '%s' failed: %s",
ret = -1;
}
if (mailbox_delete_empty(box) < 0) {
if (error != MAIL_ERROR_EXISTS) {
i_error("Deleting mailbox '%s' failed: %s",
ret = -1;
}
} else {
i_error("Unsubscribing mailbox '%s' failed: %s",
ret = -1;
}
}
}
mailbox_free(&box);
return ret;
}
static bool
static bool
{
struct mail_search_arg *arg;
case SEARCH_OR:
return FALSE;
break;
case SEARCH_SUB:
case SEARCH_INTHREAD:
return FALSE;
break;
case SEARCH_MAILBOX:
case SEARCH_MAILBOX_GUID:
case SEARCH_MAILBOX_GLOB:
break;
default:
return FALSE;
}
}
return TRUE;
}
static bool
{
struct mail_search_arg *arg;
/* a) we find one mailbox here in the SUB block */
case SEARCH_MAILBOX:
case SEARCH_MAILBOX_GUID:
case SEARCH_MAILBOX_GLOB:
return TRUE;
case SEARCH_OR:
break;
case SEARCH_SUB:
case SEARCH_INTHREAD:
return TRUE;
break;
default:
break;
}
}
/* b) there is at least one OR block, and all of the ORs must have
mailbox */
if (!have_or)
return FALSE;
return FALSE;
}
return TRUE;
}
static bool
static bool
{
struct mail_search_arg *arg;
/* we're done if all OR branches contain something else besides
MAILBOXes */
case SEARCH_MAILBOX:
case SEARCH_MAILBOX_GUID:
case SEARCH_MAILBOX_GLOB:
return FALSE;
case SEARCH_OR:
return FALSE;
break;
case SEARCH_SUB:
return FALSE;
break;
default:
break;
}
}
return TRUE;
}
static bool
{
struct mail_search_arg *arg;
/* all args can't be just MAILBOXes */
case SEARCH_MAILBOX:
case SEARCH_MAILBOX_GUID:
case SEARCH_MAILBOX_GLOB:
break;
case SEARCH_OR:
/* if each OR branch has something else than just
MAILBOXes, we're ok */
return TRUE;
break;
case SEARCH_SUB:
return TRUE;
break;
default:
return TRUE;
}
}
return FALSE;
}
static int
{
const enum mailbox_list_iter_flags iter_flags =
struct doveadm_mailbox_list_iter *iter;
const struct mailbox_info *info;
int ret = 0;
ret = -1;
} T_END;
if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
ret = -1;
return ret;
}
{
"%s: To avoid accidents, search query "
"must contain MAILBOX in all search branches", cmd);
}
"%s: To avoid accidents, each branch in search query "
"must contain something else besides MAILBOX "
"(e.g. just add \"all\" if you want everything)", cmd);
}
}
const char *const args[])
{
doveadm_mail_help_name("expunge");
}
{
switch (c) {
case 'd':
break;
default:
return FALSE;
}
return TRUE;
}
static struct doveadm_mail_cmd_context *cmd_expunge_alloc(void)
{
struct expunge_cmd_context *ctx;
}
struct doveadm_mail_cmd cmd_expunge = {
};