diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-03-22 14:56:05 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-03-22 14:56:05 +0000 |
commit | 839a733a70eebc81bab8ce0cdc547419926f1cba (patch) | |
tree | 5ba737860b713ccf00bc9d0b11aac32c053d4d2e /src/plugins/lua | |
parent | e964621bb78b876e9b25dae12d61ab51f344462c (diff) | |
download | rspamd-839a733a70eebc81bab8ce0cdc547419926f1cba.tar.gz rspamd-839a733a70eebc81bab8ce0cdc547419926f1cba.zip |
[Feature] Mime_types: When no extension defined, detect it by content
Diffstat (limited to 'src/plugins/lua')
-rw-r--r-- | src/plugins/lua/mime_types.lua | 16 |
1 files changed, 15 insertions, 1 deletions
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, |