From aab7b712d20c8885f66a17feb0a5aa4f9056d839 Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Mon, 21 Jun 2021 12:52:58 +0200 Subject: [PATCH] Introduced -Z option for pilerimport to add delay between importing emails Signed-off-by: Janos SUTO --- src/defs.h | 1 + src/import.c | 8 ++++++++ src/pilerimport.c | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/defs.h b/src/defs.h index 05b9efbb..66be6ab1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -315,6 +315,7 @@ struct import { 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 601c9b84..94b59dc2 100644 --- a/src/import.c +++ b/src/import.c @@ -25,6 +25,14 @@ int import_message(struct session_data *sdata, struct data *data, struct config 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 36027604..3af32505 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -53,6 +53,7 @@ void usage(){ 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 @@ int main(int argc, char **argv){ import.tot_msgs = 0; import.table_id = 0; import.folder = NULL; + import.delay = 0; data.import = &import; @@ -136,6 +138,7 @@ int main(int argc, char **argv){ {"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 main(int argc, char **argv){ 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 @@ int main(int argc, char **argv){ 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;