aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-03-04 19:38:04 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-03-04 19:38:04 +0300
commitde9ac8f1938e09f3c6c3d6f261db4749b3b9ff01 (patch)
treeea861fa0702a4dd3103de7c24ebd164b4aa21855 /src/plugins
parent2a2bc886c1b43a9c43a812959d7193cc03d7bc8d (diff)
downloadrspamd-de9ac8f1938e09f3c6c3d6f261db4749b3b9ff01.tar.gz
rspamd-de9ac8f1938e09f3c6c3d6f261db4749b3b9ff01.zip
* Add multimaps for "FROM" and "TO" headers (mime an smtp data can be checked)
* Improve lua api for getting message's sender and recipients
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/lua/forged_recipients.lua53
-rw-r--r--src/plugins/lua/multimap.lua96
2 files changed, 99 insertions, 50 deletions
diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua
index d082b386d..366591377 100644
--- a/src/plugins/lua/forged_recipients.lua
+++ b/src/plugins/lua/forged_recipients.lua
@@ -10,57 +10,21 @@ function check_forged_headers(task)
local res = false
if smtp_rcpt then
- local mime_rcpt = msg:get_header('To')
- local mime_cc = msg:get_header('Cc')
- local count = 0
- if mime_rcpt then
- count = table.maxn(mime_rcpt)
- end
- if mime_cc then
- count = count + table.maxn(mime_cc)
- end
- -- Check recipients count
+ local mime_rcpt = task:get_recipients_headers()
+ local count = table.maxn(mime_rcpt)
if count < table.maxn(smtp_rcpt) then
task:insert_result(symbol_rcpt, 1)
else
-- Find pair for each smtp recipient recipient in To or Cc headers
for _,sr in ipairs(smtp_rcpt) do
- if sr:sub(1,1) == '<' then
- -- Trim brackets
- sr = string.sub(sr, 2, -2)
- end
if mime_rcpt then
for _,mr in ipairs(mime_rcpt) do
- local i = string.find(mr, '<', 1, true)
- if i then
- local j = string.find(mr, '>', i, true)
- if j then
- mr = string.sub(mr, i+1, j-1)
- end
- end
-
- if string.lower(mr) == string.lower(sr) then
+ if string.lower(mr['addr']) == string.lower(sr['addr']) then
res = true
break
end
end
end
- if mime_cc then
- for _,mr in ipairs(mime_cc) do
- local i = string.find(mr, '<', 1, true)
- if i then
- local j = string.find(mr, '>', i, true)
- if j then
- mr = string.sub(mr, i+1, j-1)
- end
- end
- if string.lower(mr) == string.lower(sr) then
- res = true
- break
- end
- end
- end
-
if not res then
task:insert_result(symbol_rcpt, 1)
break
@@ -71,15 +35,8 @@ function check_forged_headers(task)
-- Check sender
local smtp_from = task:get_from()
if smtp_form then
- local mime_from = msg:get_header('From')
- local i = string.find(mime_from[0], '<', 1, true)
- if i then
- local j = string.find(mime_from[0], '>', i, true)
- if j then
- mime_from[0] = string.sub(mime_from[0], i+1, j-1)
- end
- end
- if not mime_from or not (string.lower(mime_from[0]) == string.lower(smtp_from)) then
+ local mime_from = task:get_from_headers()
+ 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
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua
index 9512ff890..15c906657 100644
--- a/src/plugins/lua/multimap.lua
+++ b/src/plugins/lua/multimap.lua
@@ -73,6 +73,94 @@ function check_multimap(task)
local rbl_str = o4 .. '.' .. o3 .. '.' .. o2 .. '.' .. o1 .. '.' .. rule['map']
task:resolve_dns_a(rbl_str, 'multimap_rbl_cb')
end
+ elseif rule['type'] == 'rcpt' then
+ -- First try to get rcpt field
+ local rcpts = task:get_recipients()
+ 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['hash']:get_key(ext) then
+ task:insert_result(rule['symbol'], 1)
+ end
+ end
+ else
+ if rule['hash']:get_key(r['addr']) then
+ task:insert_result(rule['symbol'], 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['hash']:get_key(ext) then
+ task:insert_result(rule['symbol'], 1)
+ end
+ end
+ else
+ if rule['hash']:get_key(r['addr']) then
+ task:insert_result(rule['symbol'], 1)
+ end
+ end
+ end
+ end
+ end
+ end
+ elseif rule['type'] == 'from' then
+ -- First try to get from field
+ local from = task:get_from()
+ 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['hash']:get_key(ext) then
+ task:insert_result(rule['symbol'], 1)
+ end
+ end
+ else
+ if rule['hash']:get_key(r['addr']) then
+ task:insert_result(rule['symbol'], 1)
+ end
+ 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['hash']:get_key(ext) then
+ task:insert_result(rule['symbol'], 1)
+ end
+ 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
@@ -98,6 +186,10 @@ local function add_multimap_rule(params)
newrule['type'] = 'dnsbl'
elseif value == 'header' then
newrule['type'] = 'header'
+ elseif value == 'rcpt' then
+ newrule['type'] = 'rcpt'
+ elseif value == 'from' then
+ newrule['type'] = 'from'
else
rspamd_logger:err('invalid rule type: '.. value)
return nil
@@ -116,13 +208,13 @@ local function add_multimap_rule(params)
end
end
- if not newrule['symbol'] or not newrule['map'] or not newrule['symbol'] then
+ if not newrule['symbol'] or not newrule['map'] then
rspamd_logger:err('incomplete rule')
return nil
end
if newrule['type'] == 'ip' then
newrule['ips'] = rspamd_config:add_radix_map (newrule['map'])
- elseif newrule['type'] == 'header' then
+ elseif newrule['type'] == 'header' or newrule['type'] == 'rcpt' or newrule['type'] == 'from' then
newrule['hash'] = rspamd_config:add_hash_map (newrule['map'])
end
table.insert(rules, newrule)