diff --git a/src/config.h b/src/config.h index a6e3d040..c8f13018 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.2.0-master" -#define BUILD 916 +#define BUILD 917 #define HOSTID "mailarchiver" diff --git a/src/defs.h b/src/defs.h index 9e31bbf0..e91ae951 100644 --- a/src/defs.h +++ b/src/defs.h @@ -277,6 +277,7 @@ struct import { int remove_after_import; int download_only; int keep_eml; + int timeout; long total_size; time_t started, updated, finished; }; diff --git a/src/imap.c b/src/imap.c index fa364c58..b41dcf8a 100644 --- a/src/imap.c +++ b/src/imap.c @@ -65,7 +65,7 @@ int read_response(int sd, char *buf, int buflen, int *seq, struct __data *data, memset(buf, 0, buflen); while(!strstr(buf, tagok)){ - n = recvtimeoutssl(sd, puf, sizeof(puf), 10, use_ssl, data->ssl); + n = recvtimeoutssl(sd, puf, sizeof(puf), data->import->timeout, use_ssl, data->ssl); if(n + len < buflen) strncat(buf, puf, n); else goto END; @@ -156,7 +156,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda msglen = 0; msg_written_len = 0; - while((n = recvtimeoutssl(sd, &buf[readpos], sizeof(buf)-readpos, 60, use_ssl, data->ssl)) > 0){ + while((n = recvtimeoutssl(sd, &buf[readpos], sizeof(buf)-readpos, data->import->timeout, use_ssl, data->ssl)) > 0){ readlen += n; @@ -316,7 +316,7 @@ int connect_to_imap_server(int sd, int *seq, char *username, char *password, int } - n = recvtimeoutssl(sd, buf, sizeof(buf), 10, use_ssl, data->ssl); + n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); /* imap cmd: CAPABILITY */ @@ -378,7 +378,7 @@ int list_folders(int sd, int *seq, int use_ssl, struct __data *data){ write1(sd, puf, strlen(puf), use_ssl, data->ssl); while(1){ - n = recvtimeoutssl(sd, puf, sizeof(puf), 10, use_ssl, data->ssl); + n = recvtimeoutssl(sd, puf, sizeof(puf), data->import->timeout, use_ssl, data->ssl); if(n < 0) return ERR; if(pos + n >= len){ diff --git a/src/pilerimport.c b/src/pilerimport.c index 212eec8e..03f262ac 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -500,6 +500,7 @@ int main(int argc, char **argv){ import.extra_recipient = NULL; import.start_position = 1; import.download_only = 0; + import.timeout = 30; data.import = &import; @@ -527,6 +528,7 @@ int main(int argc, char **argv){ {"folder_imap", required_argument, 0, 'f' }, {"add-recipient",required_argument, 0, 'a' }, {"batch-limit", required_argument, 0, 'b' }, + {"timeout", required_argument, 0, 't' }, {"start-position",required_argument, 0, 's' }, {"quiet", no_argument, 0, 'q' }, {"recursive", required_argument, 0, 'R' }, @@ -540,9 +542,9 @@ int main(int argc, char **argv){ int option_index = 0; - c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:s:GDRroqh?", long_options, &option_index); + c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:GDRroqh?", long_options, &option_index); #else - c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:s:GDRroqh?"); + c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:GDRroqh?"); #endif if(c == -1) break; @@ -624,6 +626,10 @@ int main(int argc, char **argv){ data.import->batch_processing_limit = atoi(optarg); break; + case 't' : + data.import->timeout = atoi(optarg); + break; + case 's' : if(atoi(optarg) < 1){ printf("invalid start position: %s\n", optarg); diff --git a/src/pop3.c b/src/pop3.c index 8175a631..7436ba17 100644 --- a/src/pop3.c +++ b/src/pop3.c @@ -75,19 +75,19 @@ int connect_to_pop3_server(int sd, char *username, char *password, int port, str } - n = recvtimeoutssl(sd, buf, sizeof(buf), 10, use_ssl, data->ssl); + n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); snprintf(buf, sizeof(buf)-1, "USER %s\r\n", username); 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), data->import->timeout, use_ssl, data->ssl); 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), 30, use_ssl, data->ssl); + n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); if(strncmp(buf, "+OK", 3) == 0) return OK; @@ -108,7 +108,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), 30, use_ssl, data->ssl); + n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); if(strncmp(buf, "+OK ", 4) == 0){ p = strchr(&buf[4], ' '); @@ -150,7 +150,7 @@ int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, lastpos = 0; - while((n = recvtimeoutssl(sd, buf, sizeof(buf), 15, use_ssl, data->ssl)) > 0){ + while((n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl)) > 0){ nreads++; readlen += n; @@ -204,7 +204,7 @@ int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, if(dryrun == 0 && rc == OK && data->import->remove_after_import == 1){ snprintf(buf, sizeof(buf)-1, "DELE %d\r\n", i); 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), data->import->timeout, use_ssl, data->ssl); } if(i % 100 == 0){