diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-13 12:52:23 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-13 12:52:23 +0000 |
commit | 404a439fef09567b522a4dc9fa9cb19dbad94bf7 (patch) | |
tree | cf8f26a6fddcbbc479f3cfcda10a48febd47bbc6 /rules/global_functions.lua | |
parent | ce8352554afa648b81400e3267587e22705b08cf (diff) | |
download | rspamd-404a439fef09567b522a4dc9fa9cb19dbad94bf7.tar.gz rspamd-404a439fef09567b522a4dc9fa9cb19dbad94bf7.zip |
[Feature] Implement received headers flags
Diffstat (limited to 'rules/global_functions.lua')
-rw-r--r-- | rules/global_functions.lua | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/rules/global_functions.lua b/rules/global_functions.lua index f98587b47..439854f28 100644 --- a/rules/global_functions.lua +++ b/rules/global_functions.lua @@ -307,17 +307,19 @@ local function meta_received_function(task) local invalid_factor = 0 local rh = task:get_received_headers() local time_factor = 0 - local tls_factor = 0 + local secure_factor = 0 + local fun = require "fun" if rh and #rh > 0 then - local ntotal = 1.0 * #rh - count_factor = 1.0 / ntotal + local ntotal = 0.0 local init_time = 0 - for _,rc in ipairs(rh) do + fun.each(function(rc) + ntotal = ntotal + 1.0 + if not rc.by_hostname then - invalid_factor = invalid_factor + 1 + invalid_factor = invalid_factor + 1.0 end if init_time == 0 and rc.timestamp then init_time = rc.timestamp @@ -325,20 +327,22 @@ local function meta_received_function(task) time_factor = time_factor + math.abs(init_time - rc.timestamp) init_time = rc.timestamp end - if rc.proto and (rc.proto == 'esmtps') then - tls_factor = tls_factor + 1 + if rc.flags and (rc.flags['ssl'] or rc.flags['authenticated']) then + secure_factor = secure_factor + 1.0 end - end + end, + fun.filter(function(rc) return not rc.flags or not rc.flags['artificial'] end, rh)) invalid_factor = invalid_factor / ntotal - tls_factor = tls_factor / ntotal + secure_factor = secure_factor / ntotal + count_factor = 1.0 / ntotal if time_factor ~= 0 then time_factor = 1.0 / time_factor end end - return {count_factor, invalid_factor, time_factor, tls_factor} + return {count_factor, invalid_factor, time_factor, secure_factor} end local function meta_urls_function(task) |