virtual-config.c revision 391970ed208650d807191e5f2fc403f20f76ce18
/* Copyright (c) 2008-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "crc32.h"
#include "istream.h"
#include "str.h"
#include "unichar.h"
#include "wildcard-match.h"
#include "imap-parser.h"
#include "imap-match.h"
#include "mail-namespace.h"
#include "mail-search-build.h"
#include "mail-search-parser.h"
#include "mailbox-attribute.h"
#include "mailbox-list-iter.h"
#include "imap-metadata.h"
#include "virtual-storage.h"
#include "virtual-plugin.h"
#include <unistd.h>
#include <fcntl.h>
struct virtual_parse_context {
struct virtual_mailbox *mbox;
unsigned int rule_idx;
char sep;
bool have_wildcards;
bool have_mailbox_defines;
};
static struct mail_search_args *
{
struct imap_parser *imap_parser;
struct mail_search_parser *parser;
struct mail_search_args *sargs;
const char *charset = "UTF-8";
int ret;
return sargs;
}
(void)i_stream_read(input);
if (ret < 0) {
} else {
}
return sargs;
}
static int
{
struct virtual_backend_box *const *bboxes;
struct mail_search_args *search_args;
unsigned int i, count;
return 0;
}
if (search_args == NULL) {
return -1;
}
/* update at all the mailboxes that were introduced since the previous
rule. */
}
return 0;
}
static int
const char **error_r)
{
struct virtual_backend_box *bbox;
const char *p;
bool no_wildcards = FALSE;
/* continues the previous search rule */
*error_r = "Search rule without a mailbox";
return -1;
}
return 0;
}
/* if there is no rule yet, it means we want the previous mailboxes
to use the rule that comes later */
return -1;
}
if (!uni_utf8_str_is_valid(line)) {
line);
return -1;
}
/* new mailbox. the search args are added to it later. */
line = "INBOX";
case '+':
break;
case '-':
break;
case '!':
/* save messages here */
*error_r = "Multiple save mailboxes defined";
return -1;
}
no_wildcards = TRUE;
break;
}
/* [+-!]/metadata entry:value */
*error_r = "':' separator missing between metadata entry name and value";
return -1;
}
bbox->metadata_value = p;
return -1;
no_wildcards = TRUE;
}
if (!no_wildcards &&
}
/* now that the prefix characters have been processed,
find the namespace */
return -1;
}
*error_r = "Virtual mailbox can't point to itself";
return -1;
}
}
return 0;
}
static void
{
struct mailbox_virtual_pattern pattern;
struct virtual_backend_box *const *bboxes;
unsigned int i, count;
for (i = 0; i < count; i++) {
continue;
if (bboxes[i]->negative_match)
else {
}
}
}
static void
{
struct virtual_backend_box *const *bboxes;
unsigned int i, count;
for (i = 0; i < count;) {
else if (bboxes[i]->negative_match)
else {
i++;
}
&count);
}
}
}
struct virtual_backend_box *wbox,
const char *name)
{
struct virtual_backend_box *bbox;
}
struct mail_namespace *iter_ns)
{
/* we match only one namespace for each pattern, except with shared
namespaces match also autocreated children */
return TRUE;
return TRUE;
config_ns->prefix_len == 0) {
/* prefix="" namespace was autocreated, so e.g. "*" would match
only that empty namespace. but we want "*" to also match
the inbox=yes namespace, so check it here separately. */
return TRUE;
}
return FALSE;
}
unsigned int *idx_r)
{
struct virtual_backend_box *const *boxes;
unsigned int i, count;
for (i = 0; i < count; i++) {
*idx_r = i;
return TRUE;
}
} else {
*idx_r = i;
return TRUE;
}
}
}
return FALSE;
}
struct virtual_backend_box *bbox,
const char **error_r)
{
struct imap_metadata_transaction *imtrans;
struct mail_attribute_value value;
int ret;
if (ret < 0)
if (ret > 0)
return ret;
}
static int
const char **error_r)
{
struct virtual_backend_box *const *boxes;
unsigned int i, count;
int ret = 1;
if (count == 0)
return 1;
for (i = 0; i < count; i++) {
break;
}
mailbox_free(&box);
return ret;
}
const char **error_r)
{
const enum mail_namespace_type iter_ns_types =
const enum mailbox_list_iter_flags iter_flags =
struct mailbox_list_iterate_context *iter;
struct virtual_backend_box *const *wboxes;
const char **patterns;
const struct mailbox_info *info;
unsigned int i, j, count;
int ret = 0;
&neg_boxes, &metadata_boxes);
/* get patterns we want to list */
if (count == 0) {
/* only negative wildcards - doesn't really make sense.
just ignore. */
return 0;
}
for (i = 0; i < count; i++)
/* match listed mailboxes to wildcards */
/* skip non-selectable mailboxes (especially mbox
directories) */
continue;
/* don't allow virtual folder to point to itself */
continue;
}
if (ret < 0)
break;
if (ret > 0) {
}
}
}
for (i = 0; i < count; i++)
if (mailbox_list_iter_deinit(&iter) < 0) {
return -1;
}
return ret < 0 ? -1 : 0;
}
{
struct virtual_backend_box *const *bboxes;
struct mail_search_args *old_args;
unsigned int i, count;
for (i = 0; i < count; i++) {
}
}
{
struct virtual_parse_context ctx;
unsigned int linenum = 0;
if (fd == -1) {
"open(%s) failed: %m", path);
} else {
"stat(%s) failed: %m", box_path);
}
return -1;
}
linenum++;
if (*line == '#')
continue;
if (*line == '\0')
else
if (ret < 0) {
"%s: Error at line %u: %s",
break;
}
}
if (ret == 0) {
if (ret < 0) {
"%s: Error at line %u: %s",
}
}
if (ret < 0)
}
"%s: No mailboxes defined", path);
ret = -1;
}
if (ret == 0)
i_close_fd(&fd);
return ret;
}
{
struct virtual_backend_box *const *bboxes;
unsigned int i, count;
/* mailbox wasn't opened */
return;
}
for (i = 0; i < count; i++) {
}
}