imap-search.c revision 42840ceb1e28a5a42d90d43a83cc9be9f498454f
/* Copyright (C) 2002 Timo Sirainen */
#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"
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;
}
enum mail_error error;
return -1;
}
/* we need special case for too_high_uid:* case */
}
else
}
return 0;
}
static struct mail_search_arg *
{
struct mail_search_arg *arg;
return arg;
}
#define ARG_NEW_FLAG(type) \
struct mail_search_arg **next_sarg,
const char *hdr_name)
{
struct mail_search_arg *sarg;
if (!have_value)
return TRUE;
return FALSE;
}
return FALSE;
}
switch (type) {
case SEARCH_BEFORE:
case SEARCH_ON:
case SEARCH_SINCE:
case SEARCH_SENTBEFORE:
case SEARCH_SENTON:
case SEARCH_SENTSINCE:
return FALSE;
}
default:
break;
}
*args += 1;
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_FLAG(SEARCH_ANSWERED);
return ARG_NEW_FLAG(SEARCH_ALL);
break;
case 'B':
/* <string> */
return ARG_NEW(SEARCH_BODY);
/* <date> */
return ARG_NEW(SEARCH_BEFORE);
/* <string> */
}
break;
case 'C':
/* <string> */
}
break;
case 'D':
return ARG_NEW_FLAG(SEARCH_DELETED);
return ARG_NEW_FLAG(SEARCH_DRAFT);
break;
case 'F':
return ARG_NEW_FLAG(SEARCH_FLAGGED);
/* <string> */
}
break;
case 'H':
/* <field-name> <string> */
const char *key;
return FALSE;
}
return FALSE;
}
*args += 1;
}
break;
case 'K':
/* <flag> */
return ARG_NEW(SEARCH_KEYWORD);
}
break;
case 'L':
/* <n> */
return ARG_NEW(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> */
/* OLD == NOT RECENT */
if (!ARG_NEW_FLAG(SEARCH_RECENT))
return FALSE;
return TRUE;
}
break;
case 'R':
return ARG_NEW_FLAG(SEARCH_RECENT);
break;
case 'S':
return ARG_NEW_FLAG(SEARCH_SEEN);
/* <string> */
/* <date> */
return ARG_NEW(SEARCH_SENTBEFORE);
/* <date> */
return ARG_NEW(SEARCH_SENTON);
/* <date> */
return ARG_NEW(SEARCH_SENTSINCE);
/* <date> */
return ARG_NEW(SEARCH_SINCE);
/* <n> */
return ARG_NEW(SEARCH_SMALLER);
}
break;
case 'T':
/* <string> */
return ARG_NEW(SEARCH_TEXT);
/* <string> */
}
break;
case 'U':
/* <message set> */
if (!ARG_NEW(SEARCH_SEQSET))
return FALSE;
if (!ARG_NEW_FLAG(SEARCH_ANSWERED))
return FALSE;
return TRUE;
if (!ARG_NEW_FLAG(SEARCH_DELETED))
return FALSE;
return TRUE;
if (!ARG_NEW_FLAG(SEARCH_DRAFT))
return FALSE;
return TRUE;
if (!ARG_NEW_FLAG(SEARCH_FLAGGED))
return FALSE;
return TRUE;
/* <flag> */
if (!ARG_NEW(SEARCH_KEYWORD))
return FALSE;
return TRUE;
if (!ARG_NEW_FLAG(SEARCH_SEEN))
return FALSE;
return TRUE;
}
break;
case 'X':
/* <string> */
return ARG_NEW(SEARCH_BODY_FAST);
/* <string> */
return ARG_NEW(SEARCH_TEXT_FAST);
}
break;
default:
/* <message-set> */
return FALSE;
}
if (!ARG_NEW_FLAG(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;
}
const char *messageset,
struct mail_search_arg **arg_r,
const char **error_r)
{
struct mail_search_arg *arg;
/* 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
*/
*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;
}