diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-04-22 18:57:52 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-04-22 18:57:52 +0400 |
commit | cca977866939436fa886e49859031631d1de0a22 (patch) | |
tree | 8798c99af5a82861f7cf718d692c74fdcdab636f /src/lua/lua_message.c | |
parent | ce4150785d795583d9fb89bc6db1518294ab64cd (diff) | |
download | rspamd-cca977866939436fa886e49859031631d1de0a22.tar.gz rspamd-cca977866939436fa886e49859031631d1de0a22.zip |
* Add functions to lua API to detect message and task date (in GMT)
Diffstat (limited to 'src/lua/lua_message.c')
-rw-r--r-- | src/lua/lua_message.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lua/lua_message.c b/src/lua/lua_message.c index 2848e082f..c1b7a734f 100644 --- a/src/lua/lua_message.c +++ b/src/lua/lua_message.c @@ -68,6 +68,7 @@ LUA_FUNCTION_DEF (message, set_reply_to); 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), @@ -81,6 +82,7 @@ static const struct luaL_reg msglib_m[] = { 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} }; @@ -180,6 +182,25 @@ lua_message_set_header (lua_State * L) 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) |