comparison src/lib-storage/list/index-mailbox-list.c @ 6054:d0787ca97a0c HEAD

Fixed support for multiple patterns
author Timo Sirainen <tss@iki.fi>
date Wed, 18 Jul 2007 01:45:34 +0300
parents cc1f4688a988
children 437dce5162c5
comparison
equal deleted inserted replaced
6053:e6f3f17da3e7 6054:d0787ca97a0c
114 enum mailbox_list_iter_flags flags) 114 enum mailbox_list_iter_flags flags)
115 { 115 {
116 struct index_mailbox_list *ilist = INDEX_LIST_CONTEXT(list); 116 struct index_mailbox_list *ilist = INDEX_LIST_CONTEXT(list);
117 struct index_mailbox_list_iterate_context *ctx; 117 struct index_mailbox_list_iterate_context *ctx;
118 enum mailbox_list_sync_flags sync_flags; 118 enum mailbox_list_sync_flags sync_flags;
119 const char *prefix; 119 const char *prefix, *cur_prefix, *const *tmp, *tmp_patterns[2];
120 int recurse_level; 120 int cur_recurse_level;
121 121
122 ctx = i_new(struct index_mailbox_list_iterate_context, 1); 122 ctx = i_new(struct index_mailbox_list_iterate_context, 1);
123 ctx->ctx.list = list; 123 ctx->ctx.list = list;
124 ctx->ctx.flags = flags; 124 ctx->ctx.flags = flags;
125 ctx->glob = imap_match_init(default_pool, patterns[0], TRUE, // FIXME 125
126 list->hierarchy_sep);
127
128 ctx->mail_view = mail_index_view_open(ilist->mail_index);
129 ctx->view = mailbox_list_index_view_init(ilist->list_index,
130 ctx->mail_view);
131 if ((flags & MAILBOX_LIST_ITER_RAW_LIST) != 0) { 126 if ((flags & MAILBOX_LIST_ITER_RAW_LIST) != 0) {
132 /* Ignore indexes completely */ 127 /* Ignore indexes completely */
133 ctx->backend_ctx = ilist->module_ctx.super. 128 ctx->backend_ctx = ilist->module_ctx.super.
134 iter_init(list, patterns, flags); 129 iter_init(list, patterns, flags);
135 } else if (index_mailbox_list_is_synced(ctx) > 0) { 130 return &ctx->ctx;
131 }
132
133 ctx->glob = imap_match_init_multiple(default_pool, patterns, TRUE,
134 list->hierarchy_sep);
135 ctx->mail_view = mail_index_view_open(ilist->mail_index);
136 ctx->view = mailbox_list_index_view_init(ilist->list_index,
137 ctx->mail_view);
138
139 /* FIXME: we could just do multiple lookups for different patterns */
140 prefix = NULL;
141 for (tmp = patterns; *tmp != NULL; tmp++) {
142 pattern_parse(list, *tmp, &cur_prefix, &cur_recurse_level);
143 if (prefix != NULL && strcmp(prefix, cur_prefix) != 0)
144 prefix = "";
145 if (cur_recurse_level > ctx->recurse_level ||
146 cur_recurse_level == -1)
147 ctx->recurse_level = cur_recurse_level;
148 }
149
150 if (index_mailbox_list_is_synced(ctx) > 0) {
136 /* synced, list from index */ 151 /* synced, list from index */
137 pattern_parse(list, patterns[0], &prefix, &recurse_level); // FIXME
138
139 ctx->info_pool = 152 ctx->info_pool =
140 pool_alloconly_create("mailbox name pool", 128); 153 pool_alloconly_create("mailbox name pool", 128);
141 ctx->iter_ctx = mailbox_list_index_iterate_init(ctx->view, 154 ctx->iter_ctx = mailbox_list_index_iterate_init(ctx->view,
142 prefix, 155 prefix, ctx->recurse_level);
143 recurse_level);
144 ctx->recurse_level = recurse_level;
145 ctx->prefix = *prefix == '\0' ? i_strdup("") : 156 ctx->prefix = *prefix == '\0' ? i_strdup("") :
146 i_strdup_printf("%s%c", prefix, list->hierarchy_sep); 157 i_strdup_printf("%s%c", prefix, list->hierarchy_sep);
147 } else { 158 } else {
148 /* FIXME: this works nicely with maildir++, but not others */ 159 /* FIXME: this works nicely with maildir++, but not others */
149 sync_flags = MAILBOX_LIST_SYNC_FLAG_RECURSIVE; 160 sync_flags = MAILBOX_LIST_SYNC_FLAG_RECURSIVE;
150 161
151 if (strchr(patterns[0], '*') != NULL) // FIXME 162 if (ctx->recurse_level >= 0) {
152 ctx->recurse_level = -1;
153 else {
154 ctx->mailbox_tree = 163 ctx->mailbox_tree =
155 mailbox_tree_init(list->hierarchy_sep); 164 mailbox_tree_init(list->hierarchy_sep);
156 } 165 }
157 166
158 ctx->info_pool = 167 ctx->info_pool =
159 pool_alloconly_create("mailbox name pool", 128); 168 pool_alloconly_create("mailbox name pool", 128);
160 if (mailbox_list_index_sync_init(ilist->list_index, "", 169 if (mailbox_list_index_sync_init(ilist->list_index, "",
161 sync_flags, 170 sync_flags,
162 &ctx->sync_ctx) == 0) { 171 &ctx->sync_ctx) == 0) {
163 //FIXME:patterns = "*"; 172 tmp_patterns[0] = "*"; tmp_patterns[1] = NULL;
164 prefix = ""; 173 patterns = tmp_patterns;
165 ctx->trans = mailbox_list_index_sync_get_transaction( 174 ctx->trans = mailbox_list_index_sync_get_transaction(
166 ctx->sync_ctx); 175 ctx->sync_ctx);
167 } 176 }
168 177
169 ctx->backend_ctx = ilist->module_ctx.super. 178 ctx->backend_ctx = ilist->module_ctx.super.
384 } 393 }
385 } else if (ctx->backend_ctx != NULL) { 394 } else if (ctx->backend_ctx != NULL) {
386 ret = ilist->module_ctx.super.iter_deinit(ctx->backend_ctx); 395 ret = ilist->module_ctx.super.iter_deinit(ctx->backend_ctx);
387 } 396 }
388 397
389 imap_match_deinit(&ctx->glob); 398 if (ctx->glob != NULL)
399 imap_match_deinit(&ctx->glob);
390 i_free(ctx->prefix); 400 i_free(ctx->prefix);
391 i_free(ctx); 401 i_free(ctx);
392 return ret; 402 return ret;
393 } 403 }
394 404