fixed a bug in imap parser

This commit is contained in:
SJ 2013-01-10 22:30:30 +01:00
parent 78259c85ef
commit d7792ee9f3
3 changed files with 27 additions and 21 deletions

View File

@ -13,7 +13,7 @@
#define VERSION "0.1.23-master-branch"
#define BUILD 749
#define BUILD 751
#define HOSTID "mailarchiver"

View File

@ -93,7 +93,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
p = strstr(buf, " EXISTS");
if(p){
*p = '\0';
p = strrchr(buf, '\n');
p = strrchr(buf, ' ');
if(p){
while(!isdigit(*p)){ p++; }
messages = atoi(p);
@ -286,15 +286,27 @@ void close_connection(int sd, struct __data *data, int use_ssl){
int list_folders(int sd, int *seq, char *folders, int foldersize, int use_ssl, struct __data *data){
char *p, *q, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], buf[MAXBUFSIZE], puf[MAXBUFSIZE];
char *p, *q, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], buf[3*MAXBUFSIZE+3], puf[MAXBUFSIZE];
int len=0, n;
memset(buf, 0, sizeof(buf));
snprintf(tag, sizeof(tag)-1, "A%d", *seq); snprintf(tagok, sizeof(tagok)-1, "A%d OK", (*seq)++);
//snprintf(buf, sizeof(buf)-1, "%s LIST \"\" %%\r\n", tag);
snprintf(buf, sizeof(buf)-1, "%s LIST \"\" \"*\"\r\n", tag);
//snprintf(puf, sizeof(puf)-1, "%s LIST \"\" %%\r\n", tag);
snprintf(puf, sizeof(puf)-1, "%s LIST \"\" \"*\"\r\n", tag);
write1(sd, buf, use_ssl, data->ssl);
write1(sd, puf, use_ssl, data->ssl);
recvtimeoutssl(sd, buf, sizeof(buf), 10, use_ssl, data->ssl);
while(1){
n = recvtimeoutssl(sd, puf, sizeof(puf), 10, use_ssl, data->ssl);
if(len + n < sizeof(buf)){
memcpy(&buf[len], puf, n);
len += n;
}
else break;
if(strstr(buf, tagok)) break;
}
p = &buf[0];
do {
@ -303,9 +315,10 @@ int list_folders(int sd, int *seq, char *folders, int foldersize, int use_ssl, s
trimBuffer(puf);
if(strncmp(puf, "* LIST ", 7) == 0){
q = strstr(puf, "\".\"");
q = strstr(puf, ") \"");
if(q){
q += 3;
q += 5;
if(*q == ' ') q++;
if(*q == '"') q++;

View File

@ -21,7 +21,7 @@
#include <piler.h>
#define SKIPLIST "junk,trash,spam,draft"
#define SKIPLIST "junk,trash,spam,draft,"
#define MBOX_ARGS 1024
extern char *optarg;
@ -243,7 +243,7 @@ int import_from_maildir(char *directory, struct session_data *sdata, struct __da
int import_from_imap_server(char *server, char *username, char *password, int port, struct session_data *sdata, struct __data *data, char *skiplist, struct __config *cfg){
int rc=ERR, ret=OK, sd, seq=1, skipmatch, use_ssl=0;
char *p, puf[SMALLBUFSIZE];
char *q, muf[SMALLBUFSIZE];
char muf[SMALLBUFSIZE];
char folders[MAXBUFSIZE];
@ -274,15 +274,8 @@ int import_from_imap_server(char *server, char *username, char *password, int po
skipmatch = 0;
if(skiplist && strlen(skiplist) > 0){
q = skiplist;
do {
memset(muf, 0, sizeof(muf));
q = split(q, ',', muf, sizeof(muf)-1);
if(strncasecmp(puf, muf, strlen(muf)) == 0){
skipmatch = 1;
break;
}
} while(q);
snprintf(muf, sizeof(muf)-1, "%s,", puf);
if(strstr(skiplist, muf)) skipmatch = 1;
}
if(skipmatch == 1){