added imap support for gui import

This commit is contained in:
SJ 2013-09-04 23:42:07 +02:00
parent 4a961e4ecc
commit c2539c71a8
2 changed files with 19 additions and 13 deletions

View File

@ -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 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 *p, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], tagbad[SMALLBUFSIZE], buf[MAXBUFSIZE], filename[SMALLBUFSIZE];
char aggrbuf[3*MAXBUFSIZE]; 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); 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++){ for(i=1; i<=messages; i++){
processed_messages++; data->import->processed_messages++;
printf("processed: %7d\r", processed_messages); fflush(stdout); printf("processed: %7d\r", data->import->processed_messages); fflush(stdout);
snprintf(tag, sizeof(tag)-1, "A%d", *seq); snprintf(tag, sizeof(tag)-1, "A%d", *seq);
snprintf(tagok, sizeof(tagok)-1, "\r\nA%d OK", (*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(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); unlink(filename);
fd = open(filename, O_CREAT|O_EXCL|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); fd = open(filename, O_CREAT|O_EXCL|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR);

View File

@ -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; int rc=ERR;
char s_type[SMALLBUFSIZE], s_username[SMALLBUFSIZE], s_password[SMALLBUFSIZE], s_server[SMALLBUFSIZE]; 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: ENDE:
close_prepared_statement(data->stmt_generic); close_prepared_statement(data->stmt_generic);
data->import->processed_messages = 0;
data->import->total_messages = 0;
time(&(data->import->started)); time(&(data->import->started));
data->import->status = 1; data->import->status = 1;
@ -433,14 +435,16 @@ ENDE:
if(strcmp(s_type, "pop3") == 0){ if(strcmp(s_type, "pop3") == 0){
rc = import_from_pop3_server(s_server, s_username, s_password, 110, sdata, data, dryrun, cfg); 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; 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(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(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(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.archiving_rules);
clearrules(data.retention_rules); clearrules(data.retention_rules);