From 0a78b061d5d238592c0c8bbf703acb46d985ed17 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 15 Oct 2014 09:36:09 +0200 Subject: [PATCH] imap import fixes --- src/config.h | 2 +- src/imap.c | 6 ++++-- src/parser.c | 12 +++++++----- src/pilerimport.c | 16 +++++++++++++--- src/pop3.c | 4 ++-- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/config.h b/src/config.h index 15ac5819..a4b3ba68 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.1.1-pre" -#define BUILD 892 +#define BUILD 893 #define HOSTID "mailarchiver" diff --git a/src/imap.c b/src/imap.c index d52bb181..a4a3e5ee 100644 --- a/src/imap.c +++ b/src/imap.c @@ -130,7 +130,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda data->import->total_messages += messages; - for(i=1; i<=messages; i++){ + for(i=data->import->start_position; i<=messages; i++){ data->import->processed_messages++; printf("processed: %7d\r", data->import->processed_messages); fflush(stdout); @@ -384,6 +384,7 @@ int list_folders(int sd, int *seq, int use_ssl, struct __data *data){ while(1){ n = recvtimeoutssl(sd, puf, sizeof(puf), 10, use_ssl, data->ssl); + if(n < 0) return ERR; if(pos + n >= len){ q = realloc(buf, len+MAXBUFSIZE+1); @@ -429,7 +430,8 @@ int list_folders(int sd, int *seq, int use_ssl, struct __data *data){ fldrlen = strtol(q, NULL, 10); } else { if(*q == '"') q++; - + + if(q[strlen(q)-1] == ' ') q[strlen(q)-1] = '\0'; if(q[strlen(q)-1] == '"') q[strlen(q)-1] = '\0'; if(fldrlen) { diff --git a/src/parser.c b/src/parser.c index 3eb70a43..75717aea 100644 --- a/src/parser.c +++ b/src/parser.c @@ -190,11 +190,13 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int } if(state->is_1st_header == 1 && sdata->ms_journal == 0 && (strncmp(buf, "X-MS-Journal-Report:", strlen("X-MS-Journal-Report:")) == 0 || (sdata->import == 1 && strncmp(buf, "X-MS-Exchange-Organization-Auth", strlen("X-MS-Exchange-Organization-Auth")) == 0))){ - sdata->ms_journal = 1; - memset(state->message_id, 0, SMALLBUFSIZE); + if(sdata->import == 0){ + sdata->ms_journal = 1; + memset(state->message_id, 0, SMALLBUFSIZE); - memset(state->b_from, 0, SMALLBUFSIZE); - memset(state->b_from_domain, 0, SMALLBUFSIZE); + memset(state->b_from, 0, SMALLBUFSIZE); + memset(state->b_from_domain, 0, SMALLBUFSIZE); + } } @@ -636,7 +638,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int if(state->is_header == 1) p = strchr(buf, ' '); else p = buf; - //printf("a: %d/%d/%d/%d %s\n", state->is_1st_header, state->is_header, state->message_rfc822, state->message_state, buf); + printf("a: %d/%d/%d/%d %s\n", state->is_1st_header, state->is_header, state->message_rfc822, state->message_state, buf); do { memset(puf, 0, sizeof(puf)); diff --git a/src/pilerimport.c b/src/pilerimport.c index 42554c4d..87ef8efb 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -297,8 +297,17 @@ int import_from_imap_server(char *server, char *username, char *password, int po } - rc = list_folders(sd, &seq, use_ssl, data); - if(rc == ERR) goto ENDE_IMAP; + /* + * if the user gives -f , then don't iterate through the folder list + * rather build the folderlist based on the option, 2014.10.14, SJ + */ + + if(folder_imap){ + addnode(data->imapfolders, folder_imap); + } else { + rc = list_folders(sd, &seq, use_ssl, data); + if(rc == ERR) goto ENDE_IMAP; + } for(i=0;i] -e | -m | -d | -i | -K | -u -p -P [-x ] [-F ] [-R] [-r] [-q]\n"); + printf("usage: pilerimport [-c ] -e | -m | -d | -i | -K | -u -p -P \n"); + printf(" [-x ] [-f ] [-F ] [-b ] [-s ] [-D] [-R] [-r] [-q]\n"); exit(0); } diff --git a/src/pop3.c b/src/pop3.c index 8c89f87b..72534c6d 100644 --- a/src/pop3.c +++ b/src/pop3.c @@ -85,7 +85,7 @@ int connect_to_pop3_server(int sd, char *username, char *password, int port, str snprintf(buf, sizeof(buf)-1, "PASS %s\r\n", password); write1(sd, buf, strlen(buf), use_ssl, data->ssl); - n = recvtimeoutssl(sd, buf, sizeof(buf), 10, use_ssl, data->ssl); + n = recvtimeoutssl(sd, buf, sizeof(buf), 30, use_ssl, data->ssl); if(strncmp(buf, "+OK", 3) == 0) return OK; @@ -106,7 +106,7 @@ int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, snprintf(buf, sizeof(buf)-1, "STAT\r\n"); n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); - n = recvtimeoutssl(sd, buf, sizeof(buf), 10, use_ssl, data->ssl); + n = recvtimeoutssl(sd, buf, sizeof(buf), 30, use_ssl, data->ssl); if(strncmp(buf, "+OK ", 4) == 0){ p = strchr(&buf[4], ' ');