]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support setting task message from Lua 1048/head
authorAndrew Lewis <nerf@judo.za.org>
Tue, 18 Oct 2016 06:49:00 +0000 (08:49 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 18 Oct 2016 07:13:55 +0000 (09:13 +0200)
 - Issue: #1046

src/lua/lua_task.c

index 44a6a6d40910b4052d7f708fd3722192aa072b41..679e7b002fa1a95d14eb395eb269151059f842f4 100644 (file)
@@ -118,6 +118,16 @@ local function cb(task)
 end
  */
 LUA_FUNCTION_DEF (task, set_pre_result);
+/***
+ * @method task:append_message(message)
+ * Adds a message to scanning output.
+ * @param {string} message
+@example
+local function cb(task)
+       task:append_message('Example message')
+end
+ */
+LUA_FUNCTION_DEF (task, append_message);
 /***
  * @method task:get_urls([need_emails])
  * Get all URLs found in a message.
@@ -694,6 +704,7 @@ static const struct luaL_reg tasklib_m[] = {
        LUA_INTERFACE_DEF (task, get_ev_base),
        LUA_INTERFACE_DEF (task, insert_result),
        LUA_INTERFACE_DEF (task, set_pre_result),
+       LUA_INTERFACE_DEF (task, append_message),
        LUA_INTERFACE_DEF (task, has_urls),
        LUA_INTERFACE_DEF (task, get_urls),
        LUA_INTERFACE_DEF (task, get_content),
@@ -1108,6 +1119,24 @@ lua_task_set_pre_result (lua_State * L)
        return 0;
 }
 
+static gint
+lua_task_append_message (lua_State * L)
+{
+       struct rspamd_task *task = lua_check_task (L, 1);
+       gchar *message;
+
+       if (task != NULL) {
+               message= rspamd_mempool_strdup (task->task_pool,
+                               luaL_checkstring (L, 2));
+               task->messages = g_list_prepend (task->messages, message);
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 0;
+}
+
 struct lua_tree_cb_data {
        lua_State *L;
        int i;