imap-search.c revision 1091d5be391af806f7cf553521f6778f830f9500
/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "mail-storage.h"
#include "mail-search.h"
#include "imap-date.h"
#include "imap-search.h"
#include "imap-parser.h"
#include "imap-messageset.h"
#include <stdlib.h>
struct search_build_data {
const char *error;
};
static int
{
struct mail_search_seqset *seqset, **p;
bool last;
*error_r = "Invalid UID messageset";
return -1;
}
p = seqset_r;
/* last message, stays same */
continue;
}
/* we need special case for too_high_uid:* case */
}
else
}
return 0;
}
static struct mail_search_arg *
{
struct mail_search_arg *arg;
return arg;
}
static bool
const char **value_r)
{
return FALSE;
}
return FALSE;
}
*args += 1;
return TRUE;
}
#define ARG_NEW_SINGLE(type) \
static bool
struct mail_search_arg **next_sarg,
enum mail_search_arg_type type)
{
return TRUE;
}
#define ARG_NEW_STR(type) \
static bool
enum mail_search_arg_type type)
{
struct mail_search_arg *sarg;
const char *value;
return FALSE;
return TRUE;
}
#define ARG_NEW_FLAGS(flags) \
static bool
{
struct mail_search_arg *sarg;
return TRUE;
}
static bool
struct mail_search_arg **next_sarg)
{
struct mail_search_arg *sarg;
struct mail_storage *storage;
enum mail_error error;
return FALSE;
return FALSE;
}
return TRUE;
}
#define ARG_NEW_SIZE(type) \
static bool
enum mail_search_arg_type type)
{
struct mail_search_arg *sarg;
const char *value;
char *p;
return FALSE;
if (*p != '\0') {
return FALSE;
}
return TRUE;
}
#define ARG_NEW_DATE(type) \
static bool
enum mail_search_arg_type type)
{
struct mail_search_arg *sarg;
const char *value;
return FALSE;
return FALSE;
}
return TRUE;
}
static bool
{
struct mail_search_arg *sarg;
const char *value;
return FALSE;
return TRUE;
}
struct mail_search_arg **next_sarg)
{
struct mail_search_seqset *seqset;
struct mail_search_arg **subargs;
const char *str;
return FALSE;
}
/* NIL not allowed */
return FALSE;
}
return FALSE;
}
return FALSE;
}
*args += 1;
return TRUE;
}
/* string argument - get the name and jump to next */
*args += 1;
switch (*str) {
case 'A':
return ARG_NEW_FLAGS(MAIL_ANSWERED);
return ARG_NEW_SINGLE(SEARCH_ALL);
break;
case 'B':
/* <string> */
*args += 1;
return ARG_NEW_SINGLE(SEARCH_ALL);
}
return ARG_NEW_STR(SEARCH_BODY);
/* <date> */
return ARG_NEW_DATE(SEARCH_BEFORE);
/* <string> */
}
break;
case 'C':
/* <string> */
}
break;
case 'D':
return ARG_NEW_FLAGS(MAIL_DELETED);
return ARG_NEW_FLAGS(MAIL_DRAFT);
break;
case 'F':
return ARG_NEW_FLAGS(MAIL_FLAGGED);
/* <string> */
}
break;
case 'H':
/* <field-name> <string> */
const char *key;
return FALSE;
}
return FALSE;
}
*args += 1;
}
break;
case 'K':
/* <flag> */
}
break;
case 'L':
/* <n> */
return ARG_NEW_SIZE(SEARCH_LARGER);
}
break;
case 'N':
return FALSE;
return TRUE;
/* NEW == (RECENT UNSEEN) */
return TRUE;
}
break;
case 'O':
/* <search-key1> <search-key2> */
for (;;) {
return FALSE;
/* <key> OR <key> OR ... <key> - put them all
under one SEARCH_OR list. */
break;
"OR") != 0)
break;
*args += 1;
}
return FALSE;
return TRUE;
/* <date> */
return ARG_NEW_DATE(SEARCH_ON);
/* OLD == NOT RECENT */
if (!ARG_NEW_FLAGS(MAIL_RECENT))
return FALSE;
return TRUE;
}
break;
case 'R':
return ARG_NEW_FLAGS(MAIL_RECENT);
break;
case 'S':
return ARG_NEW_FLAGS(MAIL_SEEN);
/* <string> */
/* <date> */
return ARG_NEW_DATE(SEARCH_SENTBEFORE);
/* <date> */
return ARG_NEW_DATE(SEARCH_SENTON);
/* <date> */
return ARG_NEW_DATE(SEARCH_SENTSINCE);
/* <date> */
return ARG_NEW_DATE(SEARCH_SINCE);
/* <n> */
return ARG_NEW_SIZE(SEARCH_SMALLER);
}
break;
case 'T':
/* <string> */
*args += 1;
return ARG_NEW_SINGLE(SEARCH_ALL);
}
return ARG_NEW_STR(SEARCH_TEXT);
/* <string> */
}
break;
case 'U':
/* <message set> */
if (!ARG_NEW_STR(SEARCH_SEQSET))
return FALSE;
if (!ARG_NEW_FLAGS(MAIL_ANSWERED))
return FALSE;
return TRUE;
if (!ARG_NEW_FLAGS(MAIL_DELETED))
return FALSE;
return TRUE;
if (!ARG_NEW_FLAGS(MAIL_DRAFT))
return FALSE;
return TRUE;
if (!ARG_NEW_FLAGS(MAIL_FLAGGED))
return FALSE;
return TRUE;
/* <flag> */
return FALSE;
return TRUE;
if (!ARG_NEW_FLAGS(MAIL_SEEN))
return FALSE;
return TRUE;
}
break;
case 'X':
/* <string> */
*args += 1;
return ARG_NEW_SINGLE(SEARCH_ALL);
}
return ARG_NEW_STR(SEARCH_BODY_FAST);
/* <string> */
*args += 1;
return ARG_NEW_SINGLE(SEARCH_ALL);
}
return ARG_NEW_STR(SEARCH_TEXT_FAST);
}
break;
default:
/* <message-set> */
return FALSE;
}
if (!ARG_NEW_SINGLE(SEARCH_SEQSET))
return FALSE;
return TRUE;
}
break;
}
return FALSE;
}
struct mail_search_arg *
{
struct search_build_data data;
/* get the first arg */
return NULL;
}
}
return first_sarg;
}
static bool
{
/* when there are no messages, all messagesets are invalid.
if there's at least one message:
- * gives seq1 = seq2 = (uint32_t)-1
- n:* should work if n <= messages_count
- n:m or m should work if m <= messages_count
*/
return FALSE;
return FALSE;
}
return TRUE;
}
const char *messageset,
struct mail_search_arg **arg_r,
const char **error_r)
{
struct mail_search_arg *arg;
*error_r = "Invalid messageset";
return -1;
}
return 0;
}
{
}
}
static int
{
struct mail_search_arg *arg;
error_r);
}
struct mail_search_arg *
{
const char *error;
int ret;
if (!uid) {
} else {
&search_arg, &error);
}
if (ret < 0) {
return NULL;
}
return search_arg;
}