virtual-config.c revision eca30f1fe8556c46abc75c94d03f59b2e89d4162
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2008-2010 Dovecot authors, see the included COPYING file */
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainenvirtual_search_args_parse(const string_t *rule, const char **error_r)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen input = i_stream_create_from_data(str_data(rule), str_len(rule));
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen parser = imap_parser_create(input, NULL, (size_t)-1);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen ret = imap_parser_finish_line(parser, 0, 0, &args);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen *error_r = t_strdup(imap_parser_get_error(parser, &fatal));
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen } else if (mail_search_build_from_imap_args(args, "UTF-8", &sargs,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenvirtual_config_add_rule(struct virtual_parse_context *ctx, const char **error_r)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen unsigned int i, count;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen if (ctx->rule_idx == array_count(&ctx->mbox->backend_boxes)) {
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen crc32_str_more(ctx->mbox->search_args_crc32, str_c(ctx->rule));
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen search_args = virtual_search_args_parse(ctx->rule, error_r);
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen *error_r = t_strconcat("Previous search rule is invalid: ",
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainen /* update at all the mailboxes that were introduced since the previous
d42eb03b3a4e79a2da22a1be2de59b95660af2beTimo Sirainen bboxes = array_get(&ctx->mbox->backend_boxes, &count);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen ctx->rule_idx = array_count(&ctx->mbox->backend_boxes);
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainenvirtual_config_parse_line(struct virtual_parse_context *ctx, const char *line,
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen const char **error_r)
ced118ac5caf6fe83d34339c2c65c63b2aa768acTimo Sirainen struct mail_user *user = ctx->mbox->storage->storage.user;
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen /* continues the previous search rule */
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen if (ctx->rule_idx == array_count(&ctx->mbox->backend_boxes)) {
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen /* if there is no rule yet, it means we want the previous mailboxes
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen to use the rule that comes later */
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen if (virtual_config_add_rule(ctx, error_r) < 0)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen /* new mailbox. the search args are added to it later. */
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen bbox = p_new(ctx->pool, struct virtual_backend_box, 1);
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen mail_namespace_find(user->namespaces, &line) :
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen *error_r = t_strdup_printf("Namespace not found for %s",
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen name = bbox->name[0] == '-' ? bbox->name + 1 : bbox->name;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen bbox->glob = imap_match_init(ctx->pool, name, TRUE, ctx->sep);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen /* save messages here */
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen array_append(&ctx->mbox->backend_boxes, &bbox, 1);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainenvirtual_mailbox_get_list_patterns(struct virtual_parse_context *ctx)
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen unsigned int i, count;
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen bboxes = array_get_modifiable(&mbox->backend_boxes, &count);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen p_array_init(&mbox->list_include_patterns, ctx->pool, count);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen p_array_init(&mbox->list_exclude_patterns, ctx->pool, count);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen for (i = 0; i < count; i++) {
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainenseparate_wildcard_mailboxes(struct virtual_mailbox *mbox,
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen ARRAY_TYPE(virtual_backend_box) *wildcard_boxes,
690bafa70767e3f6e98bbfd62ad4a26be2387ea9Timo Sirainen unsigned int i, count;
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen bboxes = array_get_modifiable(&mbox->backend_boxes, &count);
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen t_array_init(wildcard_boxes, I_MIN(16, count));
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen for (i = 0; i < count;) {
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen bboxes = array_get_modifiable(&mbox->backend_boxes,
const char *name)
unsigned int *idx_r)
unsigned int i, count;
for (i = 0; i < count; i++) {
*idx_r = i;
return TRUE;
*idx_r = i;
return TRUE;
return FALSE;
const char **patterns;
unsigned int i, j, count;
if (count == 0) {
for (i = 0; i < count; i++)
for (i = 0; i < count; i++)
unsigned int i, count;
for (i = 0; i < count; i++) {
unsigned int linenum = 0;
linenum++;
if (ret < 0) {
if (ret == 0) {
if (ret < 0) {
if (ret == 0)
return ret;
unsigned int i, count;
for (i = 0; i < count; i++) {