commit ded2e51: [CritFix] Restore compatibility with the integrations and headers alterations
Vsevolod Stakhov
vsevolod at rspamd.com
Sat Oct 22 12:07:03 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-10-22 13:00:21 +0100
URL: https://github.com/rspamd/rspamd/commit/ded2e51e60325a0e817362c6df0c341bb00d4b0e (HEAD -> master)
[CritFix] Restore compatibility with the integrations and headers alterations
---
lualib/lua_mime.lua | 15 ++++++++++++++-
src/plugins/lua/milter_headers.lua | 3 ++-
2 files changed, 16 insertions(+), 2 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
diff --git a/src/plugins/lua/milter_headers.lua b/src/plugins/lua/milter_headers.lua
index 913b71f54..a8be5ef37 100644
--- a/src/plugins/lua/milter_headers.lua
+++ b/src/plugins/lua/milter_headers.lua
@@ -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
More information about the Commits
mailing list