Back to index

courier  0.68.2
Functions
searchinfo.c File Reference
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "unicode/unicode.h"
#include "searchinfo.h"
#include "imapwrite.h"
#include "imaptoken.h"

Go to the source code of this file.

Functions

struct searchinfoalloc_search (struct searchinfo **head)
void free_search (struct searchinfo *si)
static struct searchinfoalloc_search_andlist (struct searchinfo **)
static struct searchinfoalloc_search_notkey (struct searchinfo **)
static struct searchinfoalloc_search_key (struct searchinfo **)
struct searchinfoalloc_parsesearch (struct searchinfo **head)
struct searchinfoalloc_searchextra (struct searchinfo *top, struct searchinfo **head, search_type t)
void search_set_charset_conv (struct searchinfo *si, const char *charset)

Function Documentation

struct searchinfo* alloc_parsesearch ( struct searchinfo **  head) [read]

Definition at line 54 of file searchinfo.c.

{
struct searchinfo *si;

       *head=0;
       if ((si=alloc_search_andlist(head)) == 0)
       {
              free_search(*head);
              return (0);
       }
       return (si);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct searchinfo* alloc_search ( struct searchinfo **  head) [read]

Definition at line 20 of file searchinfo.c.

{
struct searchinfo *si=(struct searchinfo *)malloc(sizeof(**head));

       if (si == 0)  write_error_exit(0);
       memset(si, 0, sizeof(*si));
       maildir_search_init(&si->sei);
       si->next= *head;
       *head=si;
       return (si);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct searchinfo * alloc_search_andlist ( struct searchinfo **  head) [static, read]

Definition at line 86 of file searchinfo.c.

{
struct searchinfo *si, *a, *b;
struct imaptoken *t;

       si=alloc_search_notkey(head);
       if (!si)      return (0);
       while ((t=currenttoken())->tokentype != IT_RPAREN && t->tokentype !=
              IT_EOL)
       {
              if ((a=alloc_search_notkey(head)) == 0)   return (0);
              b=alloc_search(head);
              b->type=search_and;
              b->a=si;
              b->b=a;
              si=b;
       }
       return (si);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct searchinfo * alloc_search_key ( struct searchinfo **  head) [static, read]

Definition at line 123 of file searchinfo.c.

{
struct imaptoken *t=currenttoken();
struct searchinfo *si;
const char *keyword;

       if (t->tokentype == IT_LPAREN)
       {
              nexttoken();
              if ((si=alloc_search_andlist(head)) == 0 ||
                     currenttoken()->tokentype != IT_RPAREN)
                     return (0);
              nexttoken();
              return (si);
       }

       if (t->tokentype != IT_ATOM && t->tokentype != IT_NUMBER)
              return (0);

       keyword=t->tokenbuf;

       if (strcmp(keyword, "ALL") == 0)
       {
       struct searchinfo *si;

              (si=alloc_search(head))->type=search_all;
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "OR") == 0)
       {
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_or;
              nexttoken();
              if ((si->a=alloc_search_notkey(head)) == 0 ||
                     (si->b=alloc_search_notkey(head)) == 0)   return (0);
              return (si);
       }

       if (strcmp(keyword, "HEADER") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_header;
              t=nexttoken_okbracket();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->cs=strdup(t->tokenbuf);
              if (!si->cs)
                     write_error_exit(0);
              t=nexttoken_okbracket();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "BCC") == 0 ||
              strcmp(keyword, "CC") == 0 ||
              strcmp(keyword, "FROM") == 0 ||
              strcmp(keyword, "TO") == 0 ||
              strcmp(keyword, "SUBJECT") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_header;
              si->cs=my_strdup(keyword);
              t=nexttoken_okbracket();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "BEFORE") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_before;
              t=nexttoken();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "BODY") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_body;
              t=nexttoken_okbracket();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }
       if (strcmp(keyword, "LARGER") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_larger;
              t=nexttoken();
              if (t->tokentype != IT_NUMBER)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "ON") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_on;
              t=nexttoken();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "SENTBEFORE") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_sentbefore;
              t=nexttoken();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "SENTON") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_senton;
              t=nexttoken();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(keyword);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "SENTSINCE") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_sentsince;
              t=nexttoken();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "SINCE") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_since;
              t=nexttoken();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "SMALLER") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_smaller;
              t=nexttoken();
              if (t->tokentype != IT_NUMBER)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "TEXT") == 0)
       {
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_text;
              t=nexttoken_okbracket();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "UID") == 0)
       {
       struct searchinfo *si;
       struct imaptoken *t;

              si=alloc_search(head);
              si->type=search_uid;
              t=nexttoken();
              if (!ismsgset(t))
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "KEYWORD") == 0
              || strcmp(keyword, "UNKEYWORD") == 0)
       {
       int    isnot= *keyword == 'U';
       struct imaptoken *t;
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_msgkeyword;
              t=nexttoken_okbracket();
              if (t->tokentype != IT_ATOM &&
                  t->tokentype != IT_NUMBER &&
                  t->tokentype != IT_QUOTED_STRING)
                     return (0);
              si->as=my_strdup(t->tokenbuf);
              nexttoken();

              if (isnot)
              {
              struct searchinfo *si2=alloc_search(head);

                     si2->type=search_not;
                     si2->a=si;
                     si=si2;
              }
              return (si);
       }
       if (strcmp(keyword, "ANSWERED") == 0 ||
              strcmp(keyword, "DELETED") == 0 ||
              strcmp(keyword, "DRAFT") == 0 ||
              strcmp(keyword, "FLAGGED") == 0 ||
              strcmp(keyword, "RECENT") == 0 ||
              strcmp(keyword, "SEEN") == 0)
       {
       struct searchinfo *si;

              si=alloc_search(head);
              si->type=search_msgflag;
              if ((si->as=malloc(strlen(keyword)+2)) == 0)
                     write_error_exit(0);
              si->as[0]='\\';
              strcpy(si->as+1, keyword);
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "UNANSWERED") == 0 ||
              strcmp(keyword, "UNDELETED") == 0 ||
              strcmp(keyword, "UNDRAFT") == 0 ||
              strcmp(keyword, "UNFLAGGED") == 0 ||
              strcmp(keyword, "UNSEEN") == 0)
       {
       struct searchinfo *si;
       struct searchinfo *si2;

              si=alloc_search(head);
              si->type=search_msgflag;
              if ((si->as=malloc(strlen(keyword))) == 0)
                     write_error_exit(0);
              si->as[0]='\\';
              strcpy(si->as+1, keyword+2);
              nexttoken();

              si2=alloc_search(head);
              si2->type=search_not;
              si2->a=si;
              return (si2);
       }

       if (strcmp(keyword, "NEW") == 0)
       {
       struct searchinfo *si, *si2;

              si=alloc_search(head);
              si->type=search_and;
              si2=si->a=alloc_search(head);
              si2->type=search_msgflag;
              si2->as=my_strdup("\\RECENT");
              si2=si->b=alloc_search(head);
              si2->type=search_not;
              si2=si2->a=alloc_search(head);
              si2->type=search_msgflag;
              si2->as=my_strdup("\\SEEN");
              nexttoken();
              return (si);
       }

       if (strcmp(keyword, "OLD") == 0)
       {
       struct searchinfo *si, *si2;

              si=alloc_search(head);
              si->type=search_not;
              si2=si->a=alloc_search(head);
              si2->type=search_msgflag;
              si2->as=my_strdup("\\RECENT");
              nexttoken();
              return (si);
       }

       if (ismsgset(t))
       {
              si=alloc_search(head);
              si->type=search_messageset;
              si->as=my_strdup(t->tokenbuf);
              nexttoken();
              return (si);
       }

       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct searchinfo * alloc_search_notkey ( struct searchinfo **  head) [static, read]

Definition at line 106 of file searchinfo.c.

{
struct imaptoken *t=currenttoken();

       if (t->tokentype == IT_ATOM && strcmp(t->tokenbuf, "NOT") == 0)
       {
       struct searchinfo *si=alloc_search(head);

              si->type=search_not;
              nexttoken();
              if ((si->a=alloc_search_key(head)) == 0)
                     return (0);
              return (si);
       }
       return (alloc_search_key(head));
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct searchinfo* alloc_searchextra ( struct searchinfo top,
struct searchinfo **  head,
search_type  t 
) [read]

Definition at line 67 of file searchinfo.c.

{
       struct searchinfo *si;

       if (t == search_references1)
       {
              /* Automatically add third and second dummy node */

              top=alloc_searchextra(top, head, search_references4);
              top=alloc_searchextra(top, head, search_references3);
              top=alloc_searchextra(top, head, search_references2);
       }
       si=alloc_search(head);
       si->type=t;
       si->a=top;
       return (si);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void free_search ( struct searchinfo si)

Definition at line 32 of file searchinfo.c.

{
struct searchinfo *p;

       while (si)
       {
              p=si->next;
              if (si->as)   free(si->as);
              if (si->bs)   free(si->bs);
              if (si->cs)   free(si->cs);

              maildir_search_destroy(&si->sei);

              free(si);
              si=p;
       }
}

Here is the caller graph for this function:

void search_set_charset_conv ( struct searchinfo si,
const char *  charset 
)

Definition at line 509 of file searchinfo.c.

{
       for (; si; si=si->next)
       {
              if (si->type != search_text && si->type != search_body
                  && si->type != search_header)
                     continue;
              if (si->value > 0)
                     continue; /* Already found, no need to do this again */

              if (maildir_search_start_str_chset(&si->sei,
                                             si->as ? si->as:"",
                                             charset))
              {
                     si->value=0;
                     continue;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function: