summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-08-18 15:56:33 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-08-18 15:56:33 +0100
commit244a9efad601be931eb71a689414be1d8bf70cea (patch)
tree7bd2ec44d28c581316281b9082e6a3283ffbbbed
parent2cb4d78b02be7a011876da557ea6b922700fd39c (diff)
downloadrspamd-244a9efad601be931eb71a689414be1d8bf70cea.tar.gz
rspamd-244a9efad601be931eb71a689414be1d8bf70cea.zip
Fix plugins.
-rw-r--r--conf/lua/hfilter.lua2
-rw-r--r--conf/lua/rspamd.classifiers.lua4
-rw-r--r--src/plugins/lua/forged_recipients.lua8
-rw-r--r--src/plugins/lua/multimap.lua68
-rw-r--r--src/plugins/lua/ratelimit.lua27
5 files changed, 14 insertions, 95 deletions
diff --git a/conf/lua/hfilter.lua b/conf/lua/hfilter.lua
index cfa6e3d22..18fc995c1 100644
--- a/conf/lua/hfilter.lua
+++ b/conf/lua/hfilter.lua
@@ -229,7 +229,7 @@ local function hfilter(task)
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
diff --git a/conf/lua/rspamd.classifiers.lua b/conf/lua/rspamd.classifiers.lua
index de1e23506..d73d08178 100644
--- a/conf/lua/rspamd.classifiers.lua
+++ b/conf/lua/rspamd.classifiers.lua
@@ -14,7 +14,7 @@ local function get_specific_statfiles(classifier, task)
-- 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)
@@ -23,7 +23,7 @@ local function get_specific_statfiles(classifier, task)
-- 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
diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua
index 9ad47a259..6fc1bcd83 100644
--- a/src/plugins/lua/forged_recipients.lua
+++ b/src/plugins/lua/forged_recipients.lua
@@ -6,11 +6,11 @@ local symbol_sender = 'FORGED_SENDER'
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)
@@ -36,9 +36,9 @@ function check_forged_headers(task)
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
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua
index aac0f5159..a4adab337 100644
--- a/src/plugins/lua/multimap.lua
+++ b/src/plugins/lua/multimap.lua
@@ -108,40 +108,6 @@ local function check_multimap(task)
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
@@ -176,40 +142,6 @@ local function check_multimap(task)
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
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index fc838dd9a..fff966e1d 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -47,6 +47,7 @@ local function check_specific_limit (task, limit, key)
--- 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()
@@ -74,6 +75,7 @@ local function check_specific_limit (task, limit, key)
end
end
if err then
+ rspamd_logger.info('got error while getting limit: ' .. err)
upstream:fail()
end
end
@@ -88,6 +90,7 @@ local function set_specific_limit (task, limit, key)
--- 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()
@@ -112,6 +115,7 @@ local function set_specific_limit (task, limit, key)
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
@@ -147,17 +151,6 @@ 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
@@ -169,9 +162,6 @@ local function rate_test_set(task, func)
-- 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',
@@ -179,24 +169,21 @@ local function rate_test_set(task, func)
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