]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Selectors: document the 'orig' address flavour
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 16 Jul 2026 10:13:10 +0000 (11:13 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 16 Jul 2026 10:13:10 +0000 (11:13 +0100)
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.

lualib/lua_selectors/extractors.lua
test/functional/cases/001_merged/270_selector.robot
test/functional/lua/selector_test.lua

index 14810a85683cb06dd678ca0e70b910deb29f9a8a..ba9f4bd820c63524053fe1198e5d1841872eac24 100644 (file)
@@ -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'] = {
index 2ff0abc47de35ad113fd350b512362a5b36eba5e..280e8e256f8eeeacf35f8815e8a2acfc296a1434 100644 (file)
@@ -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
index dd52ee3ed14a667cb19217629f291e0da804db7f..758ae0d0c584f3ac24721972399839a2bcbb7dbe 100644 (file)
@@ -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
+})