]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Use verdict instead of the plain action in plugins
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Oct 2018 14:56:38 +0000 (15:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Oct 2018 15:24:15 +0000 (16:24 +0100)
src/plugins/lua/clustering.lua
src/plugins/lua/ratelimit.lua
src/plugins/lua/reputation.lua

index d6c78ef79663afb323949b1dfd4f467f4c316966..2711c0658b5dba04c0d6ef0c1fbab2d0f68eb937 100644 (file)
@@ -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
 
index 61d19966bf5aeec5640505d2fe8f2baf5d59deb8..f0445642ed97f8658f70d9842f3bbfb36dc4f535 100644 (file)
@@ -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,
index 7831f277031b6ae269624aedcf36429de5d7996f..cfa72e226efaf957c5d09878dc123e0ddca37579 100644 (file)
@@ -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,