commit e81fe08: Merge pull request #3336 from rm-minus-rf/master

GitHub noreply at github.com
Sat Apr 18 09:21:21 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-04-18 10:19:05 +0100
URL: https://github.com/rspamd/rspamd/commit/e81fe0882df81045ef43f9741546b5a60752b115 (HEAD -> master)

Merge pull request #3336 from rm-minus-rf/master
[Feature] allow variables in force_actions messages

 lualib/lua_selectors/extractors.lua | 41 ++++++++++++++++++++++++++++++++++++-
 lualib/lua_selectors/transforms.lua | 21 ++++++++++++++++++-
 src/plugins/lua/force_actions.lua   | 28 ++++++++++++++++++++++++-
 3 files changed, 87 insertions(+), 3 deletions(-)

diff --combined lualib/lua_selectors/transforms.lua
index 5f1a4dca0,b1088aa75..4cfff3654
--- a/lualib/lua_selectors/transforms.lua
+++ b/lualib/lua_selectors/transforms.lua
@@@ -143,10 -143,6 +143,10 @@@ local transform_function = 
          s = h:hex()
        elseif encoding == 'base32' then
          s = h:base32()
 +      elseif encoding == 'bleach32' then
 +        s = h:base32('bleach')
 +      elseif encoding == 'rbase32' then
 +        s = h:base32('rfc')
        elseif encoding == 'base64' then
          s = h:base64()
        end
@@@ -154,7 -150,7 +154,7 @@@
        return s,'string'
      end,
      ['description'] = [[Create a digest from a string.
 -The first argument is encoding (`hex`, `base32`, `base64`),
 +The first argument is encoding (`hex`, `base32` (and forms `bleach32`, `rbase32`), `base64`),
  the second 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()}
@@@ -417,8 -413,27 +417,27 @@@ Empty string comes the first argument o
      ['args_schema'] = {(ts.number + ts.string / tonumber),
                         (ts.number + ts.string / tonumber):is_optional()}
    },
+   -- Returns the string(s) with all non ascii chars replaced
+   ['to_ascii'] = {
+     ['types'] = {
+       ['string'] = true,
+       ['list'] = true,
+     },
+     ['map_type'] = 'string',
+     ['process'] = function(inp, _, args)
+       if type(inp) == 'table' then
+         return fun.map( function(s) return string.gsub(tostring(s), '[\128-\255]', args[1] or '?') end , inp), 'string_list'
+       else 
+         return string.gsub(tostring(inp), '[\128-\255]', '?'), 'string'
+       end
+ 	  
+     end,
+     ['description'] = 'Returns the string with all non-ascii bytes replaced with the character given as second argument or `?`',
+     ['args_schema'] = {ts.string:is_optional()}
+   },
+ 
  }
  
  transform_function.match = transform_function.regexp
  
- return transform_function
+ return transform_function


More information about the Commits mailing list