]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Use own code for parsing of date
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 21 Dec 2016 14:18:42 +0000 (14:18 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 21 Dec 2016 14:18:42 +0000 (14:18 +0000)
src/CMakeLists.txt
src/libmime/smtp_parsers.h
src/lua/lua_task.c
src/ragel/smtp_date_parser.rl [new file with mode: 0644]

index 7254eefc26031ccb8f4316e0cd5d01c642fdc994..36ab66f7395c622dbc35507304f261516478de52 100644 (file)
@@ -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)
index 905a01f0c6719b21563fb10e25af68450c3cc4dc..3f13abb598854545a39bb965de26b3d25946e9af 100644 (file)
@@ -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_ */
index 68d9b9704314de365db58c02937b23928955d899..96c03847c61aff175927e6011eba3c76b2babb67 100644 (file)
@@ -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 (file)
index 0000000..84b63f1
--- /dev/null
@@ -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