From: Vsevolod Stakhov Date: Wed, 8 Oct 2025 10:09:26 +0000 (+0100) Subject: [Fix] Fix is_local_domain to support backend objects X-Git-Tag: 3.14.0~88^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8400a02637e073f82d4bdfa1993923454fdbdae1;p=thirdparty%2Frspamd.git [Fix] Fix is_local_domain to support backend objects The is_local_domain function was directly accessing module_state.local_domains as a table, which caused it to always return false when local_domains was configured as a backend object (MapBackend, CDBBackend, etc). Fixed by: - Moving get_from_source helper function before is_local_domain - Using get_from_source to handle both plain tables and backend objects - Updating return logic to handle different truthy values from backends --- diff --git a/lualib/lua_aliases.lua b/lualib/lua_aliases.lua index 3a98316b9c..b200185db8 100644 --- a/lualib/lua_aliases.lua +++ b/lualib/lua_aliases.lua @@ -491,6 +491,24 @@ end exports.parse_local_domains = parse_local_domains +--- Get value from backend or table +-- @param source backend object or table +-- @param key lookup key +-- @return value or nil +local function get_from_source(source, key) + if not source then + return nil + end + + -- If it's a backend object with :get() method + if type(source) == 'table' and source.get then + return source:get(key) + end + + -- Otherwise treat as plain table + return source[key] +end + --- Check if a domain is local -- @param domain domain name to check -- @return true if domain is local, false otherwise @@ -500,13 +518,13 @@ local function is_local_domain(domain) end domain = domain:lower() - local result = module_state.local_domains[domain] == true + local result = get_from_source(module_state.local_domains, domain) lua_util.debugm(N, module_state.config, 'is_local_domain: domain=%s result=%s', domain, result) - return result + return result ~= nil and result ~= false end exports.is_local_domain = is_local_domain @@ -595,24 +613,6 @@ local function apply_service_rules(email_addr) end exports.apply_service_rules = apply_service_rules ---- Get value from backend or table --- @param source backend object or table --- @param key lookup key --- @return value or nil -local function get_from_source(source, key) - if not source then - return nil - end - - -- If it's a backend object with :get() method - if type(source) == 'table' and source.get then - return source:get(key) - end - - -- Otherwise treat as plain table - return source[key] -end - --- Resolve one step of aliasing -- @param email_str normalized email string -- @return result (string, array of strings, or nil), rule_type