aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/rspamadm/mime.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-11-29 13:40:11 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-11-29 13:40:11 +0000
commit8d48eb47dfcc2fef3ad4ce7fe166a1cf36d3ffe6 (patch)
treee35adb8f2ca8f99a40ce0e313a30709f949db5cd /lualib/rspamadm/mime.lua
parent871bd66a50dd8139373d13154c6107cf0940a7fb (diff)
downloadrspamd-8d48eb47dfcc2fef3ad4ce7fe166a1cf36d3ffe6.tar.gz
rspamd-8d48eb47dfcc2fef3ad4ce7fe166a1cf36d3ffe6.zip
[Project] Add tool to rspamadm
Diffstat (limited to 'lualib/rspamadm/mime.lua')
-rw-r--r--lualib/rspamadm/mime.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua
index 7750c5a78..617f57a77 100644
--- a/lualib/rspamadm/mime.lua
+++ b/lualib/rspamadm/mime.lua
@@ -179,6 +179,13 @@ 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 "+"
+
local sign = parser:command "sign"
:description "Performs DKIM signing"
sign:argument "file"
@@ -968,6 +975,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 +1118,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