dovecot-2.0: doveadm: Changed mail command API to be more easily...
dovecot at dovecot.org
dovecot at dovecot.org
Thu May 13 12:06:00 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/0c9db163d538
changeset: 11294:0c9db163d538
user: Timo Sirainen <tss at iki.fi>
date: Thu May 13 10:59:37 2010 +0200
description:
doveadm: Changed mail command API to be more easily extensible.
diffstat:
src/doveadm/doveadm-mail-altmove.c | 23 +++++--
src/doveadm/doveadm-mail-expunge.c | 20 +++++-
src/doveadm/doveadm-mail-fetch.c | 23 +++++--
src/doveadm/doveadm-mail-mailbox.c | 89 ++++++++++++++++++++++-------
src/doveadm/doveadm-mail-search.c | 20 +++++-
src/doveadm/doveadm-mail.c | 60 ++++++++++++-------
src/doveadm/doveadm-mail.h | 27 ++++----
7 files changed, 185 insertions(+), 77 deletions(-)
diffs (truncated from 484 to 300 lines):
diff -r 13af90173e4f -r 0c9db163d538 src/doveadm/doveadm-mail-altmove.c
--- a/src/doveadm/doveadm-mail-altmove.c Thu May 13 09:27:06 2010 +0200
+++ b/src/doveadm/doveadm-mail-altmove.c Thu May 13 10:59:37 2010 +0200
@@ -94,15 +94,26 @@
}
}
-struct doveadm_mail_cmd_context *cmd_altmove(const char *const args[])
+static void cmd_altmove_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
+{
+ struct altmove_cmd_context *ctx = (struct altmove_cmd_context *)_ctx;
+
+ if (args[0] == NULL)
+ doveadm_mail_help_name("altmove");
+ ctx->search_args = doveadm_mail_build_search_args(args);
+}
+
+static struct doveadm_mail_cmd_context *cmd_altmove_alloc(void)
{
struct altmove_cmd_context *ctx;
- if (args[0] == NULL)
- doveadm_mail_help_name("altmove");
-
- ctx = doveadm_mail_cmd_init(struct altmove_cmd_context);
+ ctx = doveadm_mail_cmd_alloc(struct altmove_cmd_context);
+ ctx->ctx.init = cmd_altmove_init;
ctx->ctx.run = cmd_altmove_run;
- ctx->search_args = doveadm_mail_build_search_args(args);
return &ctx->ctx;
}
+
+struct doveadm_mail_cmd cmd_altmove = {
+ cmd_altmove_alloc, "altmove", "<search query>"
+};
diff -r 13af90173e4f -r 0c9db163d538 src/doveadm/doveadm-mail-expunge.c
--- a/src/doveadm/doveadm-mail-expunge.c Thu May 13 09:27:06 2010 +0200
+++ b/src/doveadm/doveadm-mail-expunge.c Thu May 13 10:59:37 2010 +0200
@@ -195,16 +195,28 @@
doveadm_mail_list_iter_deinit(&iter);
}
-struct doveadm_mail_cmd_context *cmd_expunge(const char *const args[])
+static void cmd_expunge_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
{
- struct expunge_cmd_context *ctx;
+ struct expunge_cmd_context *ctx = (struct expunge_cmd_context *)_ctx;
if (args[0] == NULL)
doveadm_mail_help_name("expunge");
- ctx = doveadm_mail_cmd_init(struct expunge_cmd_context);
- ctx->ctx.run = cmd_expunge_run;
ctx->search_args = doveadm_mail_build_search_args(args);
mail_search_args_simplify(ctx->search_args);
+}
+
+static struct doveadm_mail_cmd_context *cmd_expunge_alloc(void)
+{
+ struct expunge_cmd_context *ctx;
+
+ ctx = doveadm_mail_cmd_alloc(struct expunge_cmd_context);
+ ctx->ctx.init = cmd_expunge_init;
+ ctx->ctx.run = cmd_expunge_run;
return &ctx->ctx;
}
+
+struct doveadm_mail_cmd cmd_expunge = {
+ cmd_expunge_alloc, "expunge", "<search query>"
+};
diff -r 13af90173e4f -r 0c9db163d538 src/doveadm/doveadm-mail-fetch.c
--- a/src/doveadm/doveadm-mail-fetch.c Thu May 13 09:27:06 2010 +0200
+++ b/src/doveadm/doveadm-mail-fetch.c Thu May 13 10:59:37 2010 +0200
@@ -383,19 +383,16 @@
str_free(&ctx->hdr);
}
-struct doveadm_mail_cmd_context *cmd_fetch(const char *const args[])
+static void cmd_fetch_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
{
+ struct fetch_cmd_context *ctx = (struct fetch_cmd_context *)_ctx;
const char *fetch_fields = args[0];
- struct fetch_cmd_context *ctx;
unsigned char prefix_buf[9];
if (fetch_fields == NULL || args[1] == NULL)
doveadm_mail_help_name("fetch");
- ctx = doveadm_mail_cmd_init(struct fetch_cmd_context);
- ctx->ctx.run = cmd_fetch_run;
- ctx->ctx.deinit = cmd_fetch_deinit;
-
parse_fetch_fields(ctx, fetch_fields);
ctx->search_args = doveadm_mail_build_search_args(args + 1);
@@ -411,5 +408,19 @@
ctx->prefix = t_strdup(str_c(ctx->hdr));
str_truncate(ctx->hdr, 0);
}
+}
+
+static struct doveadm_mail_cmd_context *cmd_fetch_alloc(void)
+{
+ struct fetch_cmd_context *ctx;
+
+ ctx = doveadm_mail_cmd_alloc(struct fetch_cmd_context);
+ ctx->ctx.init = cmd_fetch_init;
+ ctx->ctx.run = cmd_fetch_run;
+ ctx->ctx.deinit = cmd_fetch_deinit;
return &ctx->ctx;
}
+
+struct doveadm_mail_cmd cmd_fetch = {
+ cmd_fetch_alloc, "fetch", "<fields> <search query>"
+};
diff -r 13af90173e4f -r 0c9db163d538 src/doveadm/doveadm-mail-mailbox.c
--- a/src/doveadm/doveadm-mail-mailbox.c Thu May 13 09:27:06 2010 +0200
+++ b/src/doveadm/doveadm-mail-mailbox.c Thu May 13 10:59:37 2010 +0200
@@ -45,15 +45,13 @@
doveadm_mail_list_iter_deinit(&iter);
}
-struct doveadm_mail_cmd_context *cmd_mailbox_list(const char *const args[])
+static void cmd_mailbox_list_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
{
- struct list_cmd_context *ctx;
+ struct list_cmd_context *ctx = (struct list_cmd_context *)_ctx;
struct mail_search_arg *arg;
unsigned int i;
- ctx = doveadm_mail_cmd_init(struct list_cmd_context);
- ctx->ctx.run = cmd_mailbox_list_run;
-
ctx->search_args = mail_search_build_init();
for (i = 0; args[i] != NULL; i++) {
arg = mail_search_build_add(ctx->search_args,
@@ -67,6 +65,15 @@
arg = mail_search_build_add(ctx->search_args, SEARCH_OR);
arg->value.subargs = subargs;
}
+}
+
+static struct doveadm_mail_cmd_context *cmd_mailbox_list_alloc(void)
+{
+ struct list_cmd_context *ctx;
+
+ ctx = doveadm_mail_cmd_alloc(struct list_cmd_context);
+ ctx->ctx.init = cmd_mailbox_list_init;
+ ctx->ctx.run = cmd_mailbox_list_run;
return &ctx->ctx;
}
@@ -105,23 +112,30 @@
}
}
-struct doveadm_mail_cmd_context *cmd_mailbox_create(const char *const args[])
+static void cmd_mailbox_create_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
{
- struct mailbox_cmd_context *ctx;
+ struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
const char *name;
unsigned int i;
if (args[0] == NULL)
doveadm_mail_help_name("mailbox create");
- ctx = doveadm_mail_cmd_init(struct mailbox_cmd_context);
- ctx->ctx.run = cmd_mailbox_create_run;
- p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
-
for (i = 0; args[i] != NULL; i++) {
name = p_strdup(ctx->ctx.pool, args[i]);
array_append(&ctx->mailboxes, &name, 1);
}
+}
+
+static struct doveadm_mail_cmd_context *cmd_mailbox_create_alloc(void)
+{
+ struct mailbox_cmd_context *ctx;
+
+ ctx = doveadm_mail_cmd_alloc(struct mailbox_cmd_context);
+ ctx->ctx.init = cmd_mailbox_create_init;
+ ctx->ctx.run = cmd_mailbox_create_run;
+ p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
return &ctx->ctx;
}
@@ -152,23 +166,30 @@
}
}
-struct doveadm_mail_cmd_context *cmd_mailbox_delete(const char *const args[])
+static void cmd_mailbox_delete_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
{
- struct mailbox_cmd_context *ctx;
+ struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
const char *name;
unsigned int i;
if (args[0] == NULL)
doveadm_mail_help_name("mailbox delete");
- ctx = doveadm_mail_cmd_init(struct mailbox_cmd_context);
- ctx->ctx.run = cmd_mailbox_delete_run;
- p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
-
for (i = 0; args[i] != NULL; i++) {
name = p_strdup(ctx->ctx.pool, args[i]);
array_append(&ctx->mailboxes, &name, 1);
}
+}
+
+static struct doveadm_mail_cmd_context *cmd_mailbox_delete_alloc(void)
+{
+ struct mailbox_cmd_context *ctx;
+
+ ctx = doveadm_mail_cmd_alloc(struct mailbox_cmd_context);
+ ctx->ctx.init = cmd_mailbox_delete_init;
+ ctx->ctx.run = cmd_mailbox_delete_run;
+ p_array_init(&ctx->mailboxes, ctx->ctx.pool, 16);
return &ctx->ctx;
}
@@ -201,17 +222,41 @@
mailbox_free(&newbox);
}
-struct doveadm_mail_cmd_context *cmd_mailbox_rename(const char *const args[])
+static void cmd_mailbox_rename_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
{
- struct rename_cmd_context *ctx;
+ struct rename_cmd_context *ctx = (struct rename_cmd_context *)_ctx;
if (str_array_length(args) != 2)
doveadm_mail_help_name("mailbox rename");
- ctx = doveadm_mail_cmd_init(struct rename_cmd_context);
- ctx->ctx.run = cmd_mailbox_rename_run;
-
ctx->oldname = p_strdup(ctx->ctx.pool, args[0]);
ctx->newname = p_strdup(ctx->ctx.pool, args[1]);
+}
+
+static struct doveadm_mail_cmd_context *cmd_mailbox_rename_alloc(void)
+{
+ struct rename_cmd_context *ctx;
+
+ ctx = doveadm_mail_cmd_alloc(struct rename_cmd_context);
+ ctx->ctx.init = cmd_mailbox_rename_init;
+ ctx->ctx.run = cmd_mailbox_rename_run;
return &ctx->ctx;
}
+
+struct doveadm_mail_cmd cmd_mailbox_list = {
+ cmd_mailbox_list_alloc, "mailbox list",
+ "[-7|-8] [<mailbox> [...]]"
+};
+struct doveadm_mail_cmd cmd_mailbox_create = {
+ cmd_mailbox_create_alloc, "mailbox create",
+ "[-7|-8] <mailbox> [...]"
+};
+struct doveadm_mail_cmd cmd_mailbox_delete = {
+ cmd_mailbox_delete_alloc, "mailbox delete",
+ "[-7|-8] <mailbox> [...]"
+};
+struct doveadm_mail_cmd cmd_mailbox_rename = {
+ cmd_mailbox_rename_alloc, "mailbox rename",
+ "[-7|-8] <old name> <new name>"
+};
diff -r 13af90173e4f -r 0c9db163d538 src/doveadm/doveadm-mail-search.c
--- a/src/doveadm/doveadm-mail-search.c Thu May 13 09:27:06 2010 +0200
+++ b/src/doveadm/doveadm-mail-search.c Thu May 13 10:59:37 2010 +0200
@@ -60,15 +60,27 @@
doveadm_mail_list_iter_deinit(&iter);
}
-struct doveadm_mail_cmd_context *cmd_search(const char *const args[])
+static void cmd_search_init(struct doveadm_mail_cmd_context *_ctx,
+ const char *const args[])
{
- struct search_cmd_context *ctx;
+ struct search_cmd_context *ctx = (struct search_cmd_context *)_ctx;
if (args[0] == NULL)
doveadm_mail_help_name("search");
- ctx = doveadm_mail_cmd_init(struct search_cmd_context);
+ ctx->search_args = doveadm_mail_build_search_args(args);
+}
+
+static struct doveadm_mail_cmd_context *cmd_search_alloc(void)
+{
More information about the dovecot-cvs
mailing list