aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-26 14:08:28 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-06-26 14:08:28 +0100
commitde1229f674bc8896a0373d030d3ead0c98f0e731 (patch)
tree99506d5b5bee45ff1ebce6eabc70d3c09ba8e90c /lualib
parent5d6bd253f7bf7804cb0b52485c465324cfc42b7b (diff)
downloadrspamd-de1229f674bc8896a0373d030d3ead0c98f0e731.tar.gz
rspamd-de1229f674bc8896a0373d030d3ead0c98f0e731.zip
[Feature] Allow to show HTML structure on extraction
Diffstat (limited to 'lualib')
-rw-r--r--lualib/rspamadm/mime.lua30
1 files changed, 28 insertions, 2 deletions
diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua
index b44f647a0..2cdec1513 100644
--- a/lualib/rspamadm/mime.lua
+++ b/lualib/rspamadm/mime.lua
@@ -74,6 +74,8 @@ extract:flag "-w --words"
:description "Extracts words"
extract:flag "-p --part"
:description "Show part info"
+extract:flag "-s --structure"
+ :description "Show structure info (e.g. HTML tags)"
local stat = parser:command "stat st s"
@@ -187,6 +189,7 @@ end
local function extract_handler(opts)
local out_elts = {}
+ local process_func
if opts.words then
-- Enable stemming
@@ -249,7 +252,30 @@ local function extract_handler(opts)
if opts.words then
table.insert(out_elts[fname], table.concat(part:get_words(), ' '))
else
- table.insert(out_elts[fname], tostring(part:get_content(how)))
+ if opts.structure then
+ local hc = part:get_html()
+ local res = {}
+ process_func = function(k, v)
+ return rspamd_logger.slog("%s = %s", k, v)
+ end
+
+ hc:foreach_tag('any', function(tag)
+ local elt = {}
+ local ex = tag:get_extra()
+ elt.tag = tag:get_type()
+ if ex then
+ elt.extra = ex
+ end
+ local content = tag:get_content()
+ if content then
+ elt.content = content
+ end
+ table.insert(res, elt)
+ end)
+ out_elts[fname] = res
+ else
+ table.insert(out_elts[fname], tostring(part:get_content(how)))
+ end
end
end
end
@@ -260,7 +286,7 @@ local function extract_handler(opts)
task:destroy() -- No automatic dtor
end
- print_elts(out_elts, opts)
+ print_elts(out_elts, opts, process_func)
end
local function stat_handler(opts)