From 557cad5d0aee29dc8900b4fa6922fcff379244d1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 28 Mar 2017 14:36:07 +0100 Subject: [Feature] Allow to get task's subject --- src/lua/lua_task.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 36272ecfe..46fc5da94 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -195,6 +195,12 @@ LUA_FUNCTION_DEF (task, get_request_header); * @param {rspamd_text/string} value new header's value */ LUA_FUNCTION_DEF (task, set_request_header); +/*** + * @method task:get_subject() + * Returns task subject (either from the protocol override or from a header) + * @return {string} value of a subject (decoded) + */ +LUA_FUNCTION_DEF (task, get_subject); /*** * @method task:get_header(name[, case_sensitive]) * Get decoded value of a header specified with optional case_sensitive flag. @@ -817,6 +823,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, set_from_ip), LUA_INTERFACE_DEF (task, get_from_ip_num), LUA_INTERFACE_DEF (task, get_client_ip), + LUA_INTERFACE_DEF (task, get_subject), LUA_INTERFACE_DEF (task, get_helo), LUA_INTERFACE_DEF (task, set_helo), LUA_INTERFACE_DEF (task, get_hostname), @@ -2586,6 +2593,27 @@ lua_task_get_helo (lua_State *L) return 1; } +static gint +lua_task_get_subject (lua_State *L) +{ + struct rspamd_task *task = lua_check_task (L, 1); + + if (task) { + if (task->subject != NULL) { + lua_pushstring (L, task->subject); + return 1; + } + else { + lua_pushnil (L); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static gint lua_task_set_helo (lua_State *L) { -- cgit v1.2.3