dovecot-2.2: fts: Added "doveadm fts expand" to show lib-fts sea...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 3 21:47:33 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/7cb0bc84914d
changeset: 18828:7cb0bc84914d
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 04 00:45:11 2015 +0300
description:
fts: Added "doveadm fts expand" to show lib-fts search query expanded.

diffstat:

 src/plugins/fts/doveadm-fts.c |  49 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r 53824319afb5 -r 7cb0bc84914d src/plugins/fts/doveadm-fts.c
--- a/src/plugins/fts/doveadm-fts.c	Thu Jun 04 00:44:42 2015 +0300
+++ b/src/plugins/fts/doveadm-fts.c	Thu Jun 04 00:45:11 2015 +0300
@@ -7,6 +7,7 @@
 #include "mail-search.h"
 #include "mailbox-list-iter.h"
 #include "fts-storage.h"
+#include "fts-search-args.h"
 #include "doveadm-mail.h"
 #include "doveadm-mailbox-list-iter.h"
 #include "doveadm-fts.h"
@@ -106,6 +107,53 @@
 }
 
 static int
+cmd_fts_expand_run(struct doveadm_mail_cmd_context *ctx,
+		   struct mail_user *user)
+{
+	struct mail_namespace *ns = mail_namespace_find_inbox(user->namespaces);
+	struct mailbox *box;
+	struct fts_backend *backend;
+	string_t *str = t_str_new(128);
+
+	backend = fts_list_backend(ns->list);
+	if (backend == NULL) {
+		i_error("fts not enabled for INBOX");
+		return -1;
+	}
+
+	box = mailbox_alloc(ns->list, "INBOX", 0);
+	mail_search_args_init(ctx->search_args, box, FALSE, NULL);
+
+	if (fts_search_args_expand(backend, ctx->search_args) < 0)
+		i_fatal("Couldn't expand search args");
+	mail_search_args_to_cmdline(str, ctx->search_args->args);
+	printf("%s\n", str_c(str));
+	mailbox_free(&box);
+	return 0;
+}
+
+static void
+cmd_fts_expand_init(struct doveadm_mail_cmd_context *ctx,
+		    const char *const args[])
+{
+	if (args[0] == NULL)
+		doveadm_mail_help_name("fts expand");
+
+	ctx->search_args = doveadm_mail_build_search_args(args);
+}
+
+static struct doveadm_mail_cmd_context *
+cmd_fts_expand_alloc(void)
+{
+	struct doveadm_mail_cmd_context *ctx;
+
+	ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
+	ctx->v.run = cmd_fts_expand_run;
+	ctx->v.init = cmd_fts_expand_init;
+	return ctx;
+}
+
+static int
 fts_namespace_find(struct mail_user *user, const char *ns_prefix,
 		   struct mail_namespace **ns_r)
 {
@@ -211,6 +259,7 @@
 
 static struct doveadm_mail_cmd fts_commands[] = {
 	{ cmd_fts_lookup_alloc, "fts lookup", "<search query>" },
+	{ cmd_fts_expand_alloc, "fts expand", "<search query>" },
 	{ cmd_fts_optimize_alloc, "fts optimize", "[<namespace>]" },
 	{ cmd_fts_rescan_alloc, "fts rescan", "[<namespace>]" }
 };


More information about the dovecot-cvs mailing list