diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2017-06-16 12:28:47 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2017-06-16 12:28:47 +0300 |
commit | 57a7f78339ce8eba9e49bb7759a5a1c67b286e52 (patch) | |
tree | 14a9926f2ef55d245838a90321683a4ef91a24c7 /src | |
parent | d78ff700760be3f2133479242b7d218e8e6ec14a (diff) | |
download | rspamd-57a7f78339ce8eba9e49bb7759a5a1c67b286e52.tar.gz rspamd-57a7f78339ce8eba9e49bb7759a5a1c67b286e52.zip |
[Feature] milter_headers: add `extended_headers_rcpt` option
Milter_headers module adds extended headers to messages if EVERY envelope recipient matches `extended_headers_rcpt` list.
```
extended_headers_rcpt = ["user1", "@example1.com", "user2@example2.com"];
```
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/lua/milter_headers.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/plugins/lua/milter_headers.lua b/src/plugins/lua/milter_headers.lua index a4c83cee1..3e7bb60e2 100644 --- a/src/plugins/lua/milter_headers.lua +++ b/src/plugins/lua/milter_headers.lua @@ -33,6 +33,7 @@ local settings = { skip_authenticated = true, local_headers = {}, authenticated_headers = {}, + extended_headers_rcpt = {}, routines = { ['x-spamd-result'] = { header = 'X-Spamd-Result', @@ -111,6 +112,28 @@ local function milter_headers(task) local function skip_wanted(hdr) + local function match_extended_headers_rcpt(rcpts) + local rcpts = task:get_recipients('smtp') + if not rcpts then return false end + local found + for _, r in ipairs(rcpts) do + found = false + for k, v in pairs(settings.extended_headers_rcpt) do + for _, ehr in ipairs(v) do + if r[k] == ehr then + found = true + break + end + end + if found then break end + end + if not found then break end + end + return found + end + + if settings.extended_headers_rcpt and match_extended_headers_rcpt() then return false end + if settings.skip_local and not settings.local_headers[hdr] then local ip = task:get_ip() if (ip and ip:is_local()) then return true end @@ -413,6 +436,34 @@ if (#active_routines < 1) then return end logger.infox(rspamd_config, 'active routines [%s]', table.concat(active_routines, ',')) +if type(opts['extended_headers_rcpt']) == 'string' then + opts['extended_headers_rcpt'] = {opts['extended_headers_rcpt']} +end +if type(opts['extended_headers_rcpt']) == 'table' and opts['extended_headers_rcpt'][1] then + for _, e in ipairs(opts['extended_headers_rcpt']) do + if string.find(e, '^[^@]+@[^@]+$') then + if not settings.extended_headers_rcpt.addr then + settings.extended_headers_rcpt.addr = {} + end + table.insert(settings.extended_headers_rcpt['addr'], e) + elseif string.find(e, '^[^@]+$') then + if not settings.extended_headers_rcpt.user then + settings.extended_headers_rcpt.user = {} + end + table.insert(settings.extended_headers_rcpt['user'], e) + else + local d = string.match(e, '^@([^@]+)$') + if d then + if not settings.extended_headers_rcpt.domain then + settings.extended_headers_rcpt.domain = {} + end + table.insert(settings.extended_headers_rcpt['domain'], d) + else + logger.errx(rspamd_config, 'extended_headers_rcpt: unexpected entry: %s', e) + end + end + end +end rspamd_config:register_symbol({ name = 'MILTER_HEADERS', type = 'postfilter', |