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

« back to all changes in this revision

Viewing changes to src/lib-storage/list/mailbox-list-index-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) 2006-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2006-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "str.h"
7
7
#include "mailbox-list-subscriptions.h"
8
8
#include "mailbox-list-index.h"
9
9
 
 
10
static bool iter_use_index(struct mailbox_list_index_iterate_context *ctx)
 
11
{
 
12
        struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT(ctx->ctx.list);
 
13
 
 
14
        if ((ctx->ctx.flags & MAILBOX_LIST_ITER_SELECT_SUBSCRIBED) != 0) {
 
15
                /* for now we don't use indexes when listing subscriptions,
 
16
                   because it needs to list also the nonexistent subscribed
 
17
                   mailboxes, which don't exist in the index. */
 
18
                return FALSE;
 
19
        }
 
20
        if ((ctx->ctx.flags & MAILBOX_LIST_ITER_RAW_LIST) != 0 &&
 
21
            ilist->has_backing_store) {
 
22
                /* no indexing wanted with raw lists */
 
23
                return FALSE;
 
24
        }
 
25
        if (mailbox_list_index_refresh(ctx->ctx.list) < 0 &&
 
26
            ilist->has_backing_store) {
 
27
                /* refresh failed */
 
28
                return FALSE;
 
29
        }
 
30
        return TRUE;
 
31
}
 
32
 
10
33
struct mailbox_list_iterate_context *
11
34
mailbox_list_index_iter_init(struct mailbox_list *list,
12
35
                             const char *const *patterns,
17
40
        pool_t pool;
18
41
        char ns_sep = mail_namespace_get_sep(list->ns);
19
42
 
20
 
        pool = pool_alloconly_create("mailbox list index iter", 1024);
 
43
        pool = pool_alloconly_create("mailbox list index iter", 2048);
21
44
        ctx = p_new(pool, struct mailbox_list_index_iterate_context, 1);
22
45
        ctx->ctx.pool = pool;
23
46
        ctx->ctx.list = list;
24
47
        ctx->ctx.flags = flags;
25
48
        ctx->ctx.glob = imap_match_init_multiple(pool, patterns, TRUE, ns_sep);
26
49
        array_create(&ctx->ctx.module_contexts, pool, sizeof(void *), 5);
27
 
        ctx->sep = ns_sep;
28
50
        ctx->info_pool = pool_alloconly_create("mailbox list index iter info", 128);
29
51
 
30
 
        if (mailbox_list_index_refresh(ctx->ctx.list) < 0) {
 
52
        if (!iter_use_index(ctx)) {
31
53
                /* no indexing */
32
54
                ctx->backend_ctx = ilist->module_ctx.super.
33
55
                        iter_init(list, patterns, flags);
36
58
                ctx->info.ns = list->ns;
37
59
                ctx->path = str_new(pool, 128);
38
60
                ctx->next_node = ilist->mailbox_tree;
39
 
                ilist->iter_refcount++;
 
61
                ctx->mailbox_pool = ilist->mailbox_pool;
 
62
                pool_ref(ctx->mailbox_pool);
40
63
        }
41
64
        return &ctx->ctx;
42
65
}
50
73
        p_clear(ctx->info_pool);
51
74
 
52
75
        str_truncate(ctx->path, ctx->parent_len);
53
 
        if (str_len(ctx->path) > 0)
54
 
                str_append_c(ctx->path, ctx->sep);
 
76
        if (str_len(ctx->path) > 0) {
 
77
                str_append_c(ctx->path,
 
78
                             mailbox_list_get_hierarchy_sep(ctx->ctx.list));
 
79
        }
55
80
        str_append(ctx->path, node->name);
56
81
 
57
 
        ctx->info.name = mailbox_list_get_vname(ctx->ctx.list, str_c(ctx->path));
58
 
        ctx->info.name = p_strdup(ctx->info_pool, ctx->info.name);
 
82
        ctx->info.vname = mailbox_list_get_vname(ctx->ctx.list, str_c(ctx->path));
 
83
        ctx->info.vname = p_strdup(ctx->info_pool, ctx->info.vname);
59
84
        ctx->info.flags = 0;
60
85
        if ((node->flags & MAILBOX_LIST_INDEX_FLAG_NONEXISTENT) != 0)
61
86
                ctx->info.flags |= MAILBOX_NONEXISTENT;
69
94
        if ((ctx->ctx.flags & (MAILBOX_LIST_ITER_SELECT_SUBSCRIBED |
70
95
                               MAILBOX_LIST_ITER_RETURN_SUBSCRIBED)) != 0) {
71
96
                mailbox_list_set_subscription_flags(ctx->ctx.list,
72
 
                                                    ctx->info.name,
 
97
                                                    ctx->info.vname,
73
98
                                                    &ctx->info.flags);
74
99
        }
75
100
 
76
 
        box = mailbox_alloc(ctx->ctx.list, ctx->info.name, 0);
 
101
        box = mailbox_alloc(ctx->ctx.list, ctx->info.vname, 0);
77
102
        mailbox_list_index_status_set_info_flags(box, node->uid,
78
103
                                                 &ctx->info.flags);
79
104
        mailbox_free(&box);
138
163
        /* listing mailboxes from index */
139
164
        while (ctx->next_node != NULL) {
140
165
                mailbox_list_index_update_info(ctx);
141
 
                match = imap_match(_ctx->glob, ctx->info.name);
 
166
                match = imap_match(_ctx->glob, ctx->info.vname);
142
167
 
143
168
                follow_children = (match & (IMAP_MATCH_YES |
144
169
                                            IMAP_MATCH_CHILDREN)) != 0;
165
190
 
166
191
        if (ctx->backend_ctx != NULL)
167
192
                ret = ilist->module_ctx.super.iter_deinit(ctx->backend_ctx);
168
 
        else {
169
 
                i_assert(ilist->iter_refcount > 0);
170
 
                ilist->iter_refcount--;
171
 
        }
 
193
        else
 
194
                pool_unref(&ctx->mailbox_pool);
172
195
 
173
196
        pool_unref(&ctx->info_pool);
174
197
        pool_unref(&_ctx->pool);