From c2539c71a880fe7f1643c876a16911361ce60a51 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 4 Sep 2013 23:42:07 +0200 Subject: [PATCH] added imap support for gui import --- src/imap.c | 12 +++++++----- src/pilerimport.c | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/imap.c b/src/imap.c index ef06eeaa..98fd69ab 100644 --- a/src/imap.c +++ b/src/imap.c @@ -92,7 +92,7 @@ int read_response(int sd, char *buf, int buflen, char *tagok, struct __data *dat int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sdata, struct __data *data, int use_ssl, int dryrun, struct __config *cfg){ - int rc=ERR, i, n, pos, endpos, messages=0, len, readlen, fd, lastpos, nreads, processed_messages=0; + int rc=ERR, i, n, pos, endpos, messages=0, len, readlen, fd, lastpos, nreads; char *p, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], tagbad[SMALLBUFSIZE], buf[MAXBUFSIZE], filename[SMALLBUFSIZE]; char aggrbuf[3*MAXBUFSIZE]; @@ -122,11 +122,13 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda printf("found %d messages\n", messages); - if(messages <= 0) return rc; + if(messages <= 0) return OK; + + data->import->total_messages += messages; for(i=1; i<=messages; i++){ - processed_messages++; - printf("processed: %7d\r", processed_messages); fflush(stdout); + data->import->processed_messages++; + printf("processed: %7d\r", data->import->processed_messages); fflush(stdout); snprintf(tag, sizeof(tag)-1, "A%d", *seq); snprintf(tagok, sizeof(tagok)-1, "\r\nA%d OK", (*seq)++); @@ -134,7 +136,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda snprintf(buf, sizeof(buf)-1, "%s FETCH %d (BODY.PEEK[])\r\n", tag, i); - snprintf(filename, sizeof(filename)-1, "imap-%d.txt", i); + snprintf(filename, sizeof(filename)-1, "imap-%d.txt", data->import->processed_messages); unlink(filename); fd = open(filename, O_CREAT|O_EXCL|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); diff --git a/src/pilerimport.c b/src/pilerimport.c index 5a02bf99..02fb943b 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -390,7 +390,7 @@ ENDE_POP3: } -int read_gui_import_data(struct session_data *sdata, struct __data *data, int dryrun, struct __config *cfg){ +int read_gui_import_data(struct session_data *sdata, struct __data *data, char *skiplist, int dryrun, struct __config *cfg){ int rc=ERR; char s_type[SMALLBUFSIZE], s_username[SMALLBUFSIZE], s_password[SMALLBUFSIZE], s_server[SMALLBUFSIZE]; @@ -426,6 +426,8 @@ int read_gui_import_data(struct session_data *sdata, struct __data *data, int dr ENDE: close_prepared_statement(data->stmt_generic); + data->import->processed_messages = 0; + data->import->total_messages = 0; time(&(data->import->started)); data->import->status = 1; @@ -433,14 +435,16 @@ ENDE: if(strcmp(s_type, "pop3") == 0){ rc = import_from_pop3_server(s_server, s_username, s_password, 110, sdata, data, dryrun, cfg); - - if(rc == ERR){ - data->import->status = 3; - update_import_job_stat(sdata, data); - } - } + if(strcmp(s_type, "imap") == 0){ + rc = import_from_imap_server(s_server, s_username, s_password, 143, sdata, data, skiplist, dryrun, cfg); + } + + if(rc == ERR){ + data->import->status = 3; + update_import_job_stat(sdata, data); + } return rc; } @@ -651,7 +655,7 @@ int main(int argc, char **argv){ if(directory) rc = import_from_maildir(directory, &sdata, &data, &tot_msgs, &cfg); if(imapserver && username && password) rc = import_from_imap_server(imapserver, username, password, port, &sdata, &data, skiplist, dryrun, &cfg); if(pop3server && username && password) rc = import_from_pop3_server(pop3server, username, password, port, &sdata, &data, dryrun, &cfg); - if(import_from_gui == 1) rc = read_gui_import_data(&sdata, &data, dryrun, &cfg); + if(import_from_gui == 1) rc = read_gui_import_data(&sdata, &data, skiplist, dryrun, &cfg); clearrules(data.archiving_rules); clearrules(data.retention_rules);