added timeout option to pilerimport (30s by default)

This commit is contained in:
SJ 2015-07-31 12:06:19 +02:00
parent eb0c63e60a
commit 84587c2b04
5 changed files with 20 additions and 13 deletions

View File

@ -14,7 +14,7 @@
#define VERSION "1.2.0-master"
#define BUILD 916
#define BUILD 917
#define HOSTID "mailarchiver"

View File

@ -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;
};

View File

@ -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){

View File

@ -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);

View File

@ -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){