mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 04:20:12 +01:00
improved date parsing
This commit is contained in:
parent
40d187a718
commit
97fe864810
@ -14,7 +14,7 @@
|
||||
|
||||
#define VERSION "1.2.0-master"
|
||||
|
||||
#define BUILD 925
|
||||
#define BUILD 926
|
||||
|
||||
#define HOSTID "mailarchiver"
|
||||
|
||||
|
10
src/import.c
10
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){
|
||||
|
@ -547,7 +547,8 @@ void init_session_data(struct session_data *sdata, struct __config *cfg){
|
||||
for(i=0; i<MAX_RCPT_TO; i++) memset(sdata->rcptto[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;
|
||||
|
||||
|
23
src/parser.c
23
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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user