commit 839a733: [Feature] Mime_types: When no extension defined, detect it by content
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Mar 22 15:00:04 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-03-22 14:56:05 +0000
URL: https://github.com/rspamd/rspamd/commit/839a733a70eebc81bab8ce0cdc547419926f1cba
[Feature] Mime_types: When no extension defined, detect it by content
---
src/plugins/lua/mime_types.lua | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua
index 8392d3183..10f015bd6 100644
--- a/src/plugins/lua/mime_types.lua
+++ b/src/plugins/lua/mime_types.lua
@@ -823,6 +823,9 @@ local full_extensions_map = {
{"zlib", "application/zlib"},
}
+-- Used to match extension by content type
+local reversed_extensions_map = {}
+
local function check_mime_type(task)
local function gen_extension(fname)
local parts = lua_util.str_split(fname or '', '.')
@@ -835,7 +838,7 @@ local function check_mime_type(task)
return ext[1],ext[2],parts
end
- local function check_filename(fname, ct, is_archive, part)
+ local function check_filename(fname, ct, is_archive, part, detected_ct)
local has_bad_unicode, char, ch_pos = rspamd_util.has_obscured_unicode(fname)
if has_bad_unicode then
@@ -859,6 +862,11 @@ local function check_mime_type(task)
-- ext is the last extension, LOWERCASED
-- ext2 is the one before last extension LOWERCASED
+ if not ext and detected_ct then
+ -- Try to find extension by real content type
+ ext = reversed_extensions_map[detected_ct]
+ end
+
local function check_extension(badness_mult, badness_mult2)
if not badness_mult and not badness_mult2 then return end
if #parts > 2 then
@@ -1158,6 +1166,12 @@ if opts then
end
end
+ for ext,inner_tbl in pairs(settings.extension_map) do
+ for _,elt in ipairs(inner_tbl) do
+ reversed_extensions_map[elt.ct] = ext
+ end
+ end
+
local type = 'map'
if settings['regexp'] then type = 'regexp' end
map = rspamd_map_add('mime_types', 'file', type,
More information about the Commits
mailing list