dovecot-2.0: doveadm: Added subscribe/unsubscribe commands.

dovecot at dovecot.org dovecot at dovecot.org
Thu May 13 13:05:54 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/76d4b3ac7bfa
changeset: 11300:76d4b3ac7bfa
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 13 12:05:24 2010 +0200
description:
doveadm: Added subscribe/unsubscribe commands.

diffstat:

 src/doveadm/doveadm-mail-mailbox.c |  82 +++++++++++++++++++++++++++++++++++++++++
 src/doveadm/doveadm-mail.c         |   4 +-
 src/doveadm/doveadm-mail.h         |   2 +
 3 files changed, 87 insertions(+), 1 deletions(-)

diffs (124 lines):

diff -r 9a86c335c3ed -r 76d4b3ac7bfa src/doveadm/doveadm-mail-mailbox.c
--- a/src/doveadm/doveadm-mail-mailbox.c	Thu May 13 11:58:29 2010 +0200
+++ b/src/doveadm/doveadm-mail-mailbox.c	Thu May 13 12:05:24 2010 +0200
@@ -366,6 +366,80 @@
 	return &ctx->ctx.ctx;
 }
 
+static void
+cmd_mailbox_subscribe_run(struct doveadm_mail_cmd_context *_ctx,
+			  struct mail_user *user)
+{
+	struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
+	struct mail_namespace *ns;
+	struct mailbox *box;
+	const char *const *namep;
+
+	array_foreach(&ctx->mailboxes, namep) {
+		const char *storage_name = *namep;
+
+		ns = mail_namespace_find(user->namespaces, &storage_name);
+		if (ns == NULL)
+			i_fatal("Can't find namespace for: %s", *namep);
+
+		box = mailbox_alloc(ns->list, storage_name, 0);
+		if (mailbox_list_set_subscribed(ns->list, storage_name,
+						ctx->ctx.subscriptions) < 0) {
+			i_error("Can't %s mailbox %s: %s", *namep,
+				ctx->ctx.subscriptions ? "subscribe to" :
+				"unsubscribe",
+				mailbox_list_get_last_error(ns->list, NULL));
+		}
+		mailbox_free(&box);
+	}
+}
+
+static void cmd_mailbox_subscribe_init(struct doveadm_mail_cmd_context *_ctx,
+				       const char *const args[])
+{
+	struct mailbox_cmd_context *ctx = (struct mailbox_cmd_context *)_ctx;
+	const char *name;
+	unsigned int i;
+
+	if (args[0] == NULL) {
+		doveadm_mail_help_name(ctx->ctx.subscriptions ?
+				       "mailbox subscribe" :
+				       "mailbox unsubscribe");
+	}
+	doveadm_mailbox_translate_args(&ctx->ctx, &args);
+
+	for (i = 0; args[i] != NULL; i++) {
+		name = p_strdup(ctx->ctx.ctx.pool, args[i]);
+		array_append(&ctx->mailboxes, &name, 1);
+	}
+}
+
+static struct doveadm_mail_cmd_context *
+cmd_mailbox_subscriptions_alloc(bool subscriptions)
+{
+	struct mailbox_cmd_context *ctx;
+
+	ctx = doveadm_mail_cmd_alloc(struct mailbox_cmd_context);
+	ctx->ctx.subscriptions = subscriptions;
+
+	ctx->ctx.ctx.getopt_args = "78";
+	ctx->ctx.ctx.parse_arg = cmd_mailbox_parse_arg;
+	ctx->ctx.ctx.init = cmd_mailbox_subscribe_init;
+	ctx->ctx.ctx.run = cmd_mailbox_subscribe_run;
+	p_array_init(&ctx->mailboxes, ctx->ctx.ctx.pool, 16);
+	return &ctx->ctx.ctx;
+}
+
+static struct doveadm_mail_cmd_context *cmd_mailbox_subscribe_alloc(void)
+{
+	return cmd_mailbox_subscriptions_alloc(TRUE);
+}
+
+static struct doveadm_mail_cmd_context *cmd_mailbox_unsubscribe_alloc(void)
+{
+	return cmd_mailbox_subscriptions_alloc(FALSE);
+}
+
 static void cmd_mailbox_convert(int argc, char *argv[])
 {
 	string_t *str;
@@ -425,6 +499,14 @@
 	cmd_mailbox_rename_alloc, "mailbox rename",
 	"[-7|-8] [-s] <old name> <new name>"
 };
+struct doveadm_mail_cmd cmd_mailbox_subscribe = {
+	cmd_mailbox_subscribe_alloc, "mailbox subscribe",
+	"[-7|-8] <mailbox> [...]"
+};
+struct doveadm_mail_cmd cmd_mailbox_unsubscribe = {
+	cmd_mailbox_unsubscribe_alloc, "mailbox unsubscribe",
+	"[-7|-8] <mailbox> [...]"
+};
 struct doveadm_cmd doveadm_cmd_mailbox_convert = {
 	cmd_mailbox_convert, "mailbox convert",
 	"[-7|-8] <name> [...]", NULL
diff -r 9a86c335c3ed -r 76d4b3ac7bfa src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Thu May 13 11:58:29 2010 +0200
+++ b/src/doveadm/doveadm-mail.c	Thu May 13 12:05:24 2010 +0200
@@ -450,7 +450,9 @@
 	&cmd_mailbox_list,
 	&cmd_mailbox_create,
 	&cmd_mailbox_delete,
-	&cmd_mailbox_rename
+	&cmd_mailbox_rename,
+	&cmd_mailbox_subscribe,
+	&cmd_mailbox_unsubscribe
 };
 
 void doveadm_mail_init(void)
diff -r 9a86c335c3ed -r 76d4b3ac7bfa src/doveadm/doveadm-mail.h
--- a/src/doveadm/doveadm-mail.h	Thu May 13 11:58:29 2010 +0200
+++ b/src/doveadm/doveadm-mail.h	Thu May 13 12:05:24 2010 +0200
@@ -56,5 +56,7 @@
 struct doveadm_mail_cmd cmd_mailbox_create;
 struct doveadm_mail_cmd cmd_mailbox_delete;
 struct doveadm_mail_cmd cmd_mailbox_rename;
+struct doveadm_mail_cmd cmd_mailbox_subscribe;
+struct doveadm_mail_cmd cmd_mailbox_unsubscribe;
 
 #endif


More information about the dovecot-cvs mailing list