From 24e056d1d43ac9ff487aa370b9dbc3c467eead0e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 4 Jul 2018 15:51:29 +0100 Subject: [PATCH] [Feature] Implement fuzzy hashes extraction in mime tool --- lualib/rspamadm/mime.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua index f41529646e..e07f1142a1 100644 --- a/lualib/rspamadm/mime.lua +++ b/lualib/rspamadm/mime.lua @@ -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 -- 2.47.3