diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-29 13:40:11 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-29 13:40:11 +0000 |
commit | 8d48eb47dfcc2fef3ad4ce7fe166a1cf36d3ffe6 (patch) | |
tree | e35adb8f2ca8f99a40ce0e313a30709f949db5cd /lualib/lua_mime.lua | |
parent | 871bd66a50dd8139373d13154c6107cf0940a7fb (diff) | |
download | rspamd-8d48eb47dfcc2fef3ad4ce7fe166a1cf36d3ffe6.tar.gz rspamd-8d48eb47dfcc2fef3ad4ce7fe166a1cf36d3ffe6.zip |
[Project] Add tool to rspamadm
Diffstat (limited to 'lualib/lua_mime.lua')
-rw-r--r-- | lualib/lua_mime.lua | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/lualib/lua_mime.lua b/lualib/lua_mime.lua index 167939189..ce14a49f3 100644 --- a/lualib/lua_mime.lua +++ b/lualib/lua_mime.lua @@ -951,21 +951,26 @@ exports.anonymize_message = function(task, settings) -- Process headers local modified_headers = {} - for name, processor in pairs(header_processors) do - local hdrs = task:get_header_full(name, true) - if hdrs then - for _, hdr in ipairs(hdrs) do - local new_value = processor(hdr) - if new_value then - table.insert(modified_headers, { - name = name, - value = new_value - }) - end + local function process_hdr(name, hdr) + local processor = header_processors[name:lower()] + if processor then + local new_value = processor(hdr) + if new_value then + table.insert(modified_headers, { + name = name, + value = new_value + }) end + else + table.insert(modified_headers, { + name = name, + value = hdr.value, + }) end end + task:headers_foreach(process_hdr, { full = true }) + -- Create new text content local text_content = {} local urls = {} @@ -974,12 +979,14 @@ exports.anonymize_message = function(task, settings) -- Extract text content, URLs and emails local text_parts = task:get_text_parts() for _, part in ipairs(text_parts) do - if part:is_html() then - local words = part:get_words('norm') - if words then - text_content = words + if not part:get_mimepart():is_attachment() then + if part:is_html() then + local words = part:get_words('norm') + if words then + text_content = words + end + break -- Use only first HTML part end - break -- Use only first HTML part end end @@ -1027,9 +1034,7 @@ exports.anonymize_message = function(task, settings) local new_text = table.concat(text_content, ' ') -- Create new message structure - local boundaries = {} local cur_boundary = '--XXX' - boundaries[1] = cur_boundary -- Add headers out[#out + 1] = { |