[Feature] Implement fuzzy hashes extraction in mime tool

This commit is contained in:
Vsevolod Stakhov 2018-07-04 15:51:29 +01:00
parent 5d3677f48b
commit 24e056d1d4

View File

@ -92,6 +92,8 @@ stat:mutex(
stat:flag "-F --fuzzy"
:description "Fuzzy hashes"
)
stat:flag "-s --shingles"
:description "Show shingles for fuzzy hashes"
local urls = parser:command "urls url u"
:description "Extracts URLs from MIME messages"
@ -321,7 +323,16 @@ local function stat_handler(opts)
local parts = task:get_parts() or {}
out_elts[fname] = {}
process_func = function(e)
return string.format('part: %s(%s): %s', e.type, e.file or "", e.digest)
local ret = string.format('part: %s(%s): %s', e.type, e.file or "", e.digest)
if opts.shingles and e.shingles then
local sgl = {}
for _,s in ipairs(e.shingles) do
table.insert(sgl, string.format('%s: %s+%s+%s', s[1], s[2], s[3], s[4]))
end
ret = ret .. '\n' .. table.concat(sgl, '\n')
end
return ret
end
for _,part in ipairs(parts) do
if not part:is_multipart() then
@ -331,7 +342,7 @@ local function stat_handler(opts)
local digest,shingles = text:get_fuzzy_hashes(task:get_mempool())
table.insert(out_elts[fname], {
digest = digest,
shingles = rspamd_logger.slog('%s', shingles),
shingles = shingles,
type = string.format('%s/%s', part:get_type())
})
else