diff options
author | Carsten Rosenberg <c.rosenberg@heinlein-support.de> | 2018-11-20 19:09:58 +0100 |
---|---|---|
committer | Carsten Rosenberg <c.rosenberg@heinlein-support.de> | 2018-11-20 19:09:58 +0100 |
commit | 432e25f7d7313b10bbcb1b9eca27f65b47175165 (patch) | |
tree | 42425673dbf25ed383f1d25120478bad9e492938 | |
parent | 53b7abaeab29e89d9631a8d8dedab85f0b5ad55c (diff) | |
download | rspamd-432e25f7d7313b10bbcb1b9eca27f65b47175165.tar.gz rspamd-432e25f7d7313b10bbcb1b9eca27f65b47175165.zip |
[Minor] Selectors - add hash support to attachments selector
-rw-r--r-- | lualib/lua_selectors.lua | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua index 754795495..8092d7892 100644 --- a/lualib/lua_selectors.lua +++ b/lualib/lua_selectors.lua @@ -132,13 +132,35 @@ uses any type by default)]], }, -- Get list of all attachments digests ['attachments'] = { - ['get_value'] = function(task) + ['get_value'] = function(task, args) + + local s local parts = task:get_parts() or E local digests = {} - for _,p in ipairs(parts) do - if p:get_filename() then - table.insert(digests, p:get_digest()) + if args ~= nil then + local rspamd_cryptobox = require "rspamd_cryptobox_hash" + local encoding = args[1] or 'hex' + local ht = args[2] or 'blake2' + + for _,p in ipairs(parts) do + if p:get_filename() then + local h = rspamd_cryptobox.create_specific(ht, p:get_content('raw_parsed')) + if encoding == 'hex' then + s = h:hex() + elseif encoding == 'base32' then + s = h:base32() + elseif encoding == 'base64' then + s = h:base64() + end + table.insert(digests, s) + end + end + else + for _,p in ipairs(parts) do + if p:get_filename() then + table.insert(digests, p:get_digest()) + end end end @@ -148,7 +170,13 @@ uses any type by default)]], return nil end, - ['description'] = 'Get list of all attachments digests', + ['description'] = [[Get list of all attachments digests. +The first optional argument is encoding (`hex`, `base32`, `base64`), +the second optional argument is optional hash type (`blake2`, `sha256`, `sha1`, `sha512`, `md5`)]], + + ['args_schema'] = {ts.one_of{'hex', 'base32', 'base64'}:is_optional(), + ts.one_of{'blake2', 'sha256', 'sha1', 'sha512', 'md5'}:is_optional()} + }, -- Get all attachments files ['files'] = { @@ -937,4 +965,4 @@ exports.list_transforms = function() return display_selectors(transform_function) end -return exports
\ No newline at end of file +return exports |