From: Vsevolod Stakhov Date: Thu, 16 Jul 2026 10:13:10 +0000 (+0100) Subject: [Minor] Selectors: document the 'orig' address flavour X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e584ef619f496689d236ba6466b7770969dca52a;p=thirdparty%2Frspamd.git [Minor] Selectors: document the 'orig' address flavour The from/rcpts extractors pass their arguments through to task:get_from and task:get_recipients, so from('mime', 'orig') already selects the address as it was seen in the message; document it and add a functional test exercising the flavour through the selector pipeline. --- diff --git a/lualib/lua_selectors/extractors.lua b/lualib/lua_selectors/extractors.lua index 14810a8568..ba9f4bd820 100644 --- a/lualib/lua_selectors/extractors.lua +++ b/lualib/lua_selectors/extractors.lua @@ -94,7 +94,8 @@ For example, `list('foo', 'bar')` returns a list {'foo', 'bar'}]], return nil end, ['description'] = [[Get MIME or SMTP from (e.g. `from('smtp')` or `from('mime')`, -uses any type by default)]], +uses any type by default); add `orig` (e.g. `from('mime', 'orig')`) to get the +address as it was seen in the message, before any rewrite (e.g. by the aliases module)]], }, ['rcpts'] = { ['get_value'] = function(task, args) @@ -110,7 +111,8 @@ uses any type by default)]], return nil end, ['description'] = [[Get MIME or SMTP rcpts (e.g. `rcpts('smtp')` or `rcpts('mime')`, -uses any type by default)]], +uses any type by default); add `orig` (e.g. `rcpts('mime', 'orig')`) to get the +addresses as they were seen in the message, before any rewrite (e.g. by the aliases module)]], }, -- Get country (ASN module must be executed first) ['country'] = { diff --git a/test/functional/cases/001_merged/270_selector.robot b/test/functional/cases/001_merged/270_selector.robot index 2ff0abc47d..280e8e256f 100644 --- a/test/functional/cases/001_merged/270_selector.robot +++ b/test/functional/cases/001_merged/270_selector.robot @@ -19,3 +19,11 @@ Rspamd_text selector Scan File ${MESSAGE} ... Settings={symbols_enabled = [RSPAMD_TEXT_SELECTOR]} Expect Symbol RSPAMD_TEXT_SELECTOR + +From selector orig flavour + [Documentation] from('mime', 'orig') must return the wire From through the + ... selector pipeline even after a task:set_from rewrite + Scan File ${RSPAMD_TESTDIR}/messages/from/from_dn.eml + ... Rewrite-Mime-From=yes + ... Settings={symbols_enabled = [REWRITE_MIME_FROM, SELECTOR_FROM_ORIG]} + Expect Symbol With Exact Options SELECTOR_FROM_ORIG forged@forged.example.net|user@example.org diff --git a/test/functional/lua/selector_test.lua b/test/functional/lua/selector_test.lua index dd52ee3ed1..758ae0d0c5 100644 --- a/test/functional/lua/selector_test.lua +++ b/test/functional/lua/selector_test.lua @@ -21,3 +21,20 @@ config['regexp']['RSPAMD_TEXT_SELECTOR'] = { re = 'some_rspamd_text_re=/^hello$/{selector}', score = 1, } + +-- The 'orig' flavour must be reachable through selectors and return the +-- address as it was seen in the message, before any task:set_from rewrite +local selector_from = lua_selectors.create_selector_closure( + rspamd_config, "from('mime'):addr", '') +local selector_from_orig = lua_selectors.create_selector_closure( + rspamd_config, "from('mime', 'orig'):addr", '') + +rspamd_config:register_symbol({ + name = 'SELECTOR_FROM_ORIG', + score = 1.0, + callback = function(task) + local cur = selector_from(task) + local orig = selector_from_orig(task) + return true, string.format('%s|%s', cur or 'nil', orig or 'nil') + end +})