]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support setting metric subject from Lua
authorAndrew Lewis <nerf@judo.za.org>
Wed, 15 Feb 2017 14:06:05 +0000 (16:06 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 15 Feb 2017 14:43:18 +0000 (16:43 +0200)
src/lua/lua_task.c

index 9b15eb2c0c0f91517300df98d4c64220935a2edd..af85282f2a97a76ee2aaf0948bff59af5f3bf7ab 100644 (file)
@@ -525,6 +525,12 @@ LUA_FUNCTION_DEF (task, set_metric_score);
  * @param {string} action name to set
  */
 LUA_FUNCTION_DEF (task, set_metric_action);
+/***
+ * @method task:set_metric_subject(subject)
+ * Set the subject in the default metric
+ * @param {string} subject subject to set
+ */
+LUA_FUNCTION_DEF (task, set_metric_subject);
 
 /***
  * @method task:learn(is_spam[, classifier)
@@ -764,6 +770,7 @@ static const struct luaL_reg tasklib_m[] = {
        LUA_INTERFACE_DEF (task, get_metric_action),
        LUA_INTERFACE_DEF (task, set_metric_score),
        LUA_INTERFACE_DEF (task, set_metric_action),
+       LUA_INTERFACE_DEF (task, set_metric_subject),
        LUA_INTERFACE_DEF (task, learn),
        LUA_INTERFACE_DEF (task, set_settings),
        LUA_INTERFACE_DEF (task, get_settings),
@@ -3407,6 +3414,27 @@ lua_task_set_metric_action (lua_State *L)
        return 1;
 }
 
+static gint
+lua_task_set_metric_subject (lua_State *L)
+{
+       struct rspamd_task *task = lua_check_task (L, 1);
+       const gchar *subject;
+       struct rspamd_metric *metric;
+
+       metric = task->cfg->default_metric;
+       subject = luaL_checkstring (L, 2);
+
+       if (task && metric && subject) {
+               metric->subject = subject;
+               lua_pushboolean (L, true);
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 /* Image functions */
 static gint
 lua_image_get_width (lua_State *L)