~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-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/{control,rules}: enable PIE hardening.
  + 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.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2010-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
5
5
#include "mail-index.h"
6
6
#include "mail-storage.h"
7
7
#include "mail-namespace.h"
8
 
#include "doveadm-mail-list-iter.h"
 
8
#include "doveadm-mailbox-list-iter.h"
9
9
#include "doveadm-mail-iter.h"
10
10
#include "doveadm-mail.h"
11
11
 
15
15
};
16
16
 
17
17
static int
18
 
cmd_altmove_box(const struct mailbox_info *info,
 
18
cmd_altmove_box(struct doveadm_mail_cmd_context *ctx,
 
19
                const struct mailbox_info *info,
19
20
                struct mail_search_args *search_args, bool reverse)
20
21
{
21
22
        struct doveadm_mail_iter *iter;
24
25
        enum modify_type modify_type =
25
26
                !reverse ? MODIFY_ADD : MODIFY_REMOVE;
26
27
 
27
 
        if (doveadm_mail_iter_init(info, search_args, &trans, &iter) < 0)
 
28
        if (doveadm_mail_iter_init(ctx, info, search_args, 0, NULL,
 
29
                                   &trans, &iter) < 0)
28
30
                return -1;
29
31
 
30
 
        mail = mail_alloc(trans, 0, NULL);
31
 
        while (doveadm_mail_iter_next(iter, mail)) {
 
32
        while (doveadm_mail_iter_next(iter, &mail)) {
32
33
                if (doveadm_debug) {
33
34
                        i_debug("altmove: box=%s uid=%u",
34
35
                                info->name, mail->uid);
36
37
                mail_update_flags(mail, modify_type,
37
38
                        (enum mail_flags)MAIL_INDEX_MAIL_FLAG_BACKEND);
38
39
        }
39
 
        mail_free(&mail);
40
40
        return doveadm_mail_iter_deinit_sync(&iter);
41
41
}
42
42
 
43
 
static void ns_purge(struct mail_namespace *ns)
 
43
static int
 
44
ns_purge(struct doveadm_mail_cmd_context *ctx, struct mail_namespace *ns)
44
45
{
45
46
        if (mail_storage_purge(ns->storage) < 0) {
46
47
                i_error("Purging namespace '%s' failed: %s", ns->prefix,
47
48
                        mail_storage_get_last_error(ns->storage, NULL));
 
49
                doveadm_mail_failed_storage(ctx, ns->storage);
 
50
                return -1;
48
51
        }
 
52
        return 0;
49
53
}
50
54
 
51
 
static void
 
55
static int
52
56
cmd_altmove_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
53
57
{
54
58
        struct altmove_cmd_context *ctx = (struct altmove_cmd_context *)_ctx;
55
59
        const enum mailbox_list_iter_flags iter_flags =
56
60
                MAILBOX_LIST_ITER_RAW_LIST |
57
 
                MAILBOX_LIST_ITER_NO_AUTO_INBOX |
 
61
                MAILBOX_LIST_ITER_NO_AUTO_BOXES |
58
62
                MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
59
 
        struct doveadm_mail_list_iter *iter;
 
63
        struct doveadm_mailbox_list_iter *iter;
60
64
        const struct mailbox_info *info;
61
65
        struct mail_namespace *ns, *prev_ns = NULL;
62
66
        ARRAY_DEFINE(purged_storages, struct mail_storage *);
63
67
        struct mail_storage *const *storages;
64
68
        unsigned int i, count;
 
69
        int ret = 0;
65
70
 
66
71
        t_array_init(&purged_storages, 8);
67
 
        iter = doveadm_mail_list_iter_init(user, _ctx->search_args, iter_flags);
68
 
        while ((info = doveadm_mail_list_iter_next(iter)) != NULL) T_BEGIN {
 
72
        iter = doveadm_mailbox_list_iter_init(_ctx, user, _ctx->search_args,
 
73
                                              iter_flags);
 
74
        while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) T_BEGIN {
69
75
                if (info->ns != prev_ns) {
70
76
                        if (prev_ns != NULL) {
71
 
                                ns_purge(prev_ns);
 
77
                                if (ns_purge(_ctx, prev_ns) < 0)
 
78
                                        ret = -1;
72
79
                                array_append(&purged_storages,
73
80
                                             &prev_ns->storage, 1);
74
81
                        }
75
82
                        prev_ns = info->ns;
76
83
                }
77
 
                (void)cmd_altmove_box(info, _ctx->search_args, ctx->reverse);
 
84
                if (cmd_altmove_box(_ctx, info, _ctx->search_args, ctx->reverse) < 0)
 
85
                        ret = -1;
78
86
        } T_END;
79
 
        doveadm_mail_list_iter_deinit(&iter);
 
87
        if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
 
88
                ret = -1;
80
89
 
81
90
        /* make sure all private storages have been purged */
82
91
        storages = array_get(&purged_storages, &count);
89
98
                                break;
90
99
                }
91
100
                if (i == count) {
92
 
                        ns_purge(ns);
 
101
                        if (ns_purge(_ctx, ns) < 0)
 
102
                                ret = -1;
93
103
                        array_append(&purged_storages, &ns->storage, 1);
94
104
                }
95
105
        }
 
106
        return ret;
96
107
}
97
108
 
98
109
static void cmd_altmove_init(struct doveadm_mail_cmd_context *ctx,