end
-- MAILFROM checks --
- local from = task:get_from()
+ local from = task:get_from(1)
if from then
--FROM host check
for _,fr in ipairs(from) do
-- More 5 recipients
local st_many = classifier:get_statfile_by_label(many_recipients_label)
if st_many then
- rcpt = task:get_recipients()
+ rcpt = task:get_recipients(2)
if rcpt and table.maxn(rcpt) > 5 then
print(table.maxn(rcpt))
table.foreach(st_many, function(i,v) table.insert(spec_st,v) end)
-- Undisclosed
local st_undisc = classifier:get_statfile_by_label(undisclosed_recipients_label)
if st_undisc then
- rcpt = task:get_recipients()
+ rcpt = task:get_recipients(2)
if rcpt and table.maxn(rcpt) == 0 then
table.foreach(st_undisc, function(i,v) table.insert(spec_st,v) end)
end
function check_forged_headers(task)
local msg = task:get_message()
- local smtp_rcpt = task:get_recipients()
+ local smtp_rcpt = task:get_recipients(1)
local res = false
if smtp_rcpt then
- local mime_rcpt = task:get_recipients_headers()
+ local mime_rcpt = task:get_recipients(2)
local count = 0
if mime_rcpt then
count = table.maxn(mime_rcpt)
end
end
-- Check sender
- local smtp_from = task:get_from()
+ local smtp_from = task:get_from(1)
if smtp_from then
- local mime_from = task:get_from_headers()
+ local mime_from = task:get_from(2)
if not mime_from or not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then
task:insert_result(symbol_sender, 1)
end
end
end
end
- else
- -- Get from headers
- local rcpts = task:get_recipients_headers()
- if rcpts then
- for _,r in ipairs(rcpts) do
- if r['addr'] then
- if rule['pattern'] then
- -- extract a part from header
- local _,_,ext = string.find(r['addr'], rule['pattern'])
- if ext then
- if rule['cdb'] then
- if rule['hash']:lookup(ext) then
- task:insert_result(rule['symbol'], 1)
- end
- else
- if rule['hash']:get_key(ext) then
- task:insert_result(rule['symbol'], 1)
- end
- end
- end
- else
- if rule['cdb'] then
- if rule['hash']:lookup(r['addr']) then
- task:insert_result(rule['symbol'], 1)
- end
- else
- if rule['hash']:get_key(r['addr']) then
- task:insert_result(rule['symbol'], 1)
- end
- end
- end
- end
- end
- end
end
elseif rule['type'] == 'from' then
-- First try to get from field
end
end
end
- else
- -- Get from headers
- local from = task:get_from_headers()
- if from then
- for _,r in ipairs(from) do
- if r['addr'] then
- if rule['pattern'] then
- -- extract a part from header
- local _,_,ext = string.find(r['addr'], rule['pattern'])
- if ext then
- if rule['cdb'] then
- if rule['hash']:lookup(ext) then
- task:insert_result(rule['symbol'], 1)
- end
- else
- if rule['hash']:get_key(ext) then
- task:insert_result(rule['symbol'], 1)
- end
- end
- end
- else
- if rule['cdb'] then
- if rule['hash']:lookup(r['addr']) then
- task:insert_result(rule['symbol'], 1)
- end
- else
- if rule['hash']:get_key(r['addr']) then
- task:insert_result(rule['symbol'], 1)
- end
- end
- end
- end
- end
- end
end
end
end
--- Called when value was set on server
local function rate_set_key_cb(task, err, data)
if err then
+ rspamd_logger.info('got error while getting limit: ' .. err)
upstream:fail()
else
upstream:ok()
end
end
if err then
+ rspamd_logger.info('got error while getting limit: ' .. err)
upstream:fail()
end
end
--- Called when value was set on server
local function rate_set_key_cb(task, err, data)
if err then
+ rspamd_logger.info('got error while setting limit: ' .. err)
upstream:fail()
else
upstream:ok()
rspamd_redis.make_request(task, upstream:get_ip_string(), upstream:get_port(), rate_set_key_cb,
'SET %b %b', key, lstr)
elseif err then
+ rspamd_logger.info('got error while setting limit: ' .. err)
upstream:fail()
end
end
--- Check or update ratelimit
local function rate_test_set(task, func)
-
- -- Returns local part component of address
- local function get_local_part(str)
- pos,_ = string.find(str, '@', 0, true)
- if not pos then
- return str
- else
- return string.sub(str, 1, pos - 1)
- end
- end
-
-- Get initial task data
local ip = task:get_from_ip()
if ip and whitelisted_ip then
-- Parse all rcpts
local rcpts = task:get_recipients()
local rcpts_user = {}
- if not rcpts then
- rcpts = task:get_recipients_headers()
- end
if rcpts then
if table.maxn(rcpts) > max_rcpt then
rspamd_logger.info(string.format('message <%s> contains %d recipients, maximum is %d',
return
end
for i,r in ipairs(rcpts) do
- rcpts_user[i] = get_local_part(r['addr'])
+ rcpts_user[i] = r['user']
end
end
-- Parse from
local from = task:get_from()
local from_user = ''
- if not from then
- from = task:get_from_headers()
- end
if from then
- from_user = get_local_part(from[1]['addr'])
+ from_user = from[1]['user']
end
-- Get user (authuser)
local auser = task:get_user()
if auser then
func(task, settings['user'], make_rate_key (auser, '<auth>', nil))
end
-
+
if not from_user or not rcpts_user[1] then
-- Nothing to check
return