1
/* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */
1
/* Copyright (c) 2010-2013 Dovecot authors, see the included COPYING file */
5
6
#include "mail-storage.h"
6
7
#include "mail-storage-service.h"
7
8
#include "mail-namespace.h"
22
convert_vname_separators(const char *vname, char src_sep, char dest_sep)
24
string_t *str = t_str_new(128);
26
for (; *vname != '\0'; vname++) {
27
if (*vname == src_sep)
28
str_append_c(str, dest_sep);
29
else if (*vname == dest_sep)
30
str_append_c(str, '_');
32
str_append_c(str, *vname);
21
38
dest_mailbox_open_or_create(struct import_cmd_context *ctx,
22
struct mail_user *user, const char *name,
39
struct mail_user *user,
40
const struct mailbox_info *info,
23
41
struct mailbox **box_r)
25
43
struct mail_namespace *ns;
26
44
struct mailbox *box;
27
45
enum mail_error error;
46
const char *name, *errstr;
30
48
if (*ctx->dest_parent != '\0') {
31
49
/* prefix destination mailbox name with given parent mailbox */
32
50
ns = mail_namespace_find(user->namespaces, ctx->dest_parent);
34
i_error("Can't find namespace for parent mailbox %s",
36
doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_NOTFOUND);
52
ns = mail_namespace_find(user->namespaces, info->vname);
54
name = convert_vname_separators(info->vname,
55
mail_namespace_get_sep(info->ns),
56
mail_namespace_get_sep(ns));
58
if (*ctx->dest_parent != '\0') {
39
59
name = t_strdup_printf("%s%c%s", ctx->dest_parent,
40
60
mail_namespace_get_sep(ns), name);
43
ns = mail_namespace_find(user->namespaces, name);
45
i_error("Can't find namespace for mailbox %s", name);
46
doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_NOTFOUND);
50
63
box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY);
51
64
if (mailbox_create(box, NULL, FALSE) < 0) {
52
65
errstr = mailbox_get_last_error(box, &error);
114
127
struct mail_search_args *search_args)
116
129
struct doveadm_mail_iter *iter;
117
struct mailbox_transaction_context *trans;
118
130
struct mailbox *box;
119
131
struct mail *mail;
122
134
if (doveadm_mail_iter_init(&ctx->ctx, info, search_args, 0, NULL,
126
138
if (doveadm_mail_iter_next(iter, &mail)) {
127
139
/* at least one mail matches in this mailbox */
128
if (dest_mailbox_open_or_create(ctx, dest_user, info->name,
140
if (dest_mailbox_open_or_create(ctx, dest_user, info, &box) < 0)
132
143
if (cmd_import_box_contents(iter, mail, box) < 0) {
147
158
struct import_cmd_context *ctx = (struct import_cmd_context *)_ctx;
148
159
const enum mailbox_list_iter_flags iter_flags =
149
MAILBOX_LIST_ITER_RAW_LIST |
150
160
MAILBOX_LIST_ITER_NO_AUTO_BOXES |
151
161
MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
152
162
struct doveadm_mailbox_list_iter *iter;