From: Vsevolod Stakhov Date: Sun, 23 Sep 2018 14:34:50 +0000 (+0100) Subject: [Feature] Support selectors in settings X-Git-Tag: 1.8.0~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c90615aec8e1f477096e3e8a42ce6000169c4787;p=rspamd.git [Feature] Support selectors in settings --- diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index f25714b0e..970062d3b 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -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}