~ubuntu-branches/ubuntu/raring/dovecot/raring

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Marco Nenciarini
  • Date: 2011-09-19 19:26:48 UTC
  • mfrom: (1.14.4 upstream)
  • mto: (4.8.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 86.
  • Revision ID: package-import@ubuntu.com-20110919192648-ri3sovtiz334yori
Tags: 1:2.0.15-1
* [a22575a] New upstream version 2.0.15: (Closes: #642045)
    + doveadm altmove: Added -r parameter to move mails back to primary
      storage.
    - v2.0.14: Index reading could have eaten a lot of memory in some
      situations
    - doveadm index no longer affects future caching decisions
    - mbox: Fixed crash during mail delivery when mailbox didn't yet have
      GUID assigned to it.
    - zlib+mbox: Fetching last message from compressed mailboxes crashed.
    - lib-sql: Fixed load balancing and error
* [8ce5abc] Update pigeonhole to release 0.2.4
* [87658d2] Add dovecot-solr to dovecot-core's Suggests line.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include "doveadm-mail-iter.h"
10
10
#include "doveadm-mail.h"
11
11
 
 
12
struct altmove_cmd_context {
 
13
        struct doveadm_mail_cmd_context ctx;
 
14
        bool reverse;
 
15
};
 
16
 
12
17
static int
13
18
cmd_altmove_box(const struct mailbox_info *info,
14
 
                struct mail_search_args *search_args)
 
19
                struct mail_search_args *search_args, bool reverse)
15
20
{
16
21
        struct doveadm_mail_iter *iter;
17
22
        struct mailbox_transaction_context *trans;
18
23
        struct mail *mail;
 
24
        enum modify_type modify_type =
 
25
                !reverse ? MODIFY_ADD : MODIFY_REMOVE;
19
26
 
20
27
        if (doveadm_mail_iter_init(info, search_args, &trans, &iter) < 0)
21
28
                return -1;
26
33
                        i_debug("altmove: box=%s uid=%u",
27
34
                                info->name, mail->uid);
28
35
                }
29
 
                mail_update_flags(mail, MODIFY_ADD,
 
36
                mail_update_flags(mail, modify_type,
30
37
                        (enum mail_flags)MAIL_INDEX_MAIL_FLAG_BACKEND);
31
38
        }
32
39
        mail_free(&mail);
42
49
}
43
50
 
44
51
static void
45
 
cmd_altmove_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
 
52
cmd_altmove_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
46
53
{
 
54
        struct altmove_cmd_context *ctx = (struct altmove_cmd_context *)_ctx;
47
55
        const enum mailbox_list_iter_flags iter_flags =
48
56
                MAILBOX_LIST_ITER_RAW_LIST |
49
57
                MAILBOX_LIST_ITER_NO_AUTO_INBOX |
56
64
        unsigned int i, count;
57
65
 
58
66
        t_array_init(&purged_storages, 8);
59
 
        iter = doveadm_mail_list_iter_init(user, ctx->search_args, iter_flags);
 
67
        iter = doveadm_mail_list_iter_init(user, _ctx->search_args, iter_flags);
60
68
        while ((info = doveadm_mail_list_iter_next(iter)) != NULL) T_BEGIN {
61
69
                if (info->ns != prev_ns) {
62
70
                        if (prev_ns != NULL) {
66
74
                        }
67
75
                        prev_ns = info->ns;
68
76
                }
69
 
                (void)cmd_altmove_box(info, ctx->search_args);
 
77
                (void)cmd_altmove_box(info, _ctx->search_args, ctx->reverse);
70
78
        } T_END;
71
79
        doveadm_mail_list_iter_deinit(&iter);
72
80
 
95
103
        ctx->search_args = doveadm_mail_build_search_args(args);
96
104
}
97
105
 
 
106
static bool
 
107
cmd_mailbox_altmove_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
 
108
{
 
109
        struct altmove_cmd_context *ctx = (struct altmove_cmd_context *)_ctx;
 
110
 
 
111
        switch (c) {
 
112
        case 'r':
 
113
                ctx->reverse = TRUE;
 
114
                break;
 
115
        default:
 
116
                return FALSE;
 
117
        }
 
118
        return TRUE;
 
119
}
 
120
 
98
121
static struct doveadm_mail_cmd_context *cmd_altmove_alloc(void)
99
122
{
100
 
        struct doveadm_mail_cmd_context *ctx;
 
123
        struct altmove_cmd_context *ctx;
101
124
 
102
 
        ctx = doveadm_mail_cmd_alloc(struct doveadm_mail_cmd_context);
103
 
        ctx->v.init = cmd_altmove_init;
104
 
        ctx->v.run = cmd_altmove_run;
105
 
        return ctx;
 
125
        ctx = doveadm_mail_cmd_alloc(struct altmove_cmd_context);
 
126
        ctx->ctx.getopt_args = "r";
 
127
        ctx->ctx.v.parse_arg = cmd_mailbox_altmove_parse_arg;
 
128
        ctx->ctx.v.init = cmd_altmove_init;
 
129
        ctx->ctx.v.run = cmd_altmove_run;
 
130
        return &ctx->ctx;
106
131
}
107
132
 
108
133
struct doveadm_mail_cmd cmd_altmove = {
109
 
        cmd_altmove_alloc, "altmove", "<search query>"
 
134
        cmd_altmove_alloc, "altmove", "[-r] <search query>"
110
135
};