From: Vsevolod Stakhov Date: Fri, 6 Mar 2015 13:30:32 +0000 (+0000) Subject: More fixes to SA plugin. X-Git-Tag: 0.9.0~541 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=453645aa3766bd1e5df8d9bb076f78bf3604e1d8;p=rspamd.git More fixes to SA plugin. --- diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 4fdf4a236..d535f0a1e 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1171,6 +1171,7 @@ static gint lua_config_set_metric_symbol (lua_State * L) { struct rspamd_config *cfg = lua_check_config (L); + GList *metric_list; gchar *name; const gchar *metric_name = DEFAULT_METRIC, *description = NULL; double weight; @@ -1181,10 +1182,10 @@ lua_config_set_metric_symbol (lua_State * L) name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); weight = luaL_checknumber (L, 3); - if (lua_gettop (L) > 3) { + if (lua_gettop (L) > 3 && lua_type (L, 4) == LUA_TSTRING) { description = luaL_checkstring (L, 4); } - if (lua_gettop (L) > 4) { + if (lua_gettop (L) > 4 && lua_type (L, 5) == LUA_TSTRING) { metric_name = luaL_checkstring (L, 5); } @@ -1210,7 +1211,20 @@ lua_config_set_metric_symbol (lua_State * L) } g_hash_table_insert (metric->symbols, s->name, s); - g_hash_table_insert (cfg->metrics_symbols, s->name, metric); + if ((metric_list = + g_hash_table_lookup (cfg->metrics_symbols, s->name)) == NULL) { + metric_list = g_list_prepend (NULL, metric); + rspamd_mempool_add_destructor (cfg->cfg_pool, + (rspamd_mempool_destruct_t)g_list_free, + metric_list); + g_hash_table_insert (cfg->metrics_symbols, s->name, metric_list); + } + else { + /* Slow but keep start element of list in safe */ + if (!g_list_find (metric_list, metric)) { + metric_list = g_list_append (metric_list, metric); + } + } } *s->weight_ptr = weight; diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index cb5bbb842..110c985ff 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -200,7 +200,7 @@ local function process_sa_conf(f) elseif words[1] == "describe" and valid_rule then cur_rule['description'] = words_to_re(words, 1) elseif words[1] == "score" and valid_rule then - cur_rule['score'] = tonumber(words_to_re(words, 1)[1]) + cur_rule['score'] = tonumber(words_to_re(words, 2)) end end)() end @@ -230,10 +230,10 @@ end -- Meta rules _.each(function(k, r) - rspamd_config:add_composite(k, r['meta']) if r['score'] then rspamd_config:set_metric_symbol(k, r['score'], r['description']) end + rspamd_config:add_composite(k, r['meta']) end, _.filter(function(k, r) return r['type'] == 'meta' @@ -268,10 +268,10 @@ _.each(function(k, r) task:insert_result(k, 1.0) end end - rspamd_config:register_symbol(k, calculate_score(k), f) if r['score'] then rspamd_config:set_metric_symbol(k, r['score'], r['description']) end + rspamd_config:register_symbol(k, calculate_score(k), f) end, _.filter(function(k, r) return r['type'] == 'header' and r['header'] @@ -286,10 +286,10 @@ _.each(function(k, r) task:insert_result(k, 1.0) end end - rspamd_config:register_symbol(k, calculate_score(k), f) if r['score'] then rspamd_config:set_metric_symbol(k, r['score'], r['description']) end + rspamd_config:register_symbol(k, calculate_score(k), f) end, _.filter(function(k, r) return r['type'] == 'function' and r['function'] @@ -299,21 +299,22 @@ _.each(function(k, r) -- Parts rules _.each(function(k, r) local f = function(task) - local parts = task:get_parts() + local parts = task:get_text_parts() if parts then for n, part in ipairs(parts) do -- Subject for optimization if (r['re']:match(part:get_content())) then + local s = r['re']:search(part:get_content()) task:insert_result(k, 1.0) return end end end end - rspamd_config:register_symbol(k, calculate_score(k), f) if r['score'] then rspamd_config:set_metric_symbol(k, r['score'], r['description']) end + rspamd_config:register_symbol(k, calculate_score(k), f) end, _.filter(function(k, r) return r['type'] == 'part' @@ -328,10 +329,10 @@ _.each(function(k, r) return end end - rspamd_config:register_symbol(k, calculate_score(k), f) if r['score'] then rspamd_config:set_metric_symbol(k, r['score'], r['description']) end + rspamd_config:register_symbol(k, calculate_score(k), f) end, _.filter(function(k, r) return r['type'] == 'message'