~ubuntu-branches/ubuntu/utopic/dovecot/utopic

« back to all changes in this revision

Viewing changes to src/doveadm/doveadm-mail-import.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2010-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
 
5
#include "str.h"
5
6
#include "mail-storage.h"
6
7
#include "mail-storage-service.h"
7
8
#include "mail-namespace.h"
17
18
        bool subscribe;
18
19
};
19
20
 
 
21
static const char *
 
22
convert_vname_separators(const char *vname, char src_sep, char dest_sep)
 
23
{
 
24
        string_t *str = t_str_new(128);
 
25
 
 
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, '_');
 
31
                else
 
32
                        str_append_c(str, *vname);
 
33
        }
 
34
        return str_c(str);
 
35
}
 
36
 
20
37
static int
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)
24
42
{
25
43
        struct mail_namespace *ns;
26
44
        struct mailbox *box;
27
45
        enum mail_error error;
28
 
        const char *errstr;
 
46
        const char *name, *errstr;
29
47
 
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);
33
 
                if (ns == NULL) {
34
 
                        i_error("Can't find namespace for parent mailbox %s",
35
 
                                ctx->dest_parent);
36
 
                        doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_NOTFOUND);
37
 
                        return -1;
38
 
                }
 
51
        } else {
 
52
                ns = mail_namespace_find(user->namespaces, info->vname);
 
53
        }
 
54
        name = convert_vname_separators(info->vname,
 
55
                                        mail_namespace_get_sep(info->ns),
 
56
                                        mail_namespace_get_sep(ns));
 
57
 
 
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);
41
61
        }
42
62
 
43
 
        ns = mail_namespace_find(user->namespaces, name);
44
 
        if (ns == NULL) {
45
 
                i_error("Can't find namespace for mailbox %s", name);
46
 
                doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_NOTFOUND);
47
 
                return -1;
48
 
        }
49
 
 
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)
115
128
{
116
129
        struct doveadm_mail_iter *iter;
117
 
        struct mailbox_transaction_context *trans;
118
130
        struct mailbox *box;
119
131
        struct mail *mail;
120
132
        int ret = 0;
121
133
 
122
134
        if (doveadm_mail_iter_init(&ctx->ctx, info, search_args, 0, NULL,
123
 
                                   &trans, &iter) < 0)
 
135
                                   &iter) < 0)
124
136
                return -1;
125
137
 
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,
129
 
                                                &box) < 0)
 
140
                if (dest_mailbox_open_or_create(ctx, dest_user, info, &box) < 0)
130
141
                        ret = -1;
131
142
                else {
132
143
                        if (cmd_import_box_contents(iter, mail, box) < 0) {
146
157
{
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;