diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-01-27 20:39:30 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-27 20:39:30 +0600 |
commit | abc813e0698cc604e7651beebce93266a8e719a6 (patch) | |
tree | cec425d0e511b3ff9e9dce7641b114d24840ff16 | |
parent | 23c76ecda7d9d9807e57d5e509d9f0d2a669ef5b (diff) | |
parent | 16c13369420d9792c4ae2d3de45145da00067c43 (diff) | |
download | rspamd-abc813e0698cc604e7651beebce93266a8e719a6.tar.gz rspamd-abc813e0698cc604e7651beebce93266a8e719a6.zip |
Merge pull request #4794 from rspamd/vstakhov-multimap-addr-extraction
[Feature] Add extraction type for `from` maps
-rw-r--r-- | src/plugins/lua/multimap.lua | 80 |
1 files changed, 70 insertions, 10 deletions
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 53b273227..600a09c4f 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -878,21 +878,81 @@ local function multimap_callback(task, rule) end end, rcpt = function() - if task:has_recipients('smtp') then - local rcpts = task:get_recipients('smtp') - match_addr(rule, rcpts) - elseif task:has_recipients('mime') then + local extract_from = rule.extract_from or 'default' + + if extract_from == 'mime' then local rcpts = task:get_recipients('mime') - match_addr(rule, rcpts) + if rcpts then + lua_util.debugm(N, task, 'checking mime rcpts against the map') + match_addr(rule, rcpts) + end + elseif extract_from == 'smtp' then + local rcpts = task:get_recipients('smtp') + if rcpts then + lua_util.debugm(N, task, 'checking smtp rcpts against the map') + match_addr(rule, rcpts) + end + elseif extract_from == 'both' then + local rcpts = task:get_recipients('smtp') + if rcpts then + lua_util.debugm(N, task, 'checking smtp rcpts against the map') + match_addr(rule, rcpts) + end + rcpts = task:get_recipients('mime') + if rcpts then + lua_util.debugm(N, task, 'checking mime rcpts against the map') + match_addr(rule, rcpts) + end + else + -- Default algorithm + if task:has_recipients('smtp') then + local rcpts = task:get_recipients('smtp') + lua_util.debugm(N, task, 'checking smtp rcpts against the map') + match_addr(rule, rcpts) + elseif task:has_recipients('mime') then + local rcpts = task:get_recipients('mime') + lua_util.debugm(N, task, 'checking mime rcpts against the map') + match_addr(rule, rcpts) + end end end, from = function() - if task:has_from('smtp') then - local from = task:get_from('smtp') - match_addr(rule, from) - elseif task:has_from('mime') then + local extract_from = rule.extract_from or 'default' + + if extract_from == 'mime' then local from = task:get_from('mime') - match_addr(rule, from) + if from then + lua_util.debugm(N, task, 'checking mime from against the map') + match_addr(rule, from) + end + elseif extract_from == 'smtp' then + local from = task:get_from('smtp') + if from then + lua_util.debugm(N, task, 'checking smtp from against the map') + match_addr(rule, from) + end + elseif extract_from == 'both' then + local from = task:get_from('smtp') + if from then + lua_util.debugm(N, task, 'checking smtp from against the map') + match_addr(rule, from) + end + from = task:get_from('mime') + if from then + lua_util.debugm(N, task, 'checking mime from against the map') + match_addr(rule, from) + end + else + -- Default algorithm + if task:has_from('smtp') then + local from = task:get_from('smtp') + lua_util.debugm(N, task, 'checking smtp from against the map') + match_addr(rule, from) + elseif task:has_from('mime') then + local from = task:get_from('mime') + lua_util.debugm(N, task, 'checking mime from against the map') + match_addr(rule, from) + end end end, helo = function() |