diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-02 22:52:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-02 22:52:26 +0000 |
commit | ad32f0d9d61cd402d8cb8fe78e9abef1cd89871b (patch) | |
tree | fb78bd1a51a26f275f2f8c4d2214e849c59fc4a5 | |
parent | cc213ec128c77f5c8349f25cc00e7c4d3494a912 (diff) | |
parent | f429c7ec0818b69cc8198d0756d4aab1a57be137 (diff) | |
download | rspamd-ad32f0d9d61cd402d8cb8fe78e9abef1cd89871b.tar.gz rspamd-ad32f0d9d61cd402d8cb8fe78e9abef1cd89871b.zip |
Merge pull request #1392 from fatalbanana/urlr
[Minor] URL reputation: fallback to tags to try gauge relevance
-rw-r--r-- | src/plugins/lua/url_reputation.lua | 94 |
1 files changed, 64 insertions, 30 deletions
diff --git a/src/plugins/lua/url_reputation.lua b/src/plugins/lua/url_reputation.lua index 85f5bc9f1..952093a62 100644 --- a/src/plugins/lua/url_reputation.lua +++ b/src/plugins/lua/url_reputation.lua @@ -36,6 +36,11 @@ local settings = { dkim = 'R_DKIM_ALLOW', spf = 'R_SPF_ALLOW', }, + ignore_surbl = { + URIBL_BLOCKED = true, + DBL_PROHIBIT = true, + SURBL_BLOCKED = true, + }, -- how many messages to score reputation threshold = 5, -- set reputation for only so many TLDs @@ -345,39 +350,68 @@ local function tags_save(task) else -- No reputation found, pick some URLs local most_relevant + if tld_count == 1 then + most_relevant = next(tlds) + end if settings.relevance then - -- XXX: blacklist for non-relevant identifiers (gmail etc) - local dmarc = ((task:get_symbol(settings.foreign_symbols['dmarc']) or E)[1] or E).options - local dkim = ((task:get_symbol(settings.foreign_symbols['dkim']) or E)[1] or E).options - local spf = task:get_symbol(settings.foreign_symbols['spf']) - local hostname = task:get_hostname() - if hostname then - hostname = rspamd_util.get_tld(hostname) - end - if spf then - local from = task:get_from(1) - if ((from or E)[1] or E).domain then - spf = rspamd_util.get_tld(from[1]['domain']) - else - local helo = task:get_helo() - if helo then - spf = rspamd_util.get_tld(helo) + if not most_relevant then + -- XXX: blacklist for non-relevant identifiers (gmail etc) + local dmarc = ((task:get_symbol(settings.foreign_symbols['dmarc']) or E)[1] or E).options + local dkim = ((task:get_symbol(settings.foreign_symbols['dkim']) or E)[1] or E).options + local spf = task:get_symbol(settings.foreign_symbols['spf']) + local hostname = task:get_hostname() + if hostname then + hostname = rspamd_util.get_tld(hostname) + end + if spf then + local from = task:get_from(1) + if ((from or E)[1] or E).domain then + spf = rspamd_util.get_tld(from[1]['domain']) + else + local helo = task:get_helo() + if helo then + spf = rspamd_util.get_tld(helo) + end end end - end - for _, t in ipairs(tlds) do - if t == dmarc then - most_relevant = t - break - elseif t == dkim then - most_relevant = t - break - elseif t == spf then - most_relevant = t - break - elseif t == hostname then - most_relevant = t - break + for _, t in ipairs(tlds) do + if t == dmarc then + most_relevant = t + break + elseif t == dkim then + most_relevant = t + break + elseif t == spf then + most_relevant = t + break + elseif t == hostname then + most_relevant = t + break + end + end + if not most_relevant and reputation >= 3 then + -- no authenticated domain, count surbl tags + local max_surbl_guilt + for dom, tag in pairs(tags) do + local guilt = 0 + local stags = tag['surbl'] + if stags then + for k in pairs(stags) do + if not settings.ignore_surbl[k] then + guilt = guilt + 1 + end + end + if guilt > 1 then + if not most_relevant then + most_relevant = dom + max_surbl_guilt = guilt + elseif guilt > max_surbl_guilt then + most_relevant = dom + max_surbl_guilt = guilt + end + end + end + end end end end |