aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-15 15:56:38 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-15 16:24:15 +0100
commit01ef5c03a62209a307b9ae355993c78fc909acbc (patch)
treee1bd21b18722763dce2a476958e7269a74b3bfd5 /src
parent612020039653739f93e64cf5389abbed031bceeb (diff)
downloadrspamd-01ef5c03a62209a307b9ae355993c78fc909acbc.tar.gz
rspamd-01ef5c03a62209a307b9ae355993c78fc909acbc.zip
[Feature] Use verdict instead of the plain action in plugins
Diffstat (limited to 'src')
-rw-r--r--src/plugins/lua/clustering.lua12
-rw-r--r--src/plugins/lua/ratelimit.lua11
-rw-r--r--src/plugins/lua/reputation.lua62
3 files changed, 41 insertions, 44 deletions
diff --git a/src/plugins/lua/clustering.lua b/src/plugins/lua/clustering.lua
index d6c78ef79..2711c0658 100644
--- a/src/plugins/lua/clustering.lua
+++ b/src/plugins/lua/clustering.lua
@@ -186,18 +186,18 @@ local function clusterting_filter_cb(task, rule)
end
local function clusterting_idempotent_cb(task, rule)
- local action = task:get_action()
+ local verdict = lua_util.get_task_verdict(task)
local score
- if action == 'no action' then
+ if verdict == 'ham' then
score = rule.ham_mult
- elseif action == 'reject' then
+ elseif verdict == 'spam' then
score = rule.spam_mult
- elseif action == 'add header' or action == 'rewrite subject' then
+ elseif verdict == 'junk' then
score = rule.junk_mult
else
- rspamd_logger.debugm(N, task, 'skip rule %s, action=%s',
- rule.name, action)
+ rspamd_logger.debugm(N, task, 'skip rule %s, verdict=%s',
+ rule.name, verdict)
return
end
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index 61d19966b..f0445642e 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -596,7 +596,7 @@ local function ratelimit_update_cb(task)
return
end
- local is_spam = not (task:get_metric_action() == 'no action')
+ local verdict = lua_util.get_task_verdict(task)
-- Update each bucket
for k, v in pairs(prefixes) do
@@ -615,12 +615,15 @@ local function ratelimit_update_cb(task)
end
local now = rspamd_util.get_time()
now = lua_util.round(now * 1000.0) -- Get milliseconds
- local mult_burst = bucket.ham_factor_burst or 1.0
- local mult_rate = bucket.ham_factor_burst or 1.0
+ local mult_burst = 1.0
+ local mult_rate = 1.0
- if is_spam then
+ if verdict == 'spam' or verdict == 'junk' then
mult_burst = bucket.spam_factor_burst or 1.0
mult_rate = bucket.spam_factor_rate or 1.0
+ elseif verdict == 'ham' then
+ mult_burst = bucket.ham_factor_burst or 1.0
+ mult_rate = bucket.ham_factor_rate or 1.0
end
lua_redis.exec_redis_script(bucket_update_id,
diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua
index 7831f2770..cfa72e226 100644
--- a/src/plugins/lua/reputation.lua
+++ b/src/plugins/lua/reputation.lua
@@ -38,10 +38,9 @@ local redis_params = nil
local default_expiry = 864000 -- 10 day by default
local keymap_schema = ts.shape{
- ['reject'] = ts.string,
- ['add header'] = ts.string,
- ['rewrite subject'] = ts.string,
- ['no action'] = ts.string
+ ['spam'] = ts.string,
+ ['junk'] = ts.string,
+ ['ham'] = ts.string,
}
-- Get reputation from ham/spam/probable hits
@@ -165,14 +164,14 @@ local function dkim_reputation_filter(task, rule)
end
local function dkim_reputation_idempotent(task, rule)
- local action = task:get_metric_action()
+ local verdict = lua_util.get_task_verdict()
local token = {
}
local cfg = rule.selector.config
local need_set = false
-- TODO: take metric score into consideration
- local k = cfg.keys_map[action]
+ local k = cfg.keys_map[verdict]
if k then
token[k] = 1.0
@@ -218,10 +217,9 @@ local dkim_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
- ['reject'] = 's',
- ['add header'] = 'p',
- ['rewrite subject'] = 'p',
- ['no action'] = 'h'
+ ['spam'] = 's',
+ ['junk'] = 'p',
+ ['ham'] = 'h'
},
symbol = 'DKIM_SCORE', -- symbol to be inserted
lower_bound = 10, -- minimum number of messages to be scored
@@ -312,14 +310,14 @@ local function url_reputation_filter(task, rule)
end
local function url_reputation_idempotent(task, rule)
- local action = task:get_metric_action()
+ local verdict = lua_util.get_task_verdict(task)
local token = {
}
local cfg = rule.selector.config
local need_set = false
-- TODO: take metric score into consideration
- local k = cfg.keys_map[action]
+ local k = cfg.keys_map[verdict]
if k then
token[k] = 1.0
@@ -343,10 +341,9 @@ local url_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
- ['reject'] = 's',
- ['add header'] = 'p',
- ['rewrite subject'] = 'p',
- ['no action'] = 'h'
+ ['spam'] = 's',
+ ['junk'] = 'p',
+ ['ham'] = 'h'
},
symbol = 'URL_SCORE', -- symbol to be inserted
lower_bound = 10, -- minimum number of messages to be scored
@@ -509,13 +506,13 @@ local function ip_reputation_idempotent(task, rule)
end
end
- local action = task:get_metric_action()
+ local verdict = lua_util.get_task_verdict(task)
local token = {
}
local need_set = false
-- TODO: take metric score into consideration
- local k = cfg.keys_map[action]
+ local k = cfg.keys_map[verdict]
if k then
token[k] = 1.0
@@ -545,10 +542,9 @@ local ip_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
- ['reject'] = 's',
- ['add header'] = 'p',
- ['rewrite subject'] = 'p',
- ['no action'] = 'h'
+ ['spam'] = 's',
+ ['junk'] = 'p',
+ ['ham'] = 'h'
},
scores = { -- how each component is evaluated
['asn'] = 0.4,
@@ -603,7 +599,7 @@ local function spf_reputation_filter(task, rule)
end
local function spf_reputation_idempotent(task, rule)
- local action = task:get_metric_action()
+ local verdict = lua_util.get_task_verdict(task)
local spf_record = task:get_mempool():get_variable('spf_record')
local spf_allow = task:has_symbol('R_SPF_ALLOW')
local token = {
@@ -614,7 +610,7 @@ local function spf_reputation_idempotent(task, rule)
if not spf_record or not spf_allow then return end
-- TODO: take metric score into consideration
- local k = cfg.keys_map[action]
+ local k = cfg.keys_map[verdict]
if k then
token[k] = 1.0
@@ -639,10 +635,9 @@ local spf_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
- ['reject'] = 's',
- ['add header'] = 'p',
- ['rewrite subject'] = 'p',
- ['no action'] = 'h'
+ ['spam'] = 's',
+ ['junk'] = 'p',
+ ['ham'] = 'h'
},
symbol = 'SPF_SCORE', -- symbol to be inserted
lower_bound = 10, -- minimum number of messages to be scored
@@ -718,7 +713,7 @@ local function generic_reputation_filter(task, rule)
end
local function generic_reputation_idempotent(task, rule)
- local action = task:get_metric_action()
+ local verdict = lua_util.get_task_verdict(task)
local cfg = rule.selector.config
local need_set = false
local token = {}
@@ -726,7 +721,7 @@ local function generic_reputation_idempotent(task, rule)
local selector_res = cfg.selector(task)
if not selector_res then return end
- local k = cfg.keys_map[action]
+ local k = cfg.keys_map[verdict]
if k then
token[k] = 1.0
@@ -767,10 +762,9 @@ local generic_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
- ['reject'] = 's',
- ['add header'] = 'p',
- ['rewrite subject'] = 'p',
- ['no action'] = 'h'
+ ['spam'] = 's',
+ ['junk'] = 'p',
+ ['ham'] = 'h'
},
lower_bound = 10, -- minimum number of messages to be scored
min_score = nil,