diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-12-10 17:46:13 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-10 17:46:13 +0600 |
commit | 58f213c3f76f963bd5e0d1d0b995f930d89d7818 (patch) | |
tree | c89093fcced419b5e1cd28f0f7f59e5c94f0596c /lualib/rspamadm | |
parent | 142f40fdd7578179cdd425439293f798b9969f2b (diff) | |
parent | ad9a444a525e51290a1845927e84188d2e9f18bf (diff) | |
download | rspamd-58f213c3f76f963bd5e0d1d0b995f930d89d7818.tar.gz rspamd-58f213c3f76f963bd5e0d1d0b995f930d89d7818.zip |
Merge pull request #5240 from rspamd/vstakhov-anonymize-mime
Add tool to anonymize messages content
Diffstat (limited to 'lualib/rspamadm')
-rw-r--r-- | lualib/rspamadm/mime.lua | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua index 7750c5a78..f8c7fc4f7 100644 --- a/lualib/rspamadm/mime.lua +++ b/lualib/rspamadm/mime.lua @@ -179,6 +179,21 @@ strip:option "--max-text-size" :convert(tonumber) :default(math.huge) +local anonymize = parser:command "anonymize" + :description "Try to remove sensitive information from a message" +anonymize:argument "file" + :description "File to process" + :argname "<file>" + :args "+" +anonymize:option "--exclude-header -X" + :description "Exclude specific headers from anonymization" + :argname "<header>" + :count "*" +anonymize:option "--include-header -I" + :description "Include specific headers from anonymization" + :argname "<header>" + :count "*" + local sign = parser:command "sign" :description "Performs DKIM signing" sign:argument "file" @@ -968,6 +983,41 @@ local function strip_handler(opts) end end +local function anonymize_handler(opts) + load_config(opts) + rspamd_url.init(rspamd_config:get_tld_path()) + + for _, fname in ipairs(opts.file) do + local task = load_task(opts, fname) + local newline_s = newline(task) + + local rewrite = lua_mime.anonymize_message(task, opts) or {} + + for _, o in ipairs(rewrite.out) do + if type(o) == 'string' then + io.write(o) + io.write(newline_s) + elseif type(o) == 'table' then + io.flush() + if type(o[1]) == 'string' then + io.write(o[1]) + else + o[1]:save_in_file(1) + end + + if o[2] then + io.write(newline_s) + end + else + o:save_in_file(1) + io.write(newline_s) + end + end + + task:destroy() -- No automatic dtor + end +end + -- Strips directories and .extensions (if present) from a filepath local function filename_only(filepath) local filename = filepath:match(".*%/([^%.]+)") @@ -1076,6 +1126,8 @@ local function handler(args) sign_handler(opts) elseif command == 'dump' then dump_handler(opts) + elseif command == 'anonymize' then + anonymize_handler(opts) else parser:error('command %s is not implemented', command) end |