~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/doveadm/doveadm-mailbox-list-iter.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

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"
24
24
        bool only_selectable;
25
25
};
26
26
 
27
 
static int
 
27
static bool
28
28
search_args_get_mailbox_patterns(const struct mail_search_arg *args,
29
29
                                 ARRAY_TYPE(const_string) *patterns,
30
30
                                 bool *have_guid, bool *have_wildcards)
43
43
                                if (!search_args_get_mailbox_patterns(subargs,
44
44
                                                        patterns, have_guid,
45
45
                                                        have_wildcards))
46
 
                                        return 0;
 
46
                                        return FALSE;
47
47
                        }
48
48
                        break;
49
49
                case SEARCH_MAILBOX_GLOB:
52
52
                case SEARCH_MAILBOX:
53
53
                        if (args->match_not) {
54
54
                                array_clear(patterns);
55
 
                                return 0;
 
55
                                return FALSE;
56
56
                        }
57
57
                        array_append(patterns, &args->value.str, 1);
58
58
                        break;
63
63
                        break;
64
64
                }
65
65
        }
66
 
        return 1;
 
66
        return TRUE;
67
67
}
68
68
 
69
69
static struct doveadm_mailbox_list_iter *
71
71
                                      struct mail_user *user,
72
72
                                      struct mail_search_args *search_args,
73
73
                                      enum mailbox_list_iter_flags iter_flags,
74
 
                                      enum namespace_type ns_mask)
 
74
                                      enum mail_namespace_type ns_mask)
75
75
{
76
76
        static const char *all_pattern = "*";
77
77
        struct doveadm_mailbox_list_iter *iter;
82
82
        iter->search_args = search_args;
83
83
        iter->user = user;
84
84
        i_array_init(&iter->patterns, 16);
85
 
        search_args_get_mailbox_patterns(search_args->args, &iter->patterns,
86
 
                                         &have_guid, &have_wildcards);
 
85
        (void)search_args_get_mailbox_patterns(search_args->args,
 
86
                                               &iter->patterns,
 
87
                                               &have_guid, &have_wildcards);
87
88
 
88
89
        if (array_count(&iter->patterns) == 0) {
89
90
                iter_flags |= MAILBOX_LIST_ITER_SKIP_ALIASES;
90
 
                if (have_guid)
91
 
                        ns_mask |= NAMESPACE_SHARED | NAMESPACE_PUBLIC;
 
91
                if (have_guid) {
 
92
                        ns_mask |= MAIL_NAMESPACE_TYPE_SHARED |
 
93
                                MAIL_NAMESPACE_TYPE_PUBLIC;
 
94
                }
92
95
                array_append(&iter->patterns, &all_pattern, 1);
93
96
        } else if (have_wildcards) {
94
97
                iter_flags |= MAILBOX_LIST_ITER_STAR_WITHIN_NS;
95
 
                ns_mask |= NAMESPACE_SHARED | NAMESPACE_PUBLIC;
 
98
                ns_mask |= MAIL_NAMESPACE_TYPE_SHARED |
 
99
                        MAIL_NAMESPACE_TYPE_PUBLIC;
96
100
        } else {
97
101
                /* just return the listed mailboxes without actually
98
102
                   iterating through. this also allows accessing mailboxes
99
103
                   without lookup ACL right */
100
104
                return iter;
101
105
        }
102
 
        (void)array_append_space(&iter->patterns);
 
106
        array_append_zero(&iter->patterns);
103
107
 
104
108
        iter->only_selectable = TRUE;
105
109
        iter->iter_flags = iter_flags;
115
119
                               struct mail_search_args *search_args,
116
120
                               enum mailbox_list_iter_flags iter_flags)
117
121
{
118
 
        enum namespace_type ns_mask = NAMESPACE_PRIVATE;
 
122
        enum mail_namespace_type ns_mask = MAIL_NAMESPACE_TYPE_PRIVATE;
119
123
 
120
124
        return doveadm_mailbox_list_iter_init_nsmask(ctx, user, search_args,
121
125
                                                     iter_flags, ns_mask);
127
131
                                    struct mail_search_args *search_args,
128
132
                                    enum mailbox_list_iter_flags iter_flags)
129
133
{
130
 
        enum namespace_type ns_mask =
131
 
                NAMESPACE_PRIVATE | NAMESPACE_SHARED | NAMESPACE_PUBLIC;
 
134
        enum mail_namespace_type ns_mask = MAIL_NAMESPACE_TYPE_MASK_ALL;
132
135
        struct doveadm_mailbox_list_iter *iter;
133
136
 
134
137
        iter = doveadm_mailbox_list_iter_init_nsmask(ctx, user, search_args,
167
170
                if (iter->pattern_idx == count)
168
171
                        return NULL;
169
172
 
170
 
                iter->info.name = patterns[iter->pattern_idx++];
 
173
                iter->info.vname = patterns[iter->pattern_idx++];
171
174
                iter->info.ns = mail_namespace_find(iter->user->namespaces,
172
 
                                                    iter->info.name);
173
 
                if (iter->info.ns != NULL)
174
 
                        return &iter->info;
175
 
                /* FIXME: maybe fail?.. or just wait for v2.2 to get rid of
176
 
                   this error condition */
 
175
                                                    iter->info.vname);
 
176
                return &iter->info;
177
177
        }
178
178
 
179
179
        while ((info = mailbox_list_iter_next(iter->iter)) != NULL) {
186
186
                }
187
187
 
188
188
                if (mail_search_args_match_mailbox(iter->search_args,
189
 
                                                   info->name, sep))
 
189
                                                   info->vname, sep))
190
190
                        break;
191
191
        }
192
192
        return info;