]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: Added "doveadm fts optimize" command.
authorTimo Sirainen <tss@iki.fi>
Thu, 11 Aug 2011 15:10:33 +0000 (18:10 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 11 Aug 2011 15:10:33 +0000 (18:10 +0300)
src/plugins/fts/Makefile.am
src/plugins/fts/doveadm-fts.c [new file with mode: 0644]
src/plugins/fts/fts-storage.c
src/plugins/fts/fts-storage.h

index 79612a572914df3e7a04581219f705197439d0e9..fa84dc1480b654bfce7b103299cba5f850988439 100644 (file)
@@ -1,13 +1,16 @@
 pkglibexecdir = $(libexecdir)/dovecot
+doveadm_moduledir = $(moduledir)/doveadm
 
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib \
        -I$(top_srcdir)/src/lib-mail \
        -I$(top_srcdir)/src/lib-index \
        -I$(top_srcdir)/src/lib-storage \
-       -I$(top_srcdir)/src/lib-storage/index
+       -I$(top_srcdir)/src/lib-storage/index \
+       -I$(top_srcdir)/src/doveadm
 
 NOPLUGIN_LDFLAGS =
+lib20_doveadm_fts_plugin_la_LDFLAGS = -module -avoid-version
 lib20_fts_plugin_la_LDFLAGS = -module -avoid-version
 
 module_LTLIBRARIES = \
@@ -47,3 +50,9 @@ xml2text_DEPENDENCIES = fts-parser-html.lo $(LIBDOVECOT_DEPS)
 
 pkglibexec_SCRIPTS = decode2text.sh
 EXTRA_DIST = $(pkglibexec_SCRIPTS)
+
+doveadm_module_LTLIBRARIES = \
+       lib20_doveadm_fts_plugin.la
+
+lib20_doveadm_fts_plugin_la_SOURCES = \
+       doveadm-fts.c
diff --git a/src/plugins/fts/doveadm-fts.c b/src/plugins/fts/doveadm-fts.c
new file mode 100644 (file)
index 0000000..f8ad8e0
--- /dev/null
@@ -0,0 +1,90 @@
+/* Copyright (c) 2011 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "mail-namespace.h"
+#include "fts-storage.h"
+#include "doveadm-mail.h"
+
+struct doveadm_fts_cmd_context {
+       struct doveadm_mail_cmd_context ctx;
+       bool get_match_me;
+};
+
+const char *doveadm_fts_plugin_version = DOVECOT_VERSION;
+
+void doveadm_fts_plugin_init(struct module *module);
+void doveadm_fts_plugin_deinit(void);
+
+static int
+fts_namespace_find(struct mail_user *user, const char *ns_prefix,
+                  struct mail_namespace **ns_r)
+{
+       struct mail_namespace *ns;
+
+       if (ns_prefix == NULL)
+               ns = mail_namespace_find_inbox(user->namespaces);
+       else {
+               ns = mail_namespace_find_prefix(user->namespaces, ns_prefix);
+               if (ns == NULL) {
+                       i_error("Namespace prefix not found: %s", ns_prefix);
+                       return -1;
+               }
+       }
+
+       if (fts_list_backend(ns->list) == NULL) {
+               i_error("fts not enabled for user's namespace %s", ns_prefix);
+               return -1;
+       }
+       *ns_r = ns;
+       return 0;
+}
+
+static void
+cmd_fts_optimize_run(struct doveadm_mail_cmd_context *ctx,
+                    struct mail_user *user)
+{
+       const char *ns_prefix = ctx->args[0];
+       struct mail_namespace *ns;
+       struct fts_backend *backend;
+
+       if (fts_namespace_find(user, ns_prefix, &ns) < 0)
+               return;
+       backend = fts_list_backend(ns->list);
+       if (fts_backend_optimize(backend) < 0)
+               i_error("fts optimize failed");
+}
+
+static void
+cmd_fts_optimize_init(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED,
+                     const char *const args[])
+{
+       if (str_array_length(args) > 1)
+               doveadm_mail_help_name("fts optimize");
+}
+
+static struct doveadm_mail_cmd_context *
+cmd_fts_optimize_alloc(void)
+{
+       struct doveadm_mail_cmd_context *ctx;
+
+       ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
+       ctx->v.run = cmd_fts_optimize_run;
+       ctx->v.init = cmd_fts_optimize_init;
+       return ctx;
+}
+
+static struct doveadm_mail_cmd fts_commands[] = {
+       { cmd_fts_optimize_alloc, "fts optimize", "[<namespace>]" }
+};
+
+void doveadm_fts_plugin_init(struct module *module ATTR_UNUSED)
+{
+       unsigned int i;
+
+       for (i = 0; i < N_ELEMENTS(fts_commands); i++)
+               doveadm_mail_register_cmd(&fts_commands[i]);
+}
+
+void doveadm_fts_plugin_deinit(void)
+{
+}
index ee679c88f03bd10993dc34db296d682fe71e4382..1aca3678e0947986635f424c788f598546d0c03b 100644 (file)
@@ -528,3 +528,10 @@ struct fts_backend *fts_mailbox_backend(struct mailbox *box)
 
        return flist->backend;
 }
+
+struct fts_backend *fts_list_backend(struct mailbox_list *list)
+{
+       struct fts_mailbox_list *flist = FTS_LIST_CONTEXT(list);
+
+       return flist == NULL ? NULL : flist->backend;
+}
index a244a93f17bb2ab5132f41482972d19ddeca4dc6..98f8cf365f2a5d23edd7102ec73d7ce8923dbd47 100644 (file)
@@ -44,8 +44,10 @@ struct fts_search_context {
 void fts_search_analyze(struct fts_search_context *fctx);
 /* Perform the actual index lookup and update definite_uids and maybe_uids. */
 void fts_search_lookup(struct fts_search_context *fctx);
-/* Returns FTS backend for the given mailbox. */
+/* Returns FTS backend for the given mailbox (assumes it has one). */
 struct fts_backend *fts_mailbox_backend(struct mailbox *box);
+/* Returns FTS backend for the given mailbox list, or NULL if it has none. */
+struct fts_backend *fts_list_backend(struct mailbox_list *list);
 
 void fts_mail_allocated(struct mail *mail);
 void fts_mailbox_allocated(struct mailbox *box);