]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Allow to get newlines type from a task
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Mar 2018 13:29:39 +0000 (14:29 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Mar 2018 13:29:39 +0000 (14:29 +0100)
src/lua/lua_task.c

index bd7d693d0cc41a0b1a7570d35e5d5f20d6e821f4..b7f636c37c03bf463a6e7d564bc08f19ed837264 100644 (file)
@@ -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)
 {