]> source.dussan.org Git - rspamd.git/commitdiff
More fixes to SA plugin.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Mar 2015 13:30:32 +0000 (13:30 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Mar 2015 13:30:32 +0000 (13:30 +0000)
src/lua/lua_config.c
src/plugins/lua/spamassassin.lua

index 4fdf4a2363e97c25dc7f7b7cdd24b8e9380984f2..d535f0a1e7e260e86dfce11ea1a16cbfac596e25 100644 (file)
@@ -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;
index cb5bbb842e60fdfc6d301bbcd348f3ba1adf1077..110c985ff0b0b53d52bf7dfa75a28e5ed3134375 100644 (file)
@@ -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'