diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-05 16:05:54 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-05 16:06:22 +0100 |
commit | ad36a88b58202c9a4a899b7ffd51b4a9cb54c0ac (patch) | |
tree | ae1f7ccd13e026087c35e585879d0b942533f950 /rules/html.lua | |
parent | 4a6d929b11b35dd97f05e7c8c01e3dec7ed71849 (diff) | |
download | rspamd-ad36a88b58202c9a4a899b7ffd51b4a9cb54c0ac.tar.gz rspamd-ad36a88b58202c9a4a899b7ffd51b4a9cb54c0ac.zip |
[Feature] Properly implement R_WHITE_ON_WHITE rule
Diffstat (limited to 'rules/html.lua')
-rw-r--r-- | rules/html.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/rules/html.lua b/rules/html.lua index bab636322..955d5a42e 100644 --- a/rules/html.lua +++ b/rules/html.lua @@ -164,3 +164,50 @@ rspamd_config.R_SUSPICIOUS_IMAGES = { group = 'html', description = 'Message contains many suspicious messages' } + +rspamd_config.R_WHITE_ON_WHITE = { + callback = function(task) + local tp = task:get_text_parts() -- get text parts in a message + local ret = false + local diff = 0.0 + + for _,p in ipairs(tp) do -- iterate over text parts array using `ipairs` + if p:is_html() then -- if the current part is html part + local hc = p:get_html() -- we get HTML context + + hc:foreach_tag('font', function(tag, len) + local bl = tag:get_extra() + if bl then + if bl['bgcolor'] and bl['color'] then + local color = bl['color'] + local bgcolor = bl['bgcolor'] + -- Should use visual approach here some day + local diff_r = math.abs(color[1] - bgcolor[1]) / 255.0 + local diff_g = math.abs(color[2] - bgcolor[2]) / 255.0 + local diff_b = math.abs(color[3] - bgcolor[3]) / 255.0 + diff = (diff_r + diff_g + diff_b) / 3.0 + + if diff < 0.2 then + ret = true + return true + end + end + end + + return false -- Continue search + end) + + end + end + + if ret then + return true,(0.2 - diff) * 5.0,tostring(diff * 100.0) + end + + return false + end, + + score = 6.0, + group = 'html', + description = 'Message contains low contrast text' +} |