Added --before and --after support for pilerimport

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2023-03-19 20:19:59 +01:00
parent 29d3358212
commit 7e3e8edf49
3 changed files with 23 additions and 3 deletions

View File

@ -331,7 +331,7 @@ struct import {
char *mboxdir; char *mboxdir;
char *folder; char *folder;
char filename[SMALLBUFSIZE]; char filename[SMALLBUFSIZE];
time_t started, updated, finished; time_t started, updated, finished, after, before;
}; };

View File

@ -93,6 +93,14 @@ int import_message(struct session_data *sdata, struct data *data, struct config
printf("%s: invalid message, hdr_len: %d\n", data->import->filename, sdata->hdr_len); printf("%s: invalid message, hdr_len: %d\n", data->import->filename, sdata->hdr_len);
rc = ERR; rc = ERR;
} }
else if(data->import->after > 0 && sdata->sent < data->import->after){
if(cfg->verbosity > 1) printf("discarding older email: %s\n", sdata->filename);
rc = ERR_DISCARDED;
}
else if(data->import->before > 0 && sdata->sent > data->import->before){
if(cfg->verbosity > 1) printf("discarding newer email: %s\n", sdata->filename);
rc = ERR_DISCARDED;
}
else { else {
// When importing emails, we should add the retention value (later) to the original sent value // When importing emails, we should add the retention value (later) to the original sent value
sdata->retained = sdata->sent; sdata->retained = sdata->sent;

View File

@ -59,6 +59,8 @@ void usage(){
printf(" -o Only download emails for POP3/IMAP import\n"); printf(" -o Only download emails for POP3/IMAP import\n");
printf(" -r Remove imported emails\n"); printf(" -r Remove imported emails\n");
printf(" -q Quiet mode\n"); printf(" -q Quiet mode\n");
printf(" -A <timestamp> Import emails sent after this timestamp\n");
printf(" -B <timestamp> Import emails sent before this timestamp\n");
exit(0); exit(0);
} }
@ -102,6 +104,8 @@ int main(int argc, char **argv){
import.table_id = 0; import.table_id = 0;
import.folder = NULL; import.folder = NULL;
import.delay = 0; import.delay = 0;
import.after = 0;
import.before = 0;
data.import = &import; data.import = &import;
@ -144,6 +148,8 @@ int main(int argc, char **argv){
{"remove-after-import",no_argument, 0, 'r' }, {"remove-after-import",no_argument, 0, 'r' },
{"failed-folder", required_argument, 0, 'j' }, {"failed-folder", required_argument, 0, 'j' },
{"move-folder", required_argument, 0, 'g' }, {"move-folder", required_argument, 0, 'g' },
{"after", required_argument, 0, 'A' },
{"before", required_argument, 0, 'B' },
{"only-download",no_argument, 0, 'o' }, {"only-download",no_argument, 0, 'o' },
{"read-from-export",no_argument, 0, 'y' }, {"read-from-export",no_argument, 0, 'y' },
{"dry-run", no_argument, 0, 'D' }, {"dry-run", no_argument, 0, 'D' },
@ -153,9 +159,9 @@ int main(int argc, char **argv){
int option_index = 0; 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:Z: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:A:B:yDRroqh?", long_options, &option_index);
#else #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:Z: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:A:B:yDRroqh?");
#endif #endif
if(c == -1) break; if(c == -1) break;
@ -295,6 +301,12 @@ int main(int argc, char **argv){
data.quiet = 1; data.quiet = 1;
break; break;
case 'A' : data.import->after = atol(optarg);
break;
case 'B' : data.import->before = atol(optarg);
break;
case 'h' : case 'h' :
case '?' : case '?' :
usage(); usage();