]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Rework HAS_X_PRIO rule to match symbols conventions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 11 Mar 2017 14:06:05 +0000 (14:06 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 11 Mar 2017 14:06:05 +0000 (14:06 +0000)
rules/headers_checks.lua
rules/misc.lua

index 18785234eb5fc4092d1abafe0df5bd9fce92ad62..b8d4bd872977d8bea99ab26fb846c40968014e89 100644 (file)
@@ -107,16 +107,71 @@ rspamd_config:register_symbol{
   group = 'header',
 }
 
-rspamd_config.HAS_X_PRIO = {
+local prio_cb_id = rspamd_config:register_symbol {
+  name = 'HAS_X_PRIO',
+  type = 'callback',
   callback = function (task)
+     local cnts = {
+      [1] = 'ONE',
+      [2] = 'TWO',
+      [3] = 'THREE',
+      [5] = 'FIVE',
+    }
+    local def = 'ZERO'
     local xprio = task:get_header('X-Priority');
     if not xprio then return false end
     local _,_,x = xprio:find('^%s?(%d+)');
     if (x) then
-      task:insert_result('HAS_X_PRIO_' .. x, 1.0)
+      x = tonumber(x)
+      for k,v in pairs(cnts) do
+        if x >= tonumber(k) then
+          def = v
+        end
+      end
+      task:insert_result('HAS_X_PRIO_' .. def, 1.0, tostring(x))
     end
   end
 }
+rspamd_config:register_symbol{
+  name = 'HAS_X_PRIO_ZERO',
+  score = 0.0,
+  parent = prio_cb_id,
+  type = 'virtual',
+  description = 'Priority 0',
+  group = 'header',
+}
+rspamd_config:register_symbol{
+  name = 'HAS_X_PRIO_ONE',
+  score = 0.0,
+  parent = prio_cb_id,
+  type = 'virtual',
+  description = 'Priority 1',
+  group = 'header',
+}
+rspamd_config:register_symbol{
+  name = 'HAS_X_PRIO_TWO',
+  score = 0.0,
+  parent = prio_cb_id,
+  type = 'virtual',
+  description = 'Priority 2',
+  group = 'header',
+}
+rspamd_config:register_symbol{
+  name = 'HAS_X_PRIO_THREE',
+  score = 0.0,
+  parent = prio_cb_id,
+  type = 'virtual',
+  description = 'Priority 3-4',
+  group = 'header',
+}
+rspamd_config:register_symbol{
+  name = 'HAS_X_PRIO_FIVE',
+  score = 0.0,
+  parent = prio_cb_id,
+  type = 'virtual',
+  description = 'Priority 5+',
+  group = 'header',
+}
 
 local check_replyto_id = rspamd_config:register_callback_symbol('CHECK_REPLYTO', 1.0,
   function (task)
index 66b1b90abe448a0963f021a72b7475cbe6f34245..a9382f8f469f6d5f0c664cd9602e7f70b3f7d98a 100644 (file)
@@ -19,6 +19,7 @@ limitations under the License.
 local E = {}
 local fun = require "fun"
 local util = require "rspamd_util"
+local rspamd_regexp = require "rspamd_regexp"
 
 -- Different text parts
 rspamd_config.R_PARTS_DIFFER = {