From f05607bf6a96ccb0a7d87d5fc51beaa5e1ce6bb9 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Tue, 22 Mar 2016 11:50:08 +0300 Subject: [PATCH] [Feature] Add list support to `mime types` module configuration - this change allows to configure several mime types for an extension like ```txt = [ "message/disposition-notification", "text/plain", "text/rfc822-headers" ];``` - `type` variable replaced with `mtype` as `type` is lua reserved word --- src/plugins/lua/mime_types.lua | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index 1014480a3..2c168393b 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -39,21 +39,36 @@ local function check_mime_type(task) if parts then for _,p in ipairs(parts) do - local type,subtype = p:get_type() + local mtype,subtype = p:get_type() - if not type then + if not mtype then task:insert_result(settings['symbol_unknown'], 1.0, 'missing content type') else -- Check for attachment local filename = p:get_filename() - local ct = string.format('%s/%s', type, subtype) + local ct = string.format('%s/%s', mtype, subtype) if filename then local ext = string.match(filename, '%.([^.]+)$') if ext then - if settings['extension_map'][ext] then - if ct ~= settings['extension_map'][ext] then + local mt = settings['extension_map'][ext] + if mt then + local found = nil + if (type(mt) == "table") then + for _,v in pairs(mt) do + if ct == v then + found = true + break + end + end + else + if ct == mt then + found = true + end + end + + if not found then task:insert_result(settings['symbol_attachment'], 1.0, ext) end end -- 2.39.5