aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-28 14:29:39 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-28 14:29:39 +0100
commit6ad27c1aa0e361645887d492ce3011deda65492a (patch)
tree87dd7cbec0c23aaedec1a15d7e6b74045ab7b8b5 /src/lua
parenta709da98c462abc9f6b08e4288525ad92698685f (diff)
downloadrspamd-6ad27c1aa0e361645887d492ce3011deda65492a.tar.gz
rspamd-6ad27c1aa0e361645887d492ce3011deda65492a.zip
[Minor] Allow to get newlines type from a task
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index bd7d693d0..b7f636c37 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}
};
@@ -4248,6 +4257,32 @@ lua_task_disable_action (lua_State *L)
}
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)
{
struct rspamd_task *task = lua_check_task (L, 1);