Browse Source

Rework FORGED_RECIPIENTS for common users

tags/1.1.0
Vsevolod Stakhov 8 years ago
parent
commit
64e6d18a31
1 changed files with 11 additions and 6 deletions
  1. 11
    6
      src/plugins/lua/forged_recipients.lua

+ 11
- 6
src/plugins/lua/forged_recipients.lua View File

local function check_forged_headers(task) local function check_forged_headers(task)
local smtp_rcpt = task:get_recipients(1) local smtp_rcpt = task:get_recipients(1)
local res = false local res = false
local score = 1.0

if smtp_rcpt then if smtp_rcpt then
local mime_rcpt = task:get_recipients(2) local mime_rcpt = task:get_recipients(2)
local count = 0 local count = 0
if mime_rcpt then
if mime_rcpt then
count = table.maxn(mime_rcpt) count = table.maxn(mime_rcpt)
end end
if count > 0 and count < table.maxn(smtp_rcpt) then if count > 0 and count < table.maxn(smtp_rcpt) then
if string.lower(mr['addr']) == string.lower(sr['addr']) then if string.lower(mr['addr']) == string.lower(sr['addr']) then
res = true res = true
break break
elseif string.lower(mr['user']) == string.lower(sr['user']) then
-- If we have the same username but for another domain, then
-- lower the overall score
score = score / 2
end end
end end
end end
if not res then if not res then
task:insert_result(symbol_rcpt, 1)
task:insert_result(symbol_rcpt, score)
break break
end end
end end
local smtp_from = task:get_from(1) local smtp_from = task:get_from(1)
if smtp_from and smtp_from[1] and smtp_from[1]['addr'] ~= '' then if smtp_from and smtp_from[1] and smtp_from[1]['addr'] ~= '' then
local mime_from = task:get_from(2) local mime_from = task:get_from(2)
if not mime_from or not mime_from[1] or
if not mime_from or not mime_from[1] or
not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then
task:insert_result(symbol_sender, 1) task:insert_result(symbol_sender, 1)
end end
local opts = rspamd_config:get_all_opt('forged_recipients') local opts = rspamd_config:get_all_opt('forged_recipients')
if opts then if opts then
if opts['symbol_rcpt'] or opts['symbol_sender'] then if opts['symbol_rcpt'] or opts['symbol_sender'] then
local id = rspamd_config:register_callback_symbol(1.0,
local id = rspamd_config:register_callback_symbol(1.0,
check_forged_headers) check_forged_headers)
if opts['symbol_rcpt'] then if opts['symbol_rcpt'] then
symbol_rcpt = opts['symbol_rcpt'] symbol_rcpt = opts['symbol_rcpt']
rspamd_config:register_virtual_symbol(symbol_sender, 1.0, id) rspamd_config:register_virtual_symbol(symbol_sender, 1.0, id)
end end
end end
end
end

Loading…
Cancel
Save