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;
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);
}
}
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;
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
-- 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'
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']
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']
-- 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'
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'