doveadm-mail.c revision da7c6d7313c044b60a415061f2d1787889724336
/* Copyright (c) 2009-2016 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 "client-connection.h"
#include "doveadm.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 };
char doveadm_mail_cmd_hide = '\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)
{
int exit_code = 0;
switch (error) {
case MAIL_ERROR_NONE:
i_unreached();
case MAIL_ERROR_TEMP:
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;
}
/* tempfail overrides all other exit codes, otherwise use whatever
error happened first */
}
struct mail_storage *storage)
{
enum mail_error error;
}
{
}
struct mailbox_list *list)
{
enum mail_error error;
}
struct doveadm_mail_cmd_context *
{
struct doveadm_mail_cmd_context *ctx;
return ctx;
}
static int
{
struct mail_namespace *ns;
struct mail_storage *storage;
int ret = 0;
continue;
if (mail_storage_purge(storage) < 0) {
ret = -1;
}
}
return ret;
}
static struct doveadm_mail_cmd_context *cmd_purge_alloc(void)
{
struct doveadm_mail_cmd_context *ctx;
return ctx;
}
{
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;
else {
}
i_stream_unref(&inputs[0]);
}
struct mailbox *
{
struct mail_namespace *ns;
if (!uni_utf8_str_is_valid(mailbox)) {
"Mailbox name not valid UTF-8: %s", mailbox);
}
}
struct mail_search_args *
doveadm_mail_build_search_args(const char *const args[])
{
struct mail_search_parser *parser;
struct mail_search_args *sargs;
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;
}
{
const enum mailbox_list_iter_flags iter_flags =
struct mailbox_list_iterate_context *iter;
const struct mailbox_info *info;
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");
}
static struct doveadm_mail_cmd_context *cmd_force_resync_alloc(void)
{
struct doveadm_mail_cmd_context *ctx;
return ctx;
}
static void
struct mail_storage_service_input *input_r)
{
}
static int
const struct doveadm_cmd_attributes *attrs,
const char **error_r)
{
struct mail_storage_service_input input;
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;
}
}
&ctx->cur_mail_user);
if (ret < 0) {
*error_r = "User init failed";
return ret;
}
}
return 1;
}
{
}
const struct doveadm_cmd_attributes *attrs,
const char **error_r)
{
ctx->service_flags);
if (hook_doveadm_mail_init != NULL)
}
static void
const char *wildcard_user)
{
struct doveadm_cmd_attributes attrs;
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)
{
struct doveadm_mail_cmd_context *ctx;
return ctx;
}
static struct doveadm_mail_cmd_context *
{
struct doveadm_mail_cmd_context *ctx;
if (doveadm_debug)
return ctx;
}
static void
const char *wildcard_user)
{
int ret;
const char *error;
}
if (ctx->iterate_single_user) {
struct doveadm_cmd_attributes attrs;
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
{
struct doveadm_mail_cmd_context *ctx;
const char *getopt_args, *wildcard_user;
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)
{
unsigned int len;
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 struct doveadm_mail_cmd *cmd;
unsigned int cmd_name_len;
const char *const *orig_argv;
int orig_argc;
return cmd;
/* see if it matches a multi-word command */
return cmd;
}
}
return NULL;
}
{
const struct doveadm_mail_cmd *cmd;
return FALSE;
return TRUE;
}
{
/* for now we'll just assume that cmd will be permanently in memory */
}
{
const struct doveadm_mail_cmd *cmd;
return cmd;
}
return NULL;
}
{
const struct doveadm_mail_cmd *cmd;
continue;
}
}
{
}
void doveadm_mail_try_help_name(const char *cmd_name)
{
const struct doveadm_cmd_ver2 *cmd2;
const struct doveadm_mail_cmd *cmd;
}
bool doveadm_mail_has_subcommands(const char *cmd_name)
{
const struct doveadm_mail_cmd *cmd;
return TRUE;
}
return FALSE;
}
void doveadm_mail_help_name(const char *cmd_name)
{
}
static struct doveadm_cmd_ver2 doveadm_cmd_force_resync_ver2 = {
.name = "force-resync",
};
static struct doveadm_cmd_ver2 doveadm_cmd_purge_ver2 = {
.name = "purge",
};
static struct doveadm_mail_cmd *mail_commands[] = {
};
static struct doveadm_cmd_ver2 *mail_commands_ver2[] = {
};
void doveadm_mail_init(void)
{
struct module_dir_load_settings mod_set;
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);
}
void doveadm_mail_deinit(void)
{
}
void
{
struct doveadm_mail_cmd_context *ctx;
const char *wildcard_user;
const char *fieldstr;
int i;
struct doveadm_mail_cmd mail_cmd = {
};
for(i=0;i<argc;i++) {
continue;
if (doveadm_settings->doveadm_worker_count == 0)
}
wildcard_user = "*";
/* 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 */
/* feed this into pargv */
} else {
return;
}
}
}