diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-12 17:01:41 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-12 17:01:41 +0100 |
commit | af9c1b5d66d1b63ae15746a8a0abdb0de76f7b4a (patch) | |
tree | 882608b469df04e3f18154265389b9b6c58e174d /lualib/lua_util.lua | |
parent | 15c4872c3bf55d764c1d5f2f2889391fb42a7fd0 (diff) | |
download | rspamd-af9c1b5d66d1b63ae15746a8a0abdb0de76f7b4a.tar.gz rspamd-af9c1b5d66d1b63ae15746a8a0abdb0de76f7b4a.zip |
[Minor] Lua_util: Add maybe_smtp_quote_value
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r-- | lualib/lua_util.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index bcb697e2c..a7a0e6938 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -1431,4 +1431,20 @@ exports.is_skip_local_or_authed = function(task, conf, ip) return false end +---[[[ +-- @function lua_util.maybe_smtp_quote_value(str) +-- Checks string for the forbidden elements (tspecials in RFC and quote string if needed) +-- @param {string} str input string +-- @return {string} original or quoted string +--]]] +local tspecial = lpeg.S"()<>@,;:\\\"/[]?= \t\v" +local special_match = lpeg.P((1 - tspecial)^0 * tspecial^1) +exports.maybe_smtp_quote_value = function(str) + if special_match:match(str) then + return string.format('"%s"', str:gsub('"', '\\"')) + end + + return str +end + return exports |