From: Vsevolod Stakhov Date: Mon, 12 Oct 2020 16:01:41 +0000 (+0100) Subject: [Minor] Lua_util: Add maybe_smtp_quote_value X-Git-Tag: 2.7~246 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af9c1b5d66d1b63ae15746a8a0abdb0de76f7b4a;p=thirdparty%2Frspamd.git [Minor] Lua_util: Add maybe_smtp_quote_value --- diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index bcb697e2c5..a7a0e69383 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