imap-match.c revision 19e8adccba16ff419f5675b1575358c2956dce83
/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
/* imap_match_init() logic originates from Cyrus, but the code is fully
rewritten. */
#include "lib.h"
#include "imap-match.h"
#include <ctype.h>
struct imap_match_pattern {
const char *pattern;
bool inboxcase;
};
struct imap_match_glob {
struct imap_match_pattern *patterns;
char sep;
char patterns_data[];
};
struct imap_match_context {
const char *inboxcase_end;
char sep;
bool inboxcase;
};
/* name of "INBOX" - must not have repeated substrings */
static const char inbox[] = "INBOX";
struct imap_match_glob *
{
const char *patterns[2];
}
static const char *pattern_compress(const char *pattern)
{
/* @UNSAFE: compress the pattern */
while (*pattern != '\0') {
/* remove duplicate hierarchy wildcards */
/* "%*" -> "*" */
if (*pattern == '*') {
/* remove duplicate wildcards */
pattern++;
*dest++ = '*';
} else {
*dest++ = '%';
}
} else {
}
}
*dest++ = '\0';
return ret;
}
{
/* skip over exact matches */
inboxp++; p++;
}
if (*p != '%') {
return *p == '*' || *p == separator ||
}
/* handle 'I%B%X' style checks */
if (*p != '%') {
return FALSE;
if (*++inboxp == '\0') {
/* now check that it doesn't end with
any invalid chars */
if (*++p == '%') p++;
if (*p != '\0' && *p != '*' &&
*p != separator)
return FALSE;
break;
}
}
}
return TRUE;
}
static struct imap_match_glob *
{
struct imap_match_glob *glob;
struct imap_match_pattern *match_patterns;
patterns_count + 1);
/* compress the patterns */
for (i = 0; i < patterns_count; i++) {
}
patterns_count = i;
/* now we know how much memory we need */
/* copy pattern strings to our allocated memory */
for (i = 0, pos = 0; i < patterns_count; i++) {
/* @UNSAFE */
}
return glob;
}
struct imap_match_glob *
{
struct imap_match_glob *glob;
if (pool->datastack_pool) {
}
T_BEGIN {
} T_END;
return glob;
}
{
}
static enum imap_match_result
const char **pattern_p)
{
/* match all non-wildcards */
}
}
while (*pattern == '%') {
pattern++;
if (*pattern == '\0') {
/* match, if this is the last hierarchy */
data++;
break;
}
/* skip over this hierarchy */
while (*data != '\0') {
if (ret == IMAP_MATCH_YES)
break;
}
break;
data++;
}
}
if (*pattern != '*') {
return match;
}
if (*data != '\0') {
return match;
}
}
return IMAP_MATCH_YES;
}
static enum imap_match_result
{
/* data begins with INBOX/, use case-insensitive comparison
for it */
}
if (*pattern != '*') {
/* handle the pattern up to the first '*' */
return ret;
}
while (*pattern == '*') {
pattern++;
if (*pattern == '\0')
return IMAP_MATCH_YES;
while (*data != '\0') {
if (ret == IMAP_MATCH_YES)
break;
}
data++;
}
}
}
enum imap_match_result
{
struct imap_match_context ctx;
unsigned int i;
if (ret == IMAP_MATCH_YES)
return IMAP_MATCH_YES;
}
return match;
}