changeset 13665:afec4ceda8e1

doveadm import: Added -s parameter to subscribe to created mailboxes.
author Timo Sirainen <tss@iki.fi>
date Sat, 05 Nov 2011 19:59:55 +0200
parents 3248730d84ae
children 3ecd119bd63b
files src/doveadm/doveadm-mail-import.c
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-mail-import.c	Sat Nov 05 19:37:23 2011 +0200
+++ b/src/doveadm/doveadm-mail-import.c	Sat Nov 05 19:59:55 2011 +0200
@@ -14,6 +14,7 @@
 
 	struct mail_user *src_user;
 	const char *dest_parent;
+	bool subscribe;
 };
 
 static int
@@ -53,6 +54,12 @@
 			return -1;
 		}
 	}
+	if (ctx->subscribe) {
+		if (mailbox_set_subscribed(box, TRUE) < 0) {
+			i_error("Couldn't subscribe to mailbox %s: %s",
+				name, mailbox_get_last_error(box, NULL));
+		}
+	}
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 		i_error("Syncing mailbox %s failed: %s", name,
 			mailbox_get_last_error(box, NULL));
@@ -183,11 +190,27 @@
 	mail_user_unref(&ctx->src_user);
 }
 
+static bool cmd_import_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
+{
+	struct import_cmd_context *ctx = (struct import_cmd_context *)_ctx;
+
+	switch (c) {
+	case 's':
+		ctx->subscribe = TRUE;
+		break;
+	default:
+		return FALSE;
+	}
+	return TRUE;
+}
+
 static struct doveadm_mail_cmd_context *cmd_import_alloc(void)
 {
 	struct import_cmd_context *ctx;
 
 	ctx = doveadm_mail_cmd_alloc(struct import_cmd_context);
+	ctx->ctx.getopt_args = "s";
+	ctx->ctx.v.parse_arg = cmd_import_parse_arg;
 	ctx->ctx.v.init = cmd_import_init;
 	ctx->ctx.v.deinit = cmd_import_deinit;
 	ctx->ctx.v.run = cmd_import_run;
@@ -196,5 +219,5 @@
 
 struct doveadm_mail_cmd cmd_import = {
 	cmd_import_alloc, "import",
-	"<source mail location> <dest parent mailbox> <search query>"
+	"[-s] <source mail location> <dest parent mailbox> <search query>"
 };