Browse Source

[CritFix] Restore compatibility with the integrations and headers alterations

tags/3.4
Vsevolod Stakhov 1 year ago
parent
commit
ded2e51e60
No account linked to committer's email address
2 changed files with 16 additions and 2 deletions
  1. 14
    1
      lualib/lua_mime.lua
  2. 2
    1
      src/plugins/lua/milter_headers.lua

+ 14
- 1
lualib/lua_mime.lua View File

@@ -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

+ 2
- 1
src/plugins/lua/milter_headers.lua View File

@@ -39,6 +39,7 @@ local settings = {
skip_all = false,
local_headers = {},
authenticated_headers = {},
headers_modify_mode = 'compat', -- To avoid compatibility issues on upgrade
default_headers_order = nil, -- Insert at the end (set 1 to insert just after the first received)
routines = {
['remove-headers'] = {
@@ -572,7 +573,7 @@ local function milter_headers(task)
lua_mime.modify_headers(task, {
add = add,
remove = remove
})
}, settings.headers_modify_mode)
end
end


Loading…
Cancel
Save