From e133a41570cf88645bf0267c6d64dfcd60a1cca7 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 27 Nov 2013 16:28:50 +0100 Subject: [PATCH] parsing the date header honors the timezone offset --- src/config.h | 2 +- src/parser_utils.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/config.h b/src/config.h index 071e30f9..5ccbd5a2 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-master-branch" -#define BUILD 853 +#define BUILD 854 #define HOSTID "mailarchiver" diff --git a/src/parser_utils.c b/src/parser_utils.c index b0631c60..7c4eee51 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -102,10 +102,19 @@ void init_state(struct _state *state){ } +long get_local_timezone_offset(){ + time_t t = time(NULL); + struct tm lt = {0}; + localtime_r(&t, <); + return lt.tm_gmtoff; +} + + unsigned long parse_date_header(char *datestr, struct __config *cfg){ int n=0; - char *p, *q, *r, s[SMALLBUFSIZE]; + long offset=0; unsigned long ts=0; + char *p, *q, *r, s[SMALLBUFSIZE]; struct tm tm; datestr += 5; @@ -175,6 +184,12 @@ unsigned long parse_date_header(char *datestr, struct __config *cfg){ tm.tm_isdst = -1; ts = mktime(&tm); + if(p && (*p == '+' || *p == '-')){ + offset = atoi(p) / 100 * 3600; + ts += get_local_timezone_offset() - offset; + } + + #ifdef HAVE_TWEAK_SENT_TIME if(ts > 631148400) ts += cfg->tweak_sent_time_offset; #endif