From: Vsevolod Stakhov Date: Wed, 28 Mar 2018 13:29:39 +0000 (+0100) Subject: [Minor] Allow to get newlines type from a task X-Git-Tag: 1.7.3~95 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ad27c1aa0e361645887d492ce3011deda65492a;p=thirdparty%2Frspamd.git [Minor] Allow to get newlines type from a task --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index bd7d693d0c..b7f636c37c 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -843,6 +843,14 @@ LUA_FUNCTION_DEF (task, headers_foreach); */ LUA_FUNCTION_DEF (task, disable_action); +/*** + * @method task:get_newlines_type() + * Returns the most frequent newlines type met in a task + * + * @return {string} "cr" for \r, "lf" for \n, "crlf" for \r\n + */ +LUA_FUNCTION_DEF (task, get_newlines_type); + static const struct luaL_reg tasklib_f[] = { {NULL, NULL} }; @@ -936,6 +944,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, get_protocol_reply), LUA_INTERFACE_DEF (task, headers_foreach), LUA_INTERFACE_DEF (task, disable_action), + LUA_INTERFACE_DEF (task, get_newlines_type), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; @@ -4247,6 +4256,32 @@ lua_task_disable_action (lua_State *L) return 1; } +static gint +lua_task_get_newlines_type (lua_State *L) +{ + struct rspamd_task *task = lua_check_task (L, 1); + + if (task) { + switch (task->nlines_type) { + case RSPAMD_TASK_NEWLINES_CR: + lua_pushstring (L, "cr"); + break; + case RSPAMD_TASK_NEWLINES_LF: + lua_pushstring (L, "lf"); + break; + case RSPAMD_TASK_NEWLINES_CRLF: + default: + lua_pushstring (L, "crlf"); + break; + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static gint lua_task_set_metric_subject (lua_State *L) {