From: Vsevolod Stakhov Date: Mon, 8 Aug 2016 13:16:55 +0000 (+0100) Subject: [Feature] Try to avoid FP for low contrast fonts detection X-Git-Tag: 1.3.2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=842f6c31ca5d1a2154efcd8795ae7142f22d191c;p=rspamd.git [Feature] Try to avoid FP for low contrast fonts detection --- diff --git a/rules/html.lua b/rules/html.lua index 955d5a42e..1c4c86cdc 100644 --- a/rules/html.lua +++ b/rules/html.lua @@ -170,6 +170,8 @@ rspamd_config.R_WHITE_ON_WHITE = { local tp = task:get_text_parts() -- get text parts in a message local ret = false local diff = 0.0 + local normal_len = 0 + local transp_tags = {} 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 @@ -189,7 +191,9 @@ rspamd_config.R_WHITE_ON_WHITE = { if diff < 0.2 then ret = true - return true + table.insert(transp_tags, tag) + else + normal_len = normal_len + tag:get_content_length() end end end @@ -201,7 +205,27 @@ rspamd_config.R_WHITE_ON_WHITE = { end if ret then - return true,(0.2 - diff) * 5.0,tostring(diff * 100.0) + local transp_len = 0 + local arg + + for _,t in ipairs(transp_tags) do + local bl = t:get_extra() + local color = bl['color'] + local bgcolor = bl['bgcolor'] + transp_len = transp_len + t:get_content_length() + + if not arg then + arg = string.format('%s color #%x%x%x bgcolor #%x%x%x', + tostring(t:get_type()), + color[1], color[2], color[3], + bgcolor[1], bgcolor[2], bgcolor[3]) + end + end + + local transp_rate = transp_len / (normal_len + transp_len) + if transp_rate > 0.1 then + return true,(transp_rate * 2.0),arg + end end return false