commit 093ad04: [Project] Add preliminary support of vcard parser
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Jan 12 15:49:07 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-01-12 15:42:08 +0000
URL: https://github.com/rspamd/rspamd/commit/093ad04f422ad28b6648324666db40e6ade38ac4
[Project] Add preliminary support of vcard parser
---
lualib/lua_content/init.lua | 6 ++++++
lualib/lua_content/{ical.lua => vcard.lua} | 29 +++++++++++++++--------------
2 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/lualib/lua_content/init.lua b/lualib/lua_content/init.lua
index 7bf42b9a1..7947f16ab 100644
--- a/lualib/lua_content/init.lua
+++ b/lualib/lua_content/init.lua
@@ -31,6 +31,12 @@ local content_modules = {
extensions = {'ics'},
output = "text"
},
+ vcf = {
+ mime_type = {"text/vcard", "application/vcard"},
+ module = require "lua_content/vcard",
+ extensions = {'vcf'},
+ output = "text"
+ },
pdf = {
mime_type = "application/pdf",
module = require "lua_content/pdf",
diff --git a/lualib/lua_content/ical.lua b/lualib/lua_content/vcard.lua
similarity index 71%
copy from lualib/lua_content/ical.lua
copy to lualib/lua_content/vcard.lua
index d5a49de2b..123799954 100644
--- a/lualib/lua_content/ical.lua
+++ b/lualib/lua_content/vcard.lua
@@ -1,5 +1,5 @@
--[[
-Copyright (c) 2019, Vsevolod Stakhov <vsevolod at highsecure.ru>
+Copyright (c) 2021, Vsevolod Stakhov <vsevolod at highsecure.ru>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,19 +18,20 @@ local l = require 'lpeg'
local lua_util = require "lua_util"
local N = "lua_content"
-local ical_grammar
+local vcard_grammar
+-- XXX: Currently it is a copy of ical grammar
local function gen_grammar()
- if not ical_grammar then
+ if not vcard_grammar then
local wsp = l.S(" \t\v\f")
- local crlf = l.P"\r"^-1 * l.P"\n"
+ local crlf = (l.P"\r"^-1 * l.P"\n") + l.P"\r"
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^-1
+ vcard_grammar = name * ":" * wsp^0 * value * eol^-1
end
- return ical_grammar
+ return vcard_grammar
end
local exports = {}
@@ -42,7 +43,7 @@ local function extract_text_data(specific)
return table.concat(tbl, '\n')
end
-local function process_ical(input, mpart, task)
+local function process_vcard(input, mpart, task)
local control={n='\n', r=''}
local rspamd_url = require "rspamd_url"
local escaper = l.Ct((gen_grammar() / function(key, value)
@@ -52,12 +53,12 @@ local function process_ical(input, mpart, task)
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',
+ lua_util.debugm(N, task, 'vcard: found URL in vcard %s',
tostring(u))
task:inject_url(u, mpart)
end
end
- lua_util.debugm(N, task, 'ical: ical key %s = "%s"',
+ lua_util.debugm(N, task, 'vcard: vcard key %s = "%s"',
key, value)
return {key, value}
end)^1)
@@ -69,16 +70,16 @@ local function process_ical(input, mpart, task)
end
return {
- tag = 'ical',
- extract_text = extract_text_data,
+ tag = 'vcard',
+ extract_text = function() return nil end, -- NYI
elts = elts
}
end
--[[[
--- @function lua_ical.process(input)
--- Returns all values from ical as a plain text. Names are completely ignored.
+-- @function vcard.process(input)
+-- Returns all values from vcard as a plain text. Names are completely ignored.
--]]
-exports.process = process_ical
+exports.process = process_vcard
return exports
\ No newline at end of file
More information about the Commits
mailing list