Back to index

citadel  8.12
Defines | Functions
imap_tools.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define IAPuts(Msg)   iaputs(HKEY(Msg))
#define _iaputs(Msg)   iaputs(Msg, strlen(Msg))
#define IReply(msg)   ireply(HKEY(msg))
#define IPutCStr(_ConstStr)   IPutStr(CKEY(_ConstStr))
#define IPutCParamStr(n)   IPutStr(CKEY(Params[n]))

Functions

void TokenCutRight (citimap_command *Cmd, ConstStr *CutMe, int n)
void TokenCutLeft (citimap_command *Cmd, ConstStr *CutMe, int n)
void MakeStringOf (StrBuf *Buf, int skip)
int CmdAdjust (citimap_command *Cmd, int nArgs, int Realloc)
void imap_strout (ConstStr *args)
void imap_strbuffer (StrBuf *Reply, ConstStr *args)
void plain_imap_strbuffer (StrBuf *Reply, char *buf)
void plain_imap_strout (char *buf)
int imap_parameterize (citimap_command *Cmd)
void imap_mailboxname (char *buf, int bufsize, struct ctdlroom *qrbuf)
void imap_ial_out (struct internet_address_list *ialist)
int imap_roomname (char *buf, int bufsize, const char *foldername)
int imap_is_message_set (const char *)
int imap_mailbox_matches_pattern (const char *pattern, char *mailboxname)
int imap_datecmp (const char *datestr, time_t msgtime)
void IAPrintf (const char *Format,...) __attribute__((__format__(__printf__
void void iaputs (const char *Str, long Len)
void ireply (const char *Msg, long len)
void IReplyPrintf (const char *Format,...)
void IPutStr (const char *Msg, long Len)
void IUnbuffer (void)

Define Documentation

#define _iaputs (   Msg)    iaputs(Msg, strlen(Msg))

Definition at line 43 of file imap_tools.h.

#define IAPuts (   Msg)    iaputs(HKEY(Msg))

Definition at line 41 of file imap_tools.h.

#define IPutCParamStr (   n)    IPutStr(CKEY(Params[n]))

Definition at line 55 of file imap_tools.h.

#define IPutCStr (   _ConstStr)    IPutStr(CKEY(_ConstStr))

Definition at line 54 of file imap_tools.h.

#define IReply (   msg)    ireply(HKEY(msg))

Definition at line 47 of file imap_tools.h.


Function Documentation

int CmdAdjust ( citimap_command Cmd,
int  nArgs,
int  Realloc 
)

Definition at line 436 of file imap_tools.c.

{
       ConstStr *Params;
       if (nArgs > Cmd->avail_parms) {
              Params = (ConstStr*) malloc(sizeof(ConstStr) * nArgs);
              if (Realloc) {
                     memcpy(Params, 
                            Cmd->Params, 
                            sizeof(ConstStr) * Cmd->avail_parms);

                     memset(Cmd->Params + 
                            sizeof(ConstStr) * Cmd->avail_parms,
                            0, 
                            sizeof(ConstStr) * nArgs - 
                            sizeof(ConstStr) * Cmd->avail_parms 
                            );
              }
              else {
                     Cmd->num_parms = 0;
                     memset(Params, 0, 
                            sizeof(ConstStr) * nArgs);
              }
              Cmd->avail_parms = nArgs;
              if (Cmd->Params != NULL)
                     free (Cmd->Params);
              Cmd->Params = Params;
       }
       else {
              if (!Realloc) {
                     memset(Cmd->Params, 
                            0,
                            sizeof(ConstStr) * Cmd->avail_parms);
                     Cmd->num_parms = 0;
              }
       }
       return Cmd->avail_parms;
}

Here is the caller graph for this function:

void IAPrintf ( const char *  Format,
  ... 
)
void void iaputs ( const char *  Str,
long  Len 
)

Definition at line 943 of file imap_tools.c.

{
       StrBufAppendBufPlain(IMAP->Reply, Str, Len, 0);
}

Here is the caller graph for this function:

int imap_datecmp ( const char *  datestr,
time_t  msgtime 
)

Definition at line 881 of file imap_tools.c.

                                                      {
       char daystr[256];
       char monthstr[256];
       char yearstr[256];
       int i;
       int day, month, year;
       int msgday, msgmonth, msgyear;
       struct tm msgtm;

       char *imap_datecmp_ascmonths[12] = {
              "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
       };

       if (datestr == NULL) return(0);

       /* Expecting a date in the form dd-Mmm-yyyy */
       extract_token(daystr, datestr, 0, '-', sizeof daystr);
       extract_token(monthstr, datestr, 1, '-', sizeof monthstr);
       extract_token(yearstr, datestr, 2, '-', sizeof yearstr);

       day = atoi(daystr);
       year = atoi(yearstr);
       month = 0;
       for (i=0; i<12; ++i) {
              if (!strcasecmp(monthstr, imap_datecmp_ascmonths[i])) {
                     month = i;
              }
       }

       /* Extract day/month/year from message timestamp */
       localtime_r(&msgtime, &msgtm);
       msgday = msgtm.tm_mday;
       msgmonth = msgtm.tm_mon;
       msgyear = msgtm.tm_year + 1900;

       /* Now start comparing */

       if (year < msgyear) return(+1);
       if (year > msgyear) return(-1);

       if (month < msgmonth) return(+1);
       if (month > msgmonth) return(-1);

       if (day < msgday) return(+1);
       if (day > msgday) return(-1);

       return(0);
}

Here is the caller graph for this function:

void imap_ial_out ( struct internet_address_list ialist)

Definition at line 691 of file imap_tools.c.

{
       struct internet_address_list *iptr;

       if (ialist == NULL) {
              IAPuts("NIL");
              return;
       }
       IAPuts("(");

       for (iptr = ialist; iptr != NULL; iptr = iptr->next) {
              IAPuts("(");
              plain_imap_strout(iptr->ial_name);
              IAPuts(" NIL ");
              plain_imap_strout(iptr->ial_user);
              IAPuts(" ");
              plain_imap_strout(iptr->ial_node);
              IAPuts(")");
       }

       IAPuts(")");
}

Here is the call graph for this function:

int imap_is_message_set ( const char *  )

Definition at line 722 of file imap_tools.c.

{
       int i;

       if (buf == NULL)
              return (0);   /* stupidity checks */
       if (IsEmptyStr(buf))
              return (0);

       if (!strcasecmp(buf, "ALL"))
              return (1);   /* macro?  why?  */

       for (i = 0; buf[i]; ++i) {  /* now start the scan */
              if (
                        (!isdigit(buf[i]))
                        && (buf[i] != ':')
                        && (buf[i] != ',')
                        && (buf[i] != '*')
                  )
                     return (0);
       }

       return (1);          /* looks like we're good */
}

Here is the caller graph for this function:

int imap_mailbox_matches_pattern ( const char *  pattern,
char *  mailboxname 
)

Definition at line 866 of file imap_tools.c.

{
       /* handle just-star case quickly */
       if ((pattern[0] == '*') && (pattern[1] == '\0')) {
              return WILDMAT_TRUE;
       }
       return (do_imap_match(mailboxname, pattern) == WILDMAT_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void imap_mailboxname ( char *  buf,
int  bufsize,
struct ctdlroom qrbuf 
)

Definition at line 559 of file imap_tools.c.

{
       char* bufend = buf+bufsize;
       struct floor *fl;
       char* p = buf;

       /* For mailboxes, just do it straight.
        * Do the Cyrus-compatible thing: all private folders are
        * subfolders of INBOX. */

       if (qrbuf->QRflags & QR_MAILBOX)
       {
              if (strcasecmp(qrbuf->QRname+11, MAILROOM) == 0)
                     toimap(p, bufend, "INBOX");
              else
              {
                     p = toimap(p, bufend, "INBOX");
                     if (p < bufend)
                            *p++ = '/';
                     toimap(p, bufend, qrbuf->QRname+11);
              }
       }
       else
       {
              /* Otherwise, prefix the floor name as a "public folders" moniker. */

              fl = CtdlGetCachedFloor(qrbuf->QRfloor);
              p = toimap(p, bufend, fl->f_name);
              if (p < bufend)
                     *p++ = '/';
              toimap(p, bufend, qrbuf->QRname);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 476 of file imap_tools.c.

{
       int nArgs;
       const char *In, *End;

       In = ChrPtr(Cmd->CmdBuf);
       End = In + StrLength(Cmd->CmdBuf);

       /* we start with 10 chars per arg, maybe we need to realloc later. */
       nArgs = StrLength(Cmd->CmdBuf) / 10 + 10;
       nArgs = CmdAdjust(Cmd, nArgs, 0);
       while (In < End)
       {
              /* Skip whitespace. */
              while (isspace(*In))
                     In++;
              if (*In == '\0')
                     break;

              /* Found the start of a token. */
              
              Cmd->Params[Cmd->num_parms].Key = In;

              /* Read in the token. */

              for (;;)
              {
                     if (isspace(*In))
                            break;
                     
                     if (*In == '\"')
                     {
                            /* Found a quoted section. */

                            Cmd->Params[Cmd->num_parms].Key++; 
                            //In++;
                            for (;;)
                            {
                                   In++;
                                   if (*In == '\"') {
                                          StrBufPeek(Cmd->CmdBuf, In, -1, '\0');
                                          break;
                                   }
                                   else if (*In == '\\')
                                          In++;

                                   if (*In == '\0') {
                                          Cmd->Params[Cmd->num_parms].len = 
                                                 In - Cmd->Params[Cmd->num_parms].Key;
                                          Cmd->num_parms++;
                                          return Cmd->num_parms;
                                   }
                            }
                            break;
                     }
                     else if (*In == '\\')
                     {
                            In++;
                     }

                     if (*In == '\0') {
                            Cmd->Params[Cmd->num_parms].len = 
                                   In - Cmd->Params[Cmd->num_parms].Key;
                            Cmd->num_parms++;
                            return Cmd->num_parms;
                     }
                     In++;
              }
              StrBufPeek(Cmd->CmdBuf, In, -1, '\0');
              Cmd->Params[Cmd->num_parms].len = 
                     In - Cmd->Params[Cmd->num_parms].Key;
              if (Cmd->num_parms + 1 >= Cmd->avail_parms) {
                     nArgs = CmdAdjust(Cmd, nArgs * 2, 1);
              }
              Cmd->num_parms ++;
              In++;
       }
       return Cmd->num_parms;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int imap_roomname ( char *  buf,
int  bufsize,
const char *  foldername 
)

Definition at line 605 of file imap_tools.c.

{
       struct CitContext *CCC = CC;
       int levels;
       char floorname[ROOMNAMELEN*2];
       char roomname[ROOMNAMELEN];
       int i;
       struct floor *fl;
       int ret = (-1);

       if (foldername == NULL)
              return(-1);

       /* Unmunge the entire string into the output buffer. */

       fromimap(rbuf, rbuf+bufsize, foldername);

       /* Is this an IMAP inbox? */

       if (strncasecmp(rbuf, "INBOX", 5) == 0)
       {
              if (rbuf[5] == 0)
              {
                     /* It's the system inbox. */

                     safestrncpy(rbuf, MAILROOM, bufsize);
                     ret = (0 | IR_MAILBOX);
                     goto exit;
              }
              else if (rbuf[5] == FDELIM)
              {
                     /* It's another personal mail folder. */

                     safestrncpy(rbuf, rbuf+6, bufsize);
                     ret = (0 | IR_MAILBOX);
                     goto exit;
              }

              /* If we get here, the folder just happens to start with INBOX
               * --- fall through. */
       }

       /* Is this a multi-level room name? */

       levels = num_tokens(rbuf, FDELIM);
       if (levels > 1)
       {
              long len;
              /* Extract the main room name. */
              
              len = extract_token(floorname, rbuf, 0, FDELIM, sizeof floorname);
              if (len < 0) len = 0;
              safestrncpy(roomname, &rbuf[len  + 1], sizeof(roomname));

              /* Try and find it on any floor. */
              
              for (i = 0; i < MAXFLOORS; ++i)
              {
                     fl = CtdlGetCachedFloor(i);
                     if (fl->f_flags & F_INUSE)
                     {
                            if (strcasecmp(floorname, fl->f_name) == 0)
                            {
                                   /* Got it! */

                                   safestrncpy(rbuf, roomname, bufsize);
                                   ret = i;
                                   goto exit;
                            }
                     }
              }
       }

       /* Meh. It's either not a multi-level room name, or else we
        * couldn't find it.
        */
       ret = (0 | IR_MAILBOX);

exit:
       IMAP_syslog(LOG_DEBUG, "(That translates to \"%s\")", rbuf);
       return(ret);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void imap_strbuffer ( StrBuf *  Reply,
ConstStr *  args 
)
void imap_strout ( ConstStr *  args)
void IPutStr ( const char *  Msg,
long  Len 
)

Definition at line 1026 of file imap_tools.c.

{
       int i;
       int is_literal = 0;
       citimap *Imap = IMAP;

       
       if ((Msg == NULL) || (Len == 0))
       {      /* yeah, we handle this */
              StrBufAppendBufPlain(Imap->Reply, HKEY("NIL"), 0);
              return;
       }

       for (i = 0; i < Len; ++i) {
              if ((Msg[i] == '\"') || (Msg[i] == '\\'))
                     is_literal = 1;
       }

       if (is_literal) {
              StrBufAppendPrintf(Imap->Reply, "{%ld}\r\n", Len);
              StrBufAppendBufPlain(Imap->Reply, Msg, Len, 0);
       } else {
              StrBufAppendBufPlain(Imap->Reply, 
                                 HKEY("\""), 0);
              StrBufAppendBufPlain(Imap->Reply, 
                                 Msg, Len, 0);
              StrBufAppendBufPlain(Imap->Reply, 
                                 HKEY("\""), 0);
       }
}

Here is the caller graph for this function:

void ireply ( const char *  Msg,
long  len 
)

Definition at line 948 of file imap_tools.c.

{
       citimap *Imap = IMAP;

       StrBufAppendBufPlain(Imap->Reply, 
                          CKEY(Imap->Cmd.Params[0]), 0);
       StrBufAppendBufPlain(Imap->Reply, 
                          HKEY(" "), 0);
       StrBufAppendBufPlain(Imap->Reply, 
                          Msg, len, 0);
       
       StrBufAppendBufPlain(Imap->Reply, 
                          HKEY("\r\n"), 0);
       
}
void IReplyPrintf ( const char *  Format,
  ... 
)

Definition at line 964 of file imap_tools.c.

{
       citimap *Imap = IMAP;
       va_list arg_ptr;
       

       StrBufAppendBufPlain(Imap->Reply, 
                          CKEY(Imap->Cmd.Params[0]), 0);

       StrBufAppendBufPlain(Imap->Reply, 
                          HKEY(" "), 0);

       va_start(arg_ptr, Format);
       StrBufVAppendPrintf(IMAP->Reply, Format, arg_ptr);
       va_end(arg_ptr);
       
       StrBufAppendBufPlain(Imap->Reply, 
                          HKEY("\r\n"), 0);
       
}

Here is the caller graph for this function:

void IUnbuffer ( void  )

Definition at line 1057 of file imap_tools.c.

{
       citimap *Imap = IMAP;

       cputbuf(Imap->Reply);
       FlushStrBuf(Imap->Reply);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void MakeStringOf ( StrBuf *  Buf,
int  skip 
)

Definition at line 391 of file imap_tools.c.

{
       int i;
       citimap_command *Cmd = &IMAP->Cmd;

       for (i=skip; i<Cmd->num_parms; ++i) {
              StrBufAppendBufPlain(Buf, Cmd->Params[i].Key, Cmd->Params[i].len, 0);
              if (i < (Cmd->num_parms-1)) StrBufAppendBufPlain(Buf, HKEY(" "), 0);
       }
}

Here is the caller graph for this function:

void plain_imap_strbuffer ( StrBuf *  Reply,
char *  buf 
)
void plain_imap_strout ( char *  buf)

Definition at line 990 of file imap_tools.c.

{
       int i;
       int is_literal = 0;
       long Len;
       citimap *Imap = IMAP;

       if (buf == NULL) {   /* yeah, we handle this */
              IAPuts("NIL");
              return;
       }

       Len = strlen(buf);
       for (i = 0; i < Len; ++i) {
              if ((buf[i] == '\"') || (buf[i] == '\\'))
                     is_literal = 1;
       }

       if (is_literal) {
              StrBufAppendPrintf(Imap->Reply, "{%ld}\r\n", Len);
              StrBufAppendBufPlain(Imap->Reply, buf, Len, 0);
       } else {
              StrBufAppendBufPlain(Imap->Reply, 
                                 HKEY("\""), 0);
              StrBufAppendBufPlain(Imap->Reply, 
                                 buf, Len, 0);
              StrBufAppendBufPlain(Imap->Reply, 
                                 HKEY("\""), 0);
       }
}

Here is the caller graph for this function:

void TokenCutLeft ( citimap_command Cmd,
ConstStr *  CutMe,
int  n 
)

Definition at line 420 of file imap_tools.c.

{
       if (CutMe->len < n) {
              CutMe->Key += CutMe->len;
              CutMe->len = 0;
       }
       else {
              CutMe->Key += n;
              CutMe->len -= n;
       }
}

Here is the caller graph for this function:

void TokenCutRight ( citimap_command Cmd,
ConstStr *  CutMe,
int  n 
)

Definition at line 403 of file imap_tools.c.

{
       const char *CutAt;

       if (CutMe->len < n) {
              CutAt = CutMe->Key;
              CutMe->len = 0;
       }
       else {
              CutAt = CutMe->Key + CutMe->len - n;
              CutMe->len -= n;
       }
       StrBufPeek(Cmd->CmdBuf, CutAt, -1, '\0');
}

Here is the caller graph for this function: