22#define SHOW_ME_VAPPEND_PRINTF
29#include <libcitadel.h>
30#include "../../citadel.h"
31#include "../../sysdep_decls.h"
32#include "../../internet_addressing.h"
35#include "../../ctdl_module.h"
49static void string_init(
struct string* s,
char* buf,
int bufsize)
53 s->
size = strlen(buf);
76#define string_append_s(s, p) string_append_sn((s), (p), -1)
101 UmlChar[0] = 0xC0 | (c >> 6);
102 UmlChar[1] = 0x80 | (c & 0x3F);
105 else if (c <= 0xFFFF)
107 UmlChar[0] = 0xE0 | (c >> 12);
108 UmlChar[1] = 0x80 | ((c >> 6) & 0x3f);
109 UmlChar[2] = 0x80 | (c & 0x3f);
114 UmlChar[0] = 0xf0 | c >> 18;
115 UmlChar[1] = 0x80 | ((c >> 12) & 0x3f);
116 UmlChar[2] = 0x80 | ((c >> 6) & 0x3f);
117 UmlChar[3] = 0x80 | (c & 0x3f);
128 unsigned char* p = (
unsigned char*) *ptr;
149 if ((c & 0xc0) != 0x80)
154 v = (v<<6) | (c & 0x3f);
177 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
180 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
181 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
182 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3E,0x3F,0xFF,0xFF,0xFF,
183 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
184 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
185 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
186 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
187 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
188 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
189 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
190 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
191 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
192 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
193 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
194 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
195 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
206 x = (v << (6-i)) & 0x3F;
215static char*
toimap(
char* destp,
char* destend,
char* src)
232 if (c >= 0x20 && c <= 0x7e)
281 int x = (v >> (i-6)) & 0x3f;
297static char*
fromimap(
char* destp,
char* destend,
const char* src)
300 unsigned const char *p = (
unsigned const char*) src;
352 int x = (v >> (i-16)) & 0xFFFF;
375 case '|':
return '/';
376 case '/':
return '\\';
389 StrBufAppendBufPlain(Buf, Cmd->
Params[i].Key, Cmd->
Params[i].len, 0);
390 if (i < (Cmd->
num_parms-1)) StrBufAppendBufPlain(Buf, HKEY(
" "), 0);
401 if (CutMe->len < n) {
406 CutAt = CutMe->Key + CutMe->len - n;
409 StrBufPeek(Cmd->
CmdBuf, CutAt, -1,
'\0');
416 if (CutMe->len < n) {
417 CutMe->Key += CutMe->len;
434 Params = (ConstStr*)
malloc(
sizeof(ConstStr) * nArgs);
443 sizeof(ConstStr) * nArgs -
450 sizeof(ConstStr) * nArgs);
471 const char *In, *End;
474 End = In + StrLength(Cmd->
CmdBuf);
477 nArgs = StrLength(Cmd->
CmdBuf) / 10 + 10;
508 StrBufPeek(Cmd->
CmdBuf, In, -1,
'\0');
511 else if (*In ==
'\\')
523 else if (*In ==
'\\')
536 StrBufPeek(Cmd->
CmdBuf, In, -1,
'\0');
552 char* bufend = buf+bufsize;
565 pend =
toimap(p, bufend,
"INBOX");
570 p =
toimap(p, bufend,
"INBOX");
610 if (foldername == NULL)
615 fromimap(rbuf, rbuf+bufsize, foldername);
619 if (strncasecmp(rbuf,
"INBOX", 5) == 0)
625 safestrncpy(rbuf,
MAILROOM, bufsize);
629 else if (rbuf[5] ==
FDELIM)
633 safestrncpy(rbuf, rbuf+6, bufsize);
644 levels = num_tokens(rbuf,
FDELIM);
650 len = extract_token(floorname, rbuf, 0,
FDELIM,
sizeof floorname);
651 if (len < 0) len = 0;
652 safestrncpy(roomname, &rbuf[len + 1],
sizeof(roomname));
661 if (strcasecmp(floorname, fl->
f_name) == 0)
665 safestrncpy(rbuf, roomname, bufsize);
679 syslog(LOG_DEBUG,
"(That translates to \"%s\")", rbuf);
699 if (!strcasecmp(buf,
"ALL"))
702 for (i = 0; buf[i]; ++i) {
722#define WILDMAT_TRUE 1
723#define WILDMAT_FALSE 0
724#define WILDMAT_ABORT -1
725#define WILDMAT_DELIM '/'
733 char lcase_text[
SIZ], lcase_p[
SIZ];
741 ((supplied_text[i] !=
'\0') &&
742 (i <
sizeof(lcase_text)));
744 lcase_text[i] = tolower(supplied_text[i]);
745 lcase_text[i] =
'\0';
748 ((supplied_p[i] !=
'\0') &&
749 (i <
sizeof(lcase_p)));
751 lcase_p[i] = tolower(supplied_p[i]);
755 for (p = lcase_p, text = lcase_text;
756 !IsEmptyStr(p) && !IsEmptyStr(text);
758 if ((*text ==
'\0') && (*p !=
'*') && (*p !=
'%')) {
769 while (++p, ((*p ==
'*') || (*p ==
'%'))) {
787 while (++p, (!IsEmptyStr(p) && ((*p ==
'*') || (*p ==
'%'))))
803 while (!IsEmptyStr(text)) {
811 while (!IsEmptyStr(text) &&
824 if ((*text ==
'\0') && (*p ==
'\0'))
return WILDMAT_TRUE;
836 if ((pattern[0] ==
'*') && (pattern[1] ==
'\0')) {
853 int day, month, year;
854 int msgday, msgmonth, msgyear;
857 char *imap_datecmp_ascmonths[12] = {
858 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
861 if (datestr == NULL)
return(0);
864 extract_token(daystr, datestr, 0,
'-',
sizeof daystr);
865 extract_token(monthstr, datestr, 1,
'-',
sizeof monthstr);
866 extract_token(yearstr, datestr, 2,
'-',
sizeof yearstr);
869 year = atoi(yearstr);
871 for (i=0; i<12; ++i) {
872 if (!strcasecmp(monthstr, imap_datecmp_ascmonths[i])) {
878 localtime_r(&msgtime, &msgtm);
879 msgday = msgtm.tm_mday;
880 msgmonth = msgtm.tm_mon;
881 msgyear = msgtm.tm_year + 1900;
885 if (year < msgyear)
return(+1);
886 if (year > msgyear)
return(-1);
888 if (month < msgmonth)
return(+1);
889 if (month > msgmonth)
return(-1);
891 if (day < msgday)
return(+1);
892 if (day > msgday)
return(-1);
902 va_start(arg_ptr, Format);
903 StrBufVAppendPrintf(
IMAP->Reply, Format, arg_ptr);
910 StrBufAppendBufPlain(
IMAP->Reply, Str, Len, 0);
918 StrBufAppendBufPlain(Imap->
Reply,
920 StrBufAppendBufPlain(Imap->
Reply,
922 StrBufAppendBufPlain(Imap->
Reply,
925 StrBufAppendBufPlain(Imap->
Reply,
937 StrBufAppendBufPlain(Imap->
Reply,
940 StrBufAppendBufPlain(Imap->
Reply,
943 va_start(arg_ptr, Format);
944 StrBufVAppendPrintf(
IMAP->Reply, Format, arg_ptr);
947 StrBufAppendBufPlain(Imap->
Reply,
962 if ((Msg == NULL) || (Len == 0))
964 StrBufAppendBufPlain(Imap->
Reply, HKEY(
"NIL"), 0);
968 for (i = 0; i < Len; ++i) {
969 if ((Msg[i] ==
'\"') || (Msg[i] ==
'\\'))
974 StrBufAppendPrintf(Imap->
Reply,
"{%ld}\r\n", Len);
975 StrBufAppendBufPlain(Imap->
Reply, Msg, Len, 0);
977 StrBufAppendBufPlain(Imap->
Reply,
979 StrBufAppendBufPlain(Imap->
Reply,
981 StrBufAppendBufPlain(Imap->
Reply,
991 FlushStrBuf(Imap->
Reply);
struct floor * CtdlGetCachedFloor(int floor_num)
void cputbuf(const StrBuf *Buf)