aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-11-15 09:54:20 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-11-15 09:54:20 +0000
commitc06830279ff9f98d3d5ee2888da7b2fa33a8c339 (patch)
tree6d569e0fa2d8554be6c4d4eff6ebabd91d080580 /lualib
parent73adbf798117f119ae21957951528cba4a684418 (diff)
downloadrspamd-c06830279ff9f98d3d5ee2888da7b2fa33a8c339.tar.gz
rspamd-c06830279ff9f98d3d5ee2888da7b2fa33a8c339.zip
[Fix] Dmarc: Properly encode structured headers
Issue: #5221
Diffstat (limited to 'lualib')
-rw-r--r--lualib/plugins/dmarc.lua20
1 files changed, 11 insertions, 9 deletions
diff --git a/lualib/plugins/dmarc.lua b/lualib/plugins/dmarc.lua
index 720c76e16..f69016b74 100644
--- a/lualib/plugins/dmarc.lua
+++ b/lualib/plugins/dmarc.lua
@@ -194,14 +194,17 @@ exports.gen_munging_callback = function(munging_opts, settings)
via_name = string.format('%s via %s', from.name, via_user)
end
- local hdr_encoded = rspamd_util.fold_header('From',
- rspamd_util.mime_header_encode(string.format('%s <%s>',
- via_name, via_addr)), task:get_newlines_type())
- local orig_from_encoded = rspamd_util.fold_header('X-Original-From',
- rspamd_util.mime_header_encode(string.format('%s <%s>',
- from.name or '', from.addr)), task:get_newlines_type())
+ local encoded_via_name = rspamd_util.mime_header_encode(via_name)
+ local via_from_folded = rspamd_util.fold_header('From',
+ string.format('%s <%s>', encoded_via_name, via_addr),
+ task:get_newlines_type())
+ local encoded_orig_name = rspamd_util.mime_header_encode(from.name or '')
+ local orig_from_folded = rspamd_util.fold_header('X-Original-From',
+ string.format('%s <%s>', encoded_orig_name, from.addr),
+ task:get_newlines_type())
local add_hdrs = {
- ['From'] = { order = 1, value = hdr_encoded },
+ ['From'] = { order = 1, value = via_from_folded },
+ ['X-Original-From'] = { order = 0, value = orig_from_folded },
}
local remove_hdrs = { ['From'] = 0 }
@@ -223,13 +226,12 @@ exports.gen_munging_callback = function(munging_opts, settings)
add_hdrs['Reply-To'] = { order = 0, value = nreply }
- add_hdrs['X-Original-From'] = { order = 0, value = orig_from_encoded }
lua_mime.modify_headers(task, {
remove = remove_hdrs,
add = add_hdrs
})
lua_util.debugm(N, task, 'munged DMARC header for %s: %s -> %s',
- from.domain, hdr_encoded, from.addr)
+ from.domain, via_from_folded, from.addr)
rspamd_logger.infox(task, 'munged DMARC header for %s', from.addr)
task:insert_result('DMARC_MUNGED', 1.0, from.addr)
end