dovecot-2.2: doveadm copy/move/import: Delay initializing source...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Feb 9 13:52:25 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/b4662ccd0b5e
changeset: 18235:b4662ccd0b5e
user: Timo Sirainen <tss at iki.fi>
date: Mon Feb 09 15:38:42 2015 +0200
description:
doveadm copy/move/import: Delay initializing source user until run()
This fixes using them with doveadm proxying.
diffstat:
src/doveadm/doveadm-mail-copymove.c | 10 ++++--
src/doveadm/doveadm-mail-import.c | 53 +++++++++++++++++++++---------------
2 files changed, 38 insertions(+), 25 deletions(-)
diffs (141 lines):
diff -r 111f19992c06 -r b4662ccd0b5e src/doveadm/doveadm-mail-copymove.c
--- a/src/doveadm/doveadm-mail-copymove.c Mon Feb 09 15:21:55 2015 +0200
+++ b/src/doveadm/doveadm-mail-copymove.c Mon Feb 09 15:38:42 2015 +0200
@@ -13,6 +13,7 @@
struct copy_cmd_context {
struct doveadm_mail_cmd_context ctx;
+ const char *source_username;
struct mail_storage_service_user *source_service_user;
struct mail_user *source_user;
@@ -71,13 +72,13 @@
}
static void
-cmd_copy_alloc_source_user(struct copy_cmd_context *ctx, const char *username)
+cmd_copy_alloc_source_user(struct copy_cmd_context *ctx)
{
struct mail_storage_service_input input;
const char *error;
input = ctx->ctx.storage_service_input;
- input.username = username;
+ input.username = ctx->source_username;
if (mail_storage_service_lookup_next(ctx->ctx.storage_service, &input,
&ctx->source_service_user,
@@ -100,6 +101,9 @@
const struct mailbox_info *info;
int ret = 0;
+ if (ctx->source_username != NULL && ctx->source_user == NULL)
+ cmd_copy_alloc_source_user(ctx);
+
ns = mail_namespace_find(user->namespaces, ctx->destname);
destbox = mailbox_alloc(ns->list, ctx->destname, MAILBOX_FLAG_SAVEONLY);
if (mailbox_open(destbox) < 0) {
@@ -146,7 +150,7 @@
MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) == 0)
i_fatal("Use -u parameter to specify destination user");
- cmd_copy_alloc_source_user(ctx, args[1]);
+ ctx->source_username = p_strdup(_ctx->pool, args[1]);
args += 2;
}
diff -r 111f19992c06 -r b4662ccd0b5e src/doveadm/doveadm-mail-import.c
--- a/src/doveadm/doveadm-mail-import.c Mon Feb 09 15:21:55 2015 +0200
+++ b/src/doveadm/doveadm-mail-import.c Mon Feb 09 15:38:42 2015 +0200
@@ -13,6 +13,7 @@
struct import_cmd_context {
struct doveadm_mail_cmd_context ctx;
+ const char *src_location;
struct mail_user *src_user;
const char *dest_parent;
bool subscribe;
@@ -152,6 +153,30 @@
return ret;
}
+static void cmd_import_init_source_user(struct import_cmd_context *ctx)
+{
+ struct mail_storage_service_input input;
+ struct mail_storage_service_user *service_user;
+ struct mail_user *user;
+ const char *error;
+
+ /* create a user for accessing the source storage */
+ memset(&input, 0, sizeof(input));
+ input.module = "mail";
+ input.username = "doveadm";
+ input.flags_override_add = MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES |
+ MAIL_STORAGE_SERVICE_FLAG_NO_RESTRICT_ACCESS;
+ input.flags_override_remove = MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
+ if (mail_storage_service_lookup_next(ctx->ctx.storage_service, &input,
+ &service_user, &user, &error) < 0)
+ i_fatal("Import user initialization failed: %s", error);
+ if (mail_namespaces_init_location(user, ctx->src_location, &error) < 0)
+ i_fatal("Import namespace initialization failed: %s", error);
+
+ ctx->src_user = user;
+ mail_storage_service_user_free(&service_user);
+}
+
static int
cmd_import_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
{
@@ -163,6 +188,9 @@
const struct mailbox_info *info;
int ret = 0;
+ if (ctx->src_user == NULL)
+ cmd_import_init_source_user(ctx);
+
iter = doveadm_mailbox_list_iter_init(_ctx, ctx->src_user,
_ctx->search_args, iter_flags);
while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) T_BEGIN {
@@ -178,39 +206,20 @@
const char *const args[])
{
struct import_cmd_context *ctx = (struct import_cmd_context *)_ctx;
- struct mail_storage_service_input input;
- struct mail_storage_service_user *service_user;
- struct mail_user *user;
- const char *src_location, *error;
if (str_array_length(args) < 3)
doveadm_mail_help_name("import");
- src_location = args[0];
+ ctx->src_location = p_strdup(_ctx->pool, args[0]);
ctx->dest_parent = p_strdup(_ctx->pool, args[1]);
ctx->ctx.search_args = doveadm_mail_build_search_args(args+2);
-
- /* create a user for accessing the source storage */
- memset(&input, 0, sizeof(input));
- input.module = "mail";
- input.username = "doveadm";
- input.flags_override_add = MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES |
- MAIL_STORAGE_SERVICE_FLAG_NO_RESTRICT_ACCESS;
- input.flags_override_remove = MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
- if (mail_storage_service_lookup_next(ctx->ctx.storage_service, &input,
- &service_user, &user, &error) < 0)
- i_fatal("Import user initialization failed: %s", error);
- if (mail_namespaces_init_location(user, src_location, &error) < 0)
- i_fatal("Import namespace initialization failed: %s", error);
-
- ctx->src_user = user;
- mail_storage_service_user_free(&service_user);
}
static void cmd_import_deinit(struct doveadm_mail_cmd_context *_ctx)
{
struct import_cmd_context *ctx = (struct import_cmd_context *)_ctx;
- mail_user_unref(&ctx->src_user);
+ if (ctx->src_user != NULL)
+ mail_user_unref(&ctx->src_user);
}
static bool cmd_import_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
More information about the dovecot-cvs
mailing list