diff --git a/src/defs.h b/src/defs.h index 05b9efb..66be6ab 100644 --- a/src/defs.h +++ b/src/defs.h @@ -315,6 +315,7 @@ int port; int seq; int table_id; + int delay; char *server; char *username; char *password; diff --git a/src/import.c b/src/import.c index 601c9b8..94b59dc 100644 --- a/src/import.c +++ b/src/import.c @@ -25,6 +25,14 @@ struct parser_state state; struct counters counters; + if(data->import->delay > 0){ + struct timespec req; + + req.tv_sec = 0; + req.tv_nsec = 1000000 * data->import->delay; + + nanosleep(&req, NULL); + } init_session_data(sdata, cfg); diff --git a/src/pilerimport.c b/src/pilerimport.c index 3602760..3af3250 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -53,6 +53,7 @@ printf(" -j Move failed to import emails to this folder\n"); printf(" -a Add recipient to the To:/Cc: list\n"); printf(" -T Update import table at id=\n"); + printf(" -Z Delay Z milliseconds in between emails being imported\n"); printf(" -D Dry-run, do not import anything\n"); printf(" -y Read pilerexport data from stdin\n"); printf(" -o Only download emails for POP3/IMAP import\n"); @@ -100,6 +101,7 @@ import.tot_msgs = 0; import.table_id = 0; import.folder = NULL; + import.delay = 0; data.import = &import; @@ -136,6 +138,7 @@ {"timeout", required_argument, 0, 't' }, {"start-position",required_argument, 0, 's' }, {"table-id", required_argument, 0, 'T' }, + {"delay", required_argument, 0, 'Z' }, {"quiet", no_argument, 0, 'q' }, {"recursive", no_argument, 0, 'R' }, {"remove-after-import",no_argument, 0, 'r' }, @@ -150,9 +153,9 @@ int option_index = 0; - int c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:T:yDRroqh?", long_options, &option_index); + int c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:T:Z:yDRroqh?", long_options, &option_index); #else - int c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:T:yDRroqh?"); + int c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:T:Z:yDRroqh?"); #endif if(c == -1) break; @@ -271,6 +274,15 @@ data.import->table_id = atoi(optarg); break; + case 'Z' : + if(atoi(optarg) < 1){ + printf("invalid delay value: %s\n", optarg); + return -1; + } + + data.import->delay = atoi(optarg); + break; + case 'y' : read_from_pilerexport = 1; break;