From 97fe86481069350ba506d4e8a18292743261a78c Mon Sep 17 00:00:00 2001 From: SJ Date: Tue, 10 Nov 2015 16:06:47 +0100 Subject: [PATCH] improved date parsing --- src/config.h | 2 +- src/import.c | 10 ---------- src/misc.c | 3 ++- src/parser.c | 23 +++++++---------------- src/reindex.c | 2 -- src/test.c | 1 - 6 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/config.h b/src/config.h index 9524b0a9..0b4ad8b0 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "1.2.0-master" -#define BUILD 925 +#define BUILD 926 #define HOSTID "mailarchiver" diff --git a/src/import.c b/src/import.c index 8d41bd7b..f6396741 100644 --- a/src/import.c +++ b/src/import.c @@ -73,7 +73,6 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da - sdata->sent = 0; sdata->delivered = 0; sdata->import = 1; @@ -81,15 +80,6 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da state = parse_message(sdata, 1, data, cfg); post_parse(sdata, &state, cfg); - if(sdata->sent <= 0 && sdata->delivered > 0) sdata->sent = sdata->delivered; - - if(sdata->sent > sdata->now) sdata->sent = sdata->now; - if(sdata->sent == -1) sdata->sent = 0; - - /* fat chances that you won't import emails before 1990.01.01 */ - - if(sdata->sent > 631148400) sdata->retained = sdata->sent; - rule = check_againt_ruleset(data->archiving_rules, &state, sdata->tot_len, sdata->spam_message); if(rule){ diff --git a/src/misc.c b/src/misc.c index 66647aea..6b1fee6b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -547,7 +547,8 @@ void init_session_data(struct session_data *sdata, struct __config *cfg){ for(i=0; ircptto[i], 0, SMALLBUFSIZE); time(&(sdata->now)); - sdata->sent = sdata->delivered = sdata->retained = sdata->now; + sdata->delivered = sdata->retained = sdata->now; + sdata->sent = 0; sdata->sql_errno = 0; diff --git a/src/parser.c b/src/parser.c index 80fa3203..5684dcc8 100644 --- a/src/parser.c +++ b/src/parser.c @@ -147,6 +147,7 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi digest_string(state->message_id, &(state->message_id_hash[0])); + if(sdata->sent == 0) sdata->sent = sdata->now; } @@ -228,11 +229,6 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int state->is_header = 1; memset(state->b_body, 0, BIGBUFSIZE); state->bodylen = 0; - - if(sdata->import == 1){ - sdata->sent = 0; - } - } if(take_into_pieces == 1){ @@ -381,24 +377,19 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int else if(strncasecmp(buf, "Subject:", strlen("Subject:")) == 0) state->message_state = MSG_SUBJECT; else if(strncasecmp(buf, "Recipient:", strlen("Recipient:")) == 0) state->message_state = MSG_RECIPIENT; - //else if(strncasecmp(buf, "Date:", strlen("Date:")) == 0 && sdata->sent == 0) sdata->sent = parse_date_header(buf, cfg); - /* - * in pilerimport: sdata->sent = 0 - * in piler daemon: sdata->sent = sdata->now + * by default sdata->sent = 0, and let the parser extract value from the Date: header */ - else if(strncasecmp(buf, "Date:", strlen("Date:")) == 0 && state->is_1st_header == 1){ + else if(strncasecmp(buf, "Date:", strlen("Date:")) == 0 && state->is_1st_header == 1 && sdata->sent == 0){ if(strstr(buf, "=?") && strstr(buf, "?=")) fixupEncodedHeaderLine(buf, MAXBUFSIZE); - if(sdata->sent == 0) sdata->sent = parse_date_header(buf, cfg); - else { - sdata->sent = parse_date_header(buf, cfg); + sdata->sent = parse_date_header(buf, cfg); - /* allow -1 week ... +1 day drift in the parsed Date: value */ - if(sdata->now - sdata->sent > 604800 || sdata->sent - sdata->now > 86400) sdata->sent = sdata->now; - } + /* allow +2 days drift in the parsed Date: value */ + + if(sdata->sent - sdata->now > 2*86400) sdata->sent = sdata->now; } else if(strncasecmp(buf, "Delivery-date:", strlen("Delivery-date:")) == 0 && sdata->delivered == 0) sdata->delivered = parse_date_header(buf, cfg); diff --git a/src/reindex.c b/src/reindex.c index 563f2870..f5168768 100644 --- a/src/reindex.c +++ b/src/reindex.c @@ -120,8 +120,6 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data * snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", filename); - sdata->sent = 0; - state = parse_message(sdata, 0, data, cfg); post_parse(sdata, &state, cfg); diff --git a/src/test.c b/src/test.c index 0d89f237..cf7ec5fc 100644 --- a/src/test.c +++ b/src/test.c @@ -74,7 +74,6 @@ int main(int argc, char **argv){ init_session_data(&sdata, &cfg); - sdata.sent = 0; sdata.delivered = 0; sdata.tot_len = st.st_size; sdata.import = 1;