diff options
-rw-r--r-- | src/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/libmime/smtp_parsers.h | 2 | ||||
-rw-r--r-- | src/lua/lua_task.c | 16 | ||||
-rw-r--r-- | src/ragel/smtp_date_parser.rl | 28 |
4 files changed, 49 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7254eefc2..36ab66f73 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,6 +138,11 @@ RAGEL_TARGET(ragel_rfc2047 DEPENDS ${RAGEL_DEPENDS} COMPILE_FLAGS -G2 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rfc2047.rl.c) +RAGEL_TARGET(ragel_smtp_date + INPUTS ${CMAKE_SOURCE_DIR}/src/ragel/smtp_date_parser.rl + DEPENDS ${RAGEL_DEPENDS} + COMPILE_FLAGS -G2 + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/date_parser.rl.c) ######################### LINK SECTION ############################### ADD_LIBRARY(rspamd-server STATIC @@ -154,7 +159,8 @@ ADD_LIBRARY(rspamd-server STATIC "${RAGEL_ragel_newlines_strip_OUTPUTS}" "${RAGEL_ragel_content_type_OUTPUTS}" "${RAGEL_ragel_content_disposition_OUTPUTS}" - "${RAGEL_ragel_rfc2047_OUTPUTS}") + "${RAGEL_ragel_rfc2047_OUTPUTS}" + "${RAGEL_ragel_smtp_date_OUTPUTS}") TARGET_LINK_LIBRARIES(rspamd-server rspamd-http-parser) TARGET_LINK_LIBRARIES(rspamd-server rspamd-cdb) TARGET_LINK_LIBRARIES(rspamd-server rspamd-lpeg) diff --git a/src/libmime/smtp_parsers.h b/src/libmime/smtp_parsers.h index 905a01f0c..3f13abb59 100644 --- a/src/libmime/smtp_parsers.h +++ b/src/libmime/smtp_parsers.h @@ -41,4 +41,6 @@ rspamd_rfc2047_parser (const gchar *in, gsize len, gint *pencoding, const gchar **charset, gsize *charset_len, const gchar **encoded, gsize *encoded_len); +guint64 rspamd_parse_smtp_date (const char *data, size_t len); + #endif /* SRC_LIBMIME_SMTP_PARSERS_H_ */ diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 68d9b9704..96c03847c 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -26,6 +26,7 @@ #include "utlist.h" #include "cryptobox.h" #include "unix-std.h" +#include "libmime/smtp_parsers.h" /*** * @module rspamd_task @@ -2591,16 +2592,23 @@ lua_task_get_date (lua_State *L) if (hdrs && hdrs->len > 0) { time_t tt; - gint offset; + struct tm t; struct rspamd_mime_header *h; h = g_ptr_array_index (hdrs, 0); - tt = g_mime_utils_header_decode_date (h->decoded, &offset); + tt = rspamd_parse_smtp_date (h->raw_value, h->raw_len); if (!gmt) { - tt += (offset * 60 * 60) / 100 + (offset * 60 * 60) % 100; + localtime_r (&tt, &t); +#if !defined(__sun) + t.tm_gmtoff = 0; +#endif + t.tm_isdst = 0; + tim = mktime (&t); + } + else { + tim = tt; } - tim = tt; } else { tim = 0.0; diff --git a/src/ragel/smtp_date_parser.rl b/src/ragel/smtp_date_parser.rl new file mode 100644 index 000000000..84b63f1bd --- /dev/null +++ b/src/ragel/smtp_date_parser.rl @@ -0,0 +1,28 @@ +%%{ + + machine smtp_date_parser; + include smtp_date "smtp_date.rl"; + + main := date_time; +}%% + +#include "smtp_parsers.h" +#include "util.h" + +%% write data; + +guint64 +rspamd_parse_smtp_date (const char *data, size_t len) +{ + const gchar *p = data, *pe = data + len, *eof = data + len, *tmp = data; + struct tm tm; + glong tz = 0; + gint cs = 0; + + memset (&tm, 0, sizeof (tm)); + + %% write init; + %% write exec; + + return rspamd_tm_to_time (&tm, tz); +}
\ No newline at end of file |