From: Vsevolod Stakhov Date: Tue, 13 Mar 2018 17:49:35 +0000 (+0000) Subject: [Minor] Add Lua API to get filename X-Git-Tag: 1.7.1~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=baee02f1f70d1ceedf0bf0c5788c55ea0ddb9561;p=thirdparty%2Frspamd.git [Minor] Add Lua API to get filename --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index a98f4d97aa..89f35e90da 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -174,6 +174,13 @@ LUA_FUNCTION_DEF (task, has_urls); */ LUA_FUNCTION_DEF (task, get_content); +/*** + * @method task:get_filename() + * Returns filename for a specific task + * @return {string|nil} filename or nil if unknown + */ +LUA_FUNCTION_DEF (task, get_filename); + /*** * @method task:get_rawbody() * Get raw body for the specified task @@ -855,6 +862,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, has_urls), LUA_INTERFACE_DEF (task, get_urls), LUA_INTERFACE_DEF (task, get_content), + LUA_INTERFACE_DEF (task, get_filename), LUA_INTERFACE_DEF (task, get_rawbody), LUA_INTERFACE_DEF (task, get_emails), LUA_INTERFACE_DEF (task, get_text_parts), @@ -1534,6 +1542,26 @@ lua_task_get_content (lua_State * L) return 1; } +static gint +lua_task_get_filename (lua_State * L) +{ + struct rspamd_task *task = lua_check_task (L, 1); + + if (task) { + if (task->msg.fpath) { + lua_pushstring (L, task->msg.fpath); + } + else { + lua_pushnil (L); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static gint lua_task_get_rawbody (lua_State * L) {