virtual-config.c revision de4d9f77d6378a416c9963963eac5ac18b75ec0b
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2008-2010 Dovecot authors, see the included COPYING file */
4c9294fcb17fb12326ff5db29e2f882cf4bd7fedTimo Sirainenvirtual_search_args_parse(const string_t *rule, const char **error_r)
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen input = i_stream_create_from_data(str_data(rule), str_len(rule));
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen imap_parser = imap_parser_create(input, NULL, (size_t)-1);
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen ret = imap_parser_finish_line(imap_parser, 0, 0, &args);
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen *error_r = t_strdup(imap_parser_get_error(imap_parser, &fatal));
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen if (mail_search_build(mail_search_register_imap, parser, "UTF-8",
58a770f1e0ab553a0dba9cad9d6f3a6cdf2dc855Timo Sirainenvirtual_config_add_rule(struct virtual_parse_context *ctx, const char **error_r)
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen unsigned int i, count;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen if (ctx->rule_idx == array_count(&ctx->mbox->backend_boxes)) {
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen crc32_str_more(ctx->mbox->search_args_crc32, str_c(ctx->rule));
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen search_args = virtual_search_args_parse(ctx->rule, error_r);
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen *error_r = t_strconcat("Previous search rule is invalid: ",
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* update at all the mailboxes that were introduced since the previous
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen bboxes = array_get(&ctx->mbox->backend_boxes, &count);
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen ctx->rule_idx = array_count(&ctx->mbox->backend_boxes);
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainenvirtual_config_parse_line(struct virtual_parse_context *ctx, const char *line,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen const char **error_r)
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen struct mail_user *user = ctx->mbox->storage->storage.user;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* continues the previous search rule */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen if (ctx->rule_idx == array_count(&ctx->mbox->backend_boxes)) {
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* if there is no rule yet, it means we want the previous mailboxes
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen to use the rule that comes later */
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen if (virtual_config_add_rule(ctx, error_r) < 0)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* new mailbox. the search args are added to it later. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen bbox = p_new(ctx->pool, struct virtual_backend_box, 1);
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen mail_namespace_find(user->namespaces, &line) :
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen *error_r = t_strdup_printf("Namespace not found for %s",
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen name = bbox->name[0] == '-' ? bbox->name + 1 : bbox->name;
4c9294fcb17fb12326ff5db29e2f882cf4bd7fedTimo Sirainen bbox->glob = imap_match_init(ctx->pool, name, TRUE, ctx->sep);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* save messages here */
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen array_append(&ctx->mbox->backend_boxes, &bbox, 1);
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainenvirtual_mailbox_get_list_patterns(struct virtual_parse_context *ctx)
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen unsigned int i, count;
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen bboxes = array_get_modifiable(&mbox->backend_boxes, &count);
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen p_array_init(&mbox->list_include_patterns, ctx->pool, count);
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen p_array_init(&mbox->list_exclude_patterns, ctx->pool, count);
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen for (i = 0; i < count; i++) {
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainenseparate_wildcard_mailboxes(struct virtual_mailbox *mbox,
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen ARRAY_TYPE(virtual_backend_box) *wildcard_boxes,
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen unsigned int i, count;
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen bboxes = array_get_modifiable(&mbox->backend_boxes, &count);
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen t_array_init(wildcard_boxes, I_MIN(16, count));
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen for (i = 0; i < count;) {
99df8a838cd9c5257ea5a2554383a9a999191e38Pali Rohár bboxes = array_get_modifiable(&mbox->backend_boxes,
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainenstatic void virtual_config_copy_expanded(struct virtual_parse_context *ctx,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen bbox = p_new(ctx->pool, struct virtual_backend_box, 1);
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++) {