Skip to main content

Module lua_selectors

Module lua_selectors​

This module contains 'selectors' implementation: code to extract data from Rspamd tasks and compose those together. Typical selector looks like this: header(User).lower.substring(1, 2):ip

Brief content:​

Functions:

FunctionDescription
lua_selectors.parse_selector(cfg, str)No description
lua_selectors.get_dependencies(cfg, str)Returns the list of symbols that must be executed before the selector can.
lua_selectors.register_dependencies(cfg, symbol, str)Registers the dependencies of a selector (see get_dependencies) for the.
lua_selectors.register_extractor(cfg, name, selector)No description
lua_selectors.register_transform(cfg, name, transform)No description
lua_selectors.process_selectors(task, selectors_pipe)No description
lua_selectors.combine_selectors(task, selectors, delimiter)No description
lua_selectors.flatten_selectors(selectors)Convert selectors to a flat table of elements.
lua_selectors.kv_table_from_pairs(selectors)Convert selectors to a table where the odd elements are keys and even are elements.
lua_selectors.create_closure(log_obj, cfg, selector_str, delimiter, fn)Creates a closure from a string selector, using the specific combinator function.
lua_selectors.create_closure(cfg, selector_str, delimiter='', flatten=false)Creates a closure from a string selector.
lua_selectors.get_combinator(name)Returns a combinator function by name.
lua_selectors.list_combinators()Returns list of available combinator names.
lua_selectors.create_selector_closure_with_combinator(cfg, selector_str, delimiter, combinator_name)Creates a closure from a string selector using named combinator.

Functions​

The module lua_selectors defines the following functions.

Function lua_selectors.parse_selector(cfg, str)​

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.get_dependencies(cfg, str)​

Returns the list of symbols that must be executed before the selector can produce a value (e.g. ASN_CHECK for asn, the symbol itself for symbol(NAME)), or nil if the selector cannot be parsed

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.register_dependencies(cfg, symbol, str)​

Registers the dependencies of a selector (see get_dependencies) for the symbol that evaluates it, so the symbols cache executes them first: a prefilter that uses symbol(DKIM_CHECK) gets DKIM_CHECK hoisted to the prefilter stage. Composites and classifiers are produced by the task stages rather than by symbols, and a dependency on a symbol of a later stage cannot be satisfied: those are skipped with a warning

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.register_extractor(cfg, name, selector)​

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.register_transform(cfg, name, transform)​

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.process_selectors(task, selectors_pipe)​

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.combine_selectors(task, selectors, delimiter)​

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.flatten_selectors(selectors)​

Convert selectors to a flat table of elements

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.kv_table_from_pairs(selectors)​

Convert selectors to a table where the odd elements are keys and even are elements Similarly to make a map from (k, v) pairs list To specify the concrete constant keys, one can use the id extractor

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.create_closure(log_obj, cfg, selector_str, delimiter, fn)​

Creates a closure from a string selector, using the specific combinator function

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.create_closure(cfg, selector_str, delimiter='', flatten=false)​

Creates a closure from a string selector

Parameters:

No parameters

Returns:

No return

Back to module description.

Function lua_selectors.get_combinator(name)​

Returns a combinator function by name

Parameters:

  • name {string}: combinator name: 'string', 'array', or 'object'

Returns:

  • {function}: combinator function or nil if not found

Back to module description.

Function lua_selectors.list_combinators()​

Returns list of available combinator names

Parameters:

No parameters

Returns:

  • {table}: array of combinator names

Back to module description.

Function lua_selectors.create_selector_closure_with_combinator(cfg, selector_str, delimiter, combinator_name)​

Creates a closure from a string selector using named combinator

Parameters:

  • cfg {rspamd_config}: rspamd config object
  • selector_str {string}: selector string to parse
  • delimiter {string}: delimiter for combining results (used by some combinators)
  • combinator_name {string}: name of combinator: 'string', 'array', or 'object'

Returns:

  • {function}: closure that processes selector on task, or nil on error

Back to module description.

Back to top.