diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-26 17:29:42 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-26 17:29:42 +0000 |
commit | d90b05640bcea0544ea698ccec35abbfd2e313b0 (patch) | |
tree | 57aa2fa7bf67176eb6cb93519a506b3d62a95bb0 /lualib/lua_content/ical.lua | |
parent | 69b1c2e53f9427a6529f4a1b296de8f8f1ee7322 (diff) | |
download | rspamd-d90b05640bcea0544ea698ccec35abbfd2e313b0.tar.gz rspamd-d90b05640bcea0544ea698ccec35abbfd2e313b0.zip |
[Project] Some rework about specific data that is now tagged
Diffstat (limited to 'lualib/lua_content/ical.lua')
-rw-r--r-- | lualib/lua_content/ical.lua | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lualib/lua_content/ical.lua b/lualib/lua_content/ical.lua index 8052f04b9..bb2f52771 100644 --- a/lualib/lua_content/ical.lua +++ b/lualib/lua_content/ical.lua @@ -15,7 +15,8 @@ limitations under the License. ]]-- local l = require 'lpeg' -local rspamd_text = require "rspamd_text" +local lua_util = require "lua_util" +local N = "lua_content" local ical_grammar @@ -34,28 +35,44 @@ end local exports = {} +local function extract_text_data(specific) + local fun = require "fun" + + local tbl = fun.totable(fun.map(function(e) return e[2]:lower() end, specific.elts)) + return table.concat(tbl, '\n') +end + local function process_ical(input, _, task) - local control={n='\n', r='\r'} + local control={n='\n', r=''} local rspamd_url = require "rspamd_url" - local escaper = l.Ct((gen_grammar() / function(_, value) + local escaper = l.Ct((gen_grammar() / function(key, value) value = value:gsub("\\(.)", control) + key = key:lower() local local_urls = rspamd_url.all(task:get_mempool(), value) if local_urls and #local_urls > 0 then for _,u in ipairs(local_urls) do + lua_util.debugm(N, task, 'ical: found URL in ical %s', + tostring(u)) task:inject_url(u) end end - return value + lua_util.debugm(N, task, 'ical: ical key %s = "%s"', + key, value) + return {key, value} end)^1) - local values = escaper:match(input) + local elts = escaper:match(input) - if not values then + if not elts then return nil end - return rspamd_text.fromtable(values, "\n") + return { + tag = 'ical', + extract_text = extract_text_data, + elts = elts + } end --[[[ |