aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-25 13:26:17 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-25 13:26:17 +0000
commit82d8d983b1f1a2f53daea13325690651086f2c82 (patch)
treed7134e49bfc4d141bd3a1957950ec8ef30ca5c72
parent205485cf1645379a7c7df5c578fad55d99d8dad5 (diff)
downloadrspamd-82d8d983b1f1a2f53daea13325690651086f2c82.tar.gz
rspamd-82d8d983b1f1a2f53daea13325690651086f2c82.zip
[Project] Fix urls injection for ics files
-rw-r--r--lualib/lua_content/ical.lua35
-rw-r--r--lualib/lua_content/init.lua10
2 files changed, 32 insertions, 13 deletions
diff --git a/lualib/lua_content/ical.lua b/lualib/lua_content/ical.lua
index c19723614..8052f04b9 100644
--- a/lualib/lua_content/ical.lua
+++ b/lualib/lua_content/ical.lua
@@ -17,18 +17,37 @@ limitations under the License.
local l = require 'lpeg'
local rspamd_text = require "rspamd_text"
-local wsp = l.P" "
-local crlf = l.P"\r"^-1 * l.P"\n"
-local eol = (crlf * #crlf) + (crlf - (crlf^-1 * wsp))
-local name = l.C((l.P(1) - (l.P":"))^1) / function(v) return (v:gsub("[\n\r]+%s","")) end
-local value = l.C((l.P(1) - eol)^0) / function(v) return (v:gsub("[\n\r]+%s","")) end
-local elt = name * ":" * wsp^0 * value * eol
+local ical_grammar
+
+local function gen_grammar()
+ if not ical_grammar then
+ local wsp = l.P" "
+ local crlf = l.P"\r"^-1 * l.P"\n"
+ local eol = (crlf * #crlf) + (crlf - (crlf^-1 * wsp))
+ local name = l.C((l.P(1) - (l.P":"))^1) / function(v) return (v:gsub("[\n\r]+%s","")) end
+ local value = l.C((l.P(1) - eol)^0) / function(v) return (v:gsub("[\n\r]+%s","")) end
+ ical_grammar = name * ":" * wsp^0 * value * eol
+ end
+
+ return ical_grammar
+end
local exports = {}
-local function process_ical(input, _, _)
+local function process_ical(input, _, task)
local control={n='\n', r='\r'}
- local escaper = l.Ct((elt / function(_,b) return (b:gsub("\\(.)", control)) end)^1)
+ local rspamd_url = require "rspamd_url"
+ local escaper = l.Ct((gen_grammar() / function(_, value)
+ value = value:gsub("\\(.)", control)
+ 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
+ task:inject_url(u)
+ end
+ end
+ return value
+ end)^1)
local values = escaper:match(input)
diff --git a/lualib/lua_content/init.lua b/lualib/lua_content/init.lua
index 994d613f4..06d509e00 100644
--- a/lualib/lua_content/init.lua
+++ b/lualib/lua_content/init.lua
@@ -51,7 +51,7 @@ local function init()
end
end
-exports.maybe_process_mime_part = function(part, log_obj)
+exports.maybe_process_mime_part = function(part, task)
if not modules_by_mime_type then
init()
end
@@ -70,17 +70,17 @@ exports.maybe_process_mime_part = function(part, log_obj)
end
if pair then
- lua_util.debugm(N, log_obj, "found known content of type %s: %s",
+ lua_util.debugm(N, task, "found known content of type %s: %s",
mt, pair[1])
- local data = pair[2].module.process(part:get_content(), part, log_obj)
+ local data = pair[2].module.process(part:get_content(), part, task)
if data then
- lua_util.debugm(N, log_obj, "extracted content from %s: %s type",
+ lua_util.debugm(N, task, "extracted content from %s: %s type",
pair[1], type(data))
part:set_specific(data)
else
- lua_util.debugm(N, log_obj, "failed to extract anything from %s",
+ lua_util.debugm(N, task, "failed to extract anything from %s",
pair[1])
end
end