]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support selectors in settings
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 23 Sep 2018 14:34:50 +0000 (15:34 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 23 Sep 2018 14:34:50 +0000 (15:34 +0100)
src/plugins/lua/settings.lua

index f25714b0e44266bb066a95471314d8dc7873b5cd..970062d3b71cc0f0a4dae076820c1383fb346cb1 100644 (file)
@@ -28,6 +28,7 @@ local lua_squeeze = require "lua_squeeze_rules"
 local lua_util = require "lua_util"
 local rspamd_ip = require "rspamd_ip"
 local rspamd_regexp = require "rspamd_regexp"
+local lua_selectors = require "lua_selectors"
 local ucl = require "ucl"
 local fun = require "fun"
 
@@ -39,6 +40,8 @@ local settings_ids = {}
 local settings_initialized = false
 local max_pri = 0
 
+local selectors_cache = {} -- Used to speed up selectors in settings
+
 local function apply_settings(task, to_apply)
   task:set_settings(to_apply)
   task:cache_set('settings', to_apply)
@@ -189,7 +192,7 @@ local function check_settings(task)
     return false
   end
 
-  local function check_specific_setting(_, rule, ip, client_ip, from, rcpt,
+  local function check_specific_setting(rule_name, rule, ip, client_ip, from, rcpt,
       user, auth_user)
     local res = false
 
@@ -313,6 +316,24 @@ local function check_settings(task)
       end
     end
 
+    if rule['selector'] then
+      local sel = selectors_cache[rule_name]
+      if not sel then
+        sel = lua_selectors.create_selector_closure(rspamd_config, rule.selector,
+            rule.delimiter or "")
+
+        if sel then
+          selectors_cache[rule_name] = sel
+        end
+      end
+
+      if sel then
+        if sel(task) then
+          res = true
+        end
+      end
+    end
+
     if res then
       if rule['whitelist'] then
         rule['apply'] = {whitelist = true}