1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2025-12-15 19:06:03 +00:00

[RSPAMD] Add boundary if present when applying domain-wide footer

This commit is contained in:
FreddleSpl0it
2025-09-09 10:52:19 +02:00
parent 8446abd484
commit 8d7235b535

View File

@@ -550,13 +550,13 @@ rspamd_config:register_symbol({
-- determine newline type -- determine newline type
local function newline(task) local function newline(task)
local t = task:get_newlines_type() local t = task:get_newlines_type()
if t == 'cr' then if t == 'cr' then
return '\r' return '\r'
elseif t == 'lf' then elseif t == 'lf' then
return '\n' return '\n'
end end
return '\r\n' return '\r\n'
end end
-- retrieve footer -- retrieve footer
@@ -564,7 +564,7 @@ rspamd_config:register_symbol({
if err or type(data) ~= 'string' then if err or type(data) ~= 'string' then
rspamd_logger.infox(rspamd_config, "domain wide footer request for user %s returned invalid or empty data (\"%s\") or error (\"%s\")", uname, data, err) rspamd_logger.infox(rspamd_config, "domain wide footer request for user %s returned invalid or empty data (\"%s\") or error (\"%s\")", uname, data, err)
else else
-- parse json string -- parse json string
local footer = cjson.decode(data) local footer = cjson.decode(data)
if not footer then if not footer then
@@ -613,26 +613,30 @@ rspamd_config:register_symbol({
if footer.plain and footer.plain ~= "" then if footer.plain and footer.plain ~= "" then
footer.plain = lua_util.jinja_template(footer.plain, replacements, true) footer.plain = lua_util.jinja_template(footer.plain, replacements, true)
end end
-- add footer -- add footer
local out = {} local out = {}
local rewrite = lua_mime.add_text_footer(task, footer.html, footer.plain) or {} local rewrite = lua_mime.add_text_footer(task, footer.html, footer.plain) or {}
local seen_cte local seen_cte
local newline_s = newline(task) local newline_s = newline(task)
local function rewrite_ct_cb(name, hdr) local function rewrite_ct_cb(name, hdr)
if rewrite.need_rewrite_ct then if rewrite.need_rewrite_ct then
if name:lower() == 'content-type' then if name:lower() == 'content-type' then
local nct = string.format('%s: %s/%s; charset=utf-8', -- include boundary if present
'Content-Type', rewrite.new_ct.type, rewrite.new_ct.subtype) local boundary_part = rewrite.new_ct.boundary and
string.format('; boundary="%s"', rewrite.new_ct.boundary) or ''
local nct = string.format('%s: %s/%s; charset=utf-8%s',
'Content-Type', rewrite.new_ct.type, rewrite.new_ct.subtype, boundary_part)
out[#out + 1] = nct out[#out + 1] = nct
-- update Content-Type header -- update Content-Type header (include boundary if present)
task:set_milter_reply({ task:set_milter_reply({
remove_headers = {['Content-Type'] = 0}, remove_headers = {['Content-Type'] = 0},
}) })
task:set_milter_reply({ task:set_milter_reply({
add_headers = {['Content-Type'] = string.format('%s/%s; charset=utf-8', rewrite.new_ct.type, rewrite.new_ct.subtype)} add_headers = {['Content-Type'] = string.format('%s/%s; charset=utf-8%s',
rewrite.new_ct.type, rewrite.new_ct.subtype, boundary_part)}
}) })
return return
elseif name:lower() == 'content-transfer-encoding' then elseif name:lower() == 'content-transfer-encoding' then
@@ -651,16 +655,16 @@ rspamd_config:register_symbol({
end end
out[#out + 1] = hdr.raw:gsub('\r?\n?$', '') out[#out + 1] = hdr.raw:gsub('\r?\n?$', '')
end end
task:headers_foreach(rewrite_ct_cb, {full = true}) task:headers_foreach(rewrite_ct_cb, {full = true})
if not seen_cte and rewrite.need_rewrite_ct then if not seen_cte and rewrite.need_rewrite_ct then
out[#out + 1] = string.format('%s: %s', 'Content-Transfer-Encoding', 'quoted-printable') out[#out + 1] = string.format('%s: %s', 'Content-Transfer-Encoding', 'quoted-printable')
end end
-- End of headers -- End of headers
out[#out + 1] = newline_s out[#out + 1] = newline_s
if rewrite.out then if rewrite.out then
for _,o in ipairs(rewrite.out) do for _,o in ipairs(rewrite.out) do
out[#out + 1] = o out[#out + 1] = o