mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-01-12 13:50:12 +01:00
fixed a bug in imap parser
This commit is contained in:
parent
78259c85ef
commit
d7792ee9f3
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#define VERSION "0.1.23-master-branch"
|
#define VERSION "0.1.23-master-branch"
|
||||||
|
|
||||||
#define BUILD 749
|
#define BUILD 751
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
29
src/imap.c
29
src/imap.c
@ -93,7 +93,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda
|
|||||||
p = strstr(buf, " EXISTS");
|
p = strstr(buf, " EXISTS");
|
||||||
if(p){
|
if(p){
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
p = strrchr(buf, '\n');
|
p = strrchr(buf, ' ');
|
||||||
if(p){
|
if(p){
|
||||||
while(!isdigit(*p)){ p++; }
|
while(!isdigit(*p)){ p++; }
|
||||||
messages = atoi(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){
|
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(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(puf, sizeof(puf)-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);
|
||||||
|
|
||||||
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];
|
p = &buf[0];
|
||||||
do {
|
do {
|
||||||
@ -303,9 +315,10 @@ int list_folders(int sd, int *seq, char *folders, int foldersize, int use_ssl, s
|
|||||||
trimBuffer(puf);
|
trimBuffer(puf);
|
||||||
|
|
||||||
if(strncmp(puf, "* LIST ", 7) == 0){
|
if(strncmp(puf, "* LIST ", 7) == 0){
|
||||||
q = strstr(puf, "\".\"");
|
|
||||||
|
q = strstr(puf, ") \"");
|
||||||
if(q){
|
if(q){
|
||||||
q += 3;
|
q += 5;
|
||||||
|
|
||||||
if(*q == ' ') q++;
|
if(*q == ' ') q++;
|
||||||
if(*q == '"') q++;
|
if(*q == '"') q++;
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <piler.h>
|
#include <piler.h>
|
||||||
|
|
||||||
|
|
||||||
#define SKIPLIST "junk,trash,spam,draft"
|
#define SKIPLIST "junk,trash,spam,draft,"
|
||||||
#define MBOX_ARGS 1024
|
#define MBOX_ARGS 1024
|
||||||
|
|
||||||
extern char *optarg;
|
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 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;
|
int rc=ERR, ret=OK, sd, seq=1, skipmatch, use_ssl=0;
|
||||||
char *p, puf[SMALLBUFSIZE];
|
char *p, puf[SMALLBUFSIZE];
|
||||||
char *q, muf[SMALLBUFSIZE];
|
char muf[SMALLBUFSIZE];
|
||||||
char folders[MAXBUFSIZE];
|
char folders[MAXBUFSIZE];
|
||||||
|
|
||||||
|
|
||||||
@ -274,15 +274,8 @@ int import_from_imap_server(char *server, char *username, char *password, int po
|
|||||||
skipmatch = 0;
|
skipmatch = 0;
|
||||||
|
|
||||||
if(skiplist && strlen(skiplist) > 0){
|
if(skiplist && strlen(skiplist) > 0){
|
||||||
q = skiplist;
|
snprintf(muf, sizeof(muf)-1, "%s,", puf);
|
||||||
do {
|
if(strstr(skiplist, muf)) skipmatch = 1;
|
||||||
memset(muf, 0, sizeof(muf));
|
|
||||||
q = split(q, ',', muf, sizeof(muf)-1);
|
|
||||||
if(strncasecmp(puf, muf, strlen(muf)) == 0){
|
|
||||||
skipmatch = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(q);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(skipmatch == 1){
|
if(skipmatch == 1){
|
||||||
|
Loading…
Reference in New Issue
Block a user