extern const luaL_reg null_reg[];
-#define RSPAMD_LUA_API_VERSION 4
+#define RSPAMD_LUA_API_VERSION 5
/* Common utility functions */
void lua_newclass (lua_State *L, const gchar *classname, const struct luaL_reg *func);
LUA_FUNCTION_DEF (message, get_header);
LUA_FUNCTION_DEF (message, get_header_strong);
LUA_FUNCTION_DEF (message, set_header);
+LUA_FUNCTION_DEF (message, get_date);
static const struct luaL_reg msglib_m[] = {
LUA_INTERFACE_DEF (message, get_subject),
LUA_INTERFACE_DEF (message, get_header),
LUA_INTERFACE_DEF (message, get_header_strong),
LUA_INTERFACE_DEF (message, set_header),
+ LUA_INTERFACE_DEF (message, get_date),
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
return 1;
}
+static gint
+lua_message_get_date (lua_State * L)
+{
+ GMimeMessage *obj = lua_check_message (L);
+ time_t msg_time;
+ int offset;
+
+ if (obj != NULL) {
+ g_mime_message_get_date (obj, &msg_time, &offset);
+ /* Convert result to GMT */
+ msg_time -= (offset / 100) * 3600;
+ lua_pushnumber (L, msg_time);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
gint
luaopen_message (lua_State * L)
LUA_FUNCTION_DEF (task, get_helo);
LUA_FUNCTION_DEF (task, get_images);
LUA_FUNCTION_DEF (task, get_symbol);
+LUA_FUNCTION_DEF (task, get_date);
LUA_FUNCTION_DEF (task, get_metric_score);
LUA_FUNCTION_DEF (task, get_metric_action);
LUA_FUNCTION_DEF (task, learn_statfile);
LUA_INTERFACE_DEF (task, get_helo),
LUA_INTERFACE_DEF (task, get_images),
LUA_INTERFACE_DEF (task, get_symbol),
+ LUA_INTERFACE_DEF (task, get_date),
LUA_INTERFACE_DEF (task, get_metric_score),
LUA_INTERFACE_DEF (task, get_metric_action),
LUA_INTERFACE_DEF (task, learn_statfile),
return 1;
}
+static gint
+lua_task_get_date (lua_State *L)
+{
+ struct worker_task *task = lua_check_task (L);
+ time_t task_time;
+
+ if (task != NULL) {
+ /* Get GMT date and store it to time_t */
+ task_time = mktime (gmtime (&task->tv.tv_sec));
+ lua_pushnumber (L, task_time);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
static gint
lua_task_learn_statfile (lua_State *L)
{