diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-10-22 13:00:21 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-10-22 13:00:21 +0100 |
commit | ded2e51e60325a0e817362c6df0c341bb00d4b0e (patch) | |
tree | 795f5ffdb3e257f07de11420b2b79a53a9dce73c /lualib/lua_mime.lua | |
parent | 764a54dea98636dfc725edd29a48577742d506c9 (diff) | |
download | rspamd-ded2e51e60325a0e817362c6df0c341bb00d4b0e.tar.gz rspamd-ded2e51e60325a0e817362c6df0c341bb00d4b0e.zip |
[CritFix] Restore compatibility with the integrations and headers alterations
Diffstat (limited to 'lualib/lua_mime.lua')
-rw-r--r-- | lualib/lua_mime.lua | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lualib/lua_mime.lua b/lualib/lua_mime.lua index 1087b7fd5..9dff5cfed 100644 --- a/lualib/lua_mime.lua +++ b/lualib/lua_mime.lua @@ -515,8 +515,11 @@ end --[[[ -- @function lua_mime.modify_headers(task, {add = {hname = {value = 'value', order = 1}}, remove = {hname = {1,2}}}) -- Adds/removes headers both internal and in the milter reply +-- Mode defines to be compatible with Rspamd <=3.2 and is the default (equal to 'compat') --]] -exports.modify_headers = function(task, hdr_alterations) +exports.modify_headers = function(task, hdr_alterations, mode) + -- Assume default mode compatibility + if not mode then mode = 'compat' end local add = hdr_alterations.add or {} local remove = hdr_alterations.remove or {} @@ -550,6 +553,11 @@ exports.modify_headers = function(task, hdr_alterations) else logger.errx(task, 'invalid modification of header: %s', hdr) end + + if mode == 'compat' and #add_headers[hname] == 1 then + -- Switch to the compatibility mode + add_headers[hname] = add_headers[hname][1] + end end if hdr_alterations.order then -- Get headers alterations ordered @@ -580,6 +588,11 @@ exports.modify_headers = function(task, hdr_alterations) end end + if mode == 'compat' then + -- Clear empty alterations in the compat mode + if not next(add_headers) then add_headers = nil end + if not next(hdr_alterations.remove) then hdr_alterations.remove = nil end + end task:set_milter_reply({ add_headers = add_headers, remove_headers = hdr_alterations.remove |