]> source.dussan.org Git - rspamd.git/commitdiff
Revert "[Fix] Remove incorrect method `task:set_metric_subject`"
authorAndrew Lewis <nerf@judo.za.org>
Thu, 7 Sep 2017 19:49:48 +0000 (21:49 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 7 Sep 2017 19:49:48 +0000 (21:49 +0200)
This reverts commit e809039a9e84cb6235a6447d1c9c8fc34ddcf8c6.

src/libserver/cfg_file.h
src/lua/lua_task.c

index 48f352f499c9ee792c1c21b4e875060558cf450a..d96c6e474605fb664529261b1672cfff23f461f4 100644 (file)
@@ -269,7 +269,7 @@ struct rspamd_metric {
        gdouble unknown_weight;                         /**< weight of unknown symbols                                          */
        gdouble grow_factor;                            /**< grow factor for metric                                                     */
        GHashTable *symbols;                            /**< weights of symbols in metric                                       */
-       const gchar *subject;                           /**< subject rewrite string                                                     */
+       gchar *subject;                                 /**< subject rewrite string                                                     */
        GHashTable * groups;                                /**< groups of symbols                                                              */
        struct metric_action actions[METRIC_ACTION_MAX]; /**< all actions of the metric                                         */
 };
index 2f5883563dc26d394ce1cee51626618f3446c871..9d139044fc8a6c6d3b90ea6bc48dc96a0cc297f9 100644 (file)
@@ -586,6 +586,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)
@@ -880,6 +886,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),
@@ -4068,6 +4075,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 = rspamd_mempool_strdup (task->task_pool, subject);
+               lua_pushboolean (L, true);
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 static gint
 lua_task_get_protocol_reply (lua_State *L)
 {