From baee02f1f70d1ceedf0bf0c5788c55ea0ddb9561 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 13 Mar 2018 17:49:35 +0000 Subject: [PATCH] [Minor] Add Lua API to get filename --- 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 a98f4d97a..89f35e90d 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) { -- 2.39.5