1
/* Copyright (c) 2011-2012 Dovecot authors, see the included COPYING file */
4
#include "mail-namespace.h"
5
#include "fts-storage.h"
6
#include "doveadm-mail.h"
7
#include "doveadm-fts.h"
9
const char *doveadm_fts_plugin_version = DOVECOT_VERSION;
12
fts_namespace_find(struct mail_user *user, const char *ns_prefix,
13
struct mail_namespace **ns_r)
15
struct mail_namespace *ns;
17
if (ns_prefix == NULL)
18
ns = mail_namespace_find_inbox(user->namespaces);
20
ns = mail_namespace_find_prefix(user->namespaces, ns_prefix);
22
i_error("Namespace prefix not found: %s", ns_prefix);
27
if (fts_list_backend(ns->list) == NULL) {
28
i_error("fts not enabled for user's namespace %s", ns_prefix);
36
cmd_fts_optimize_run(struct doveadm_mail_cmd_context *ctx,
37
struct mail_user *user)
39
const char *ns_prefix = ctx->args[0];
40
struct mail_namespace *ns;
41
struct fts_backend *backend;
43
if (fts_namespace_find(user, ns_prefix, &ns) < 0) {
44
doveadm_mail_failed_error(ctx, MAIL_ERROR_NOTFOUND);
47
backend = fts_list_backend(ns->list);
48
if (fts_backend_optimize(backend) < 0) {
49
i_error("fts optimize failed");
50
doveadm_mail_failed_error(ctx, MAIL_ERROR_TEMP);
57
cmd_fts_optimize_init(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED,
58
const char *const args[])
60
if (str_array_length(args) > 1)
61
doveadm_mail_help_name("fts optimize");
64
static struct doveadm_mail_cmd_context *
65
cmd_fts_optimize_alloc(void)
67
struct doveadm_mail_cmd_context *ctx;
69
ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
70
ctx->v.run = cmd_fts_optimize_run;
71
ctx->v.init = cmd_fts_optimize_init;
76
cmd_fts_rescan_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
78
const char *ns_prefix = ctx->args[0];
79
struct mail_namespace *ns;
80
struct fts_backend *backend;
82
if (fts_namespace_find(user, ns_prefix, &ns) < 0) {
83
doveadm_mail_failed_error(ctx, MAIL_ERROR_NOTFOUND);
86
backend = fts_list_backend(ns->list);
87
if (fts_backend_rescan(backend) < 0) {
88
i_error("fts rescan failed");
89
doveadm_mail_failed_error(ctx, MAIL_ERROR_TEMP);
96
cmd_fts_rescan_init(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED,
97
const char *const args[])
99
if (str_array_length(args) > 1)
100
doveadm_mail_help_name("fts rescan");
103
static struct doveadm_mail_cmd_context *
104
cmd_fts_rescan_alloc(void)
106
struct doveadm_mail_cmd_context *ctx;
108
ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
109
ctx->v.run = cmd_fts_rescan_run;
110
ctx->v.init = cmd_fts_rescan_init;
114
static struct doveadm_mail_cmd fts_commands[] = {
115
{ cmd_fts_optimize_alloc, "fts optimize", "[<namespace>]" },
116
{ cmd_fts_rescan_alloc, "fts rescan", "[<namespace>]" }
119
void doveadm_fts_plugin_init(struct module *module ATTR_UNUSED)
123
for (i = 0; i < N_ELEMENTS(fts_commands); i++)
124
doveadm_mail_register_cmd(&fts_commands[i]);
125
doveadm_dump_fts_expunge_log_init();
128
void doveadm_fts_plugin_deinit(void)