/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "lib-signals.h"
#include "ioloop.h"
#include "istream.h"
#include "istream-dot.h"
#include "istream-seekable.h"
#include "str.h"
#include "unichar.h"
#include "module-dir.h"
#include "wildcard-match.h"
#include "master-service.h"
#include "mail-user.h"
#include "mail-namespace.h"
#include "mail-storage.h"
#include "mail-storage-settings.h"
#include "mail-storage-service.h"
#include "mail-storage-hooks.h"
#include "mail-search-build.h"
#include "mail-search-parser.h"
#include "mailbox-list-iter.h"
#include "doveadm.h"
#include "client-connection.h"
#include "doveadm-settings.h"
#include "doveadm-print.h"
#include "doveadm-dsync.h"
#include "doveadm-mail.h"
#include <stdio.h>
doveadm_mail_cmd_module_register = { 0 };
static int killed_signo = 0;
bool doveadm_is_killed(void)
{
return killed_signo != 0;
}
int doveadm_killed_signo(void)
{
return killed_signo;
}
enum mail_error error)
{
switch (error) {
case MAIL_ERROR_NONE:
i_unreached();
case MAIL_ERROR_TEMP:
case MAIL_ERROR_UNAVAILABLE:
break;
case MAIL_ERROR_NOTPOSSIBLE:
case MAIL_ERROR_EXISTS:
case MAIL_ERROR_CONVERSION:
case MAIL_ERROR_INVALIDDATA:
break;
case MAIL_ERROR_PARAMS:
break;
case MAIL_ERROR_PERM:
break;
case MAIL_ERROR_NOQUOTA:
break;
case MAIL_ERROR_NOTFOUND:
break;
case MAIL_ERROR_EXPUNGED:
case MAIL_ERROR_INUSE:
break;
case MAIL_ERROR_LIMIT:
break;
break;
}
/* tempfail overrides all other exit codes, otherwise use whatever
error happened first */
}
struct mail_storage *storage)
{
}
{
}
struct mailbox_list *list)
{
}
struct doveadm_mail_cmd_context *
{
return ctx;
}
static int
{
int ret = 0;
continue;
if (mail_storage_purge(storage) < 0) {
ret = -1;
}
}
return ret;
}
{
return ctx;
}
{
const unsigned char *data;
return;
i_error("read(%s) failed: %s",
}
}
{
}
{
ioloop = io_loop_create();
/* read the pending input from stream. */
if (io_loop_is_running(ioloop))
timeout_remove(&to);
}
{
return;
ctx->cmd_input = i_stream_create_error_str(EINVAL, "Input stream missing (provide with file parameter)");
return;
}
if (!cli)
else {
}
i_stream_unref(&inputs[0]);
}
struct mailbox *
{
if (!uni_utf8_str_is_valid(mailbox)) {
"Mailbox name not valid UTF-8: %s", mailbox);
}
}
struct mail_search_args *
{
return sargs;
}
const struct mailbox_info *info)
{
int ret = 0;
if (mailbox_open(box) < 0) {
ret = -1;
i_error("Forcing a resync on mailbox %s failed: %s",
ret = -1;
}
mailbox_free(&box);
return ret;
}
struct mail_storage_service_user *service_user,
const char **error_r)
{
"mailbox_list_index_very_dirty_syncs",
"no",
error_r) <= 0)
i_unreached();
return 0;
}
{
int ret = 0;
MAILBOX_NONEXISTENT)) == 0) T_BEGIN {
ret = -1;
} T_END;
}
if (mailbox_list_iter_deinit(&iter) < 0) {
i_error("Listing mailboxes failed: %s",
ret = -1;
}
return ret;
}
static void
const char *const args[])
{
doveadm_mail_help_name("force-resync");
}
{
return ctx;
}
static void
struct mail_storage_service_input *input_r)
{
}
static int
const char **error_r)
{
int ret;
if (ip[0] == '\0')
else
/* see if we want to execute this command via (another)
doveadm server */
if (ret != 0)
return ret;
if (ret <= 0) {
if (ret < 0) {
error);
}
return ret;
}
return -1;
}
}
if (ret < 0) {
return ret;
}
}
return 1;
}
{
}
const char **error_r)
{
ctx->service_flags);
if (hook_doveadm_mail_init != NULL)
}
static void
const char *wildcard_user)
{
unsigned int user_idx;
int ret;
ctx->service_flags);
if (hook_doveadm_mail_init != NULL)
user_idx = 0;
if (wildcard_user != NULL) {
continue;
}
T_BEGIN {
if (ret < 0)
else if (ret == 0)
i_info("User no longer exists, skipping");
} T_END;
if (ret == -1)
break;
if (doveadm_verbose) {
if (++user_idx % 100 == 0) {
}
}
if (killed_signo != 0) {
ret = -1;
break;
}
}
if (doveadm_verbose)
printf("\n");
if (ip[0] == '\0')
i_set_failure_prefix("doveadm: ");
else
if (ret < 0) {
i_error("Failed to iterate through some users");
}
}
static void
const char *const args[] ATTR_UNUSED)
{
}
static int
const char **username_r)
{
i_error("read(%s) failed: %s",
return -1;
}
}
static void
{
}
struct doveadm_mail_cmd_context *
const struct doveadm_settings *set)
{
return ctx;
}
static struct doveadm_mail_cmd_context *
{
if (doveadm_debug)
return ctx;
}
static void
const char *wildcard_user)
{
int ret;
const char *error;
if (doveadm_print_is_initialized() &&
}
if (ctx->iterate_single_user) {
if (!cli) {
/* we may access multiple users */
}
if (ctx->add_username_header)
if (ret < 0) {
} else if (ret == 0) {
i_error("User doesn't exist");
}
} else {
}
/* service deinit unloads mail plugins, so do it late */
}
{
}
static void
{
int c;
getopt_args = "AF:S:u:";
/* keep context's getopt_args first in case it contains '+' */
switch (c) {
case 'A':
break;
case 'S':
if (doveadm_settings->doveadm_worker_count == 0)
break;
case 'u':
ctx->service_flags |=
}
break;
case 'F':
ctx->service_flags |=
wildcard_user = "*";
break;
default:
}
}
}
}
static bool
const char *const **argv)
{
if (*argc < 2)
return FALSE;
*argc -= 1;
*argv += 1;
return FALSE;
/* more args */
}
return FALSE;
/* match */
return TRUE;
}
const struct doveadm_mail_cmd *
const char *const **argv)
{
const char *const *orig_argv;
int orig_argc;
return cmd;
/* see if it matches a multi-word command */
return cmd;
}
}
return NULL;
}
{
return FALSE;
return TRUE;
}
{
/* for now we'll just assume that cmd will be permanently in memory */
}
{
return cmd;
}
return NULL;
}
{
continue;
}
}
{
}
{
}
{
return TRUE;
}
return FALSE;
}
{
}
.name = "force-resync",
};
.name = "purge",
};
};
};
void doveadm_mail_init(void)
{
unsigned int i;
for (i = 0; i < N_ELEMENTS(mail_commands); i++)
for (i = 0; i < N_ELEMENTS(mail_commands_ver2); i++)
/* load all configured mail plugins */
&mod_set);
/* keep mail_storage_init() referenced so that its _deinit() doesn't
try to free doveadm plugins' hooks too early. */
}
void doveadm_mail_deinit(void)
{
}
void
{
const char *wildcard_user;
const char *fieldstr;
int i;
};
if (!cli) {
/* doveadm-server always does userdb lookups */
} else {
}
continue;
if (tcp_server)
else
fieldstr = "-A";
if (doveadm_settings->doveadm_worker_count == 0)
if (!tcp_server)
fieldstr = "-u";
if (tcp_server)
else {
}
}
wildcard_user = "*";
fieldstr = "-F";
/* mailbox status, fetch, flags: convert an array into a
single space-separated parameter (alternative to
fieldstr) */
/* input for doveadm_mail_get_input(),
used by e.g. save */
return;
}
/* Keep all named special parameters above this line */
return;
}
/* feed this into pargv */
} else {
return;
}
}
/* All the -parameters need to be included in full_args so that
they're sent to doveadm-server. */
}