diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-09 16:54:31 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-09 16:54:31 +0100 |
commit | 0b979e1351d1d5ff6d42f42391469ce366c18154 (patch) | |
tree | ed22fdd9bf1473d2da0e7126d57dff2d1cc17f32 /src/lua/lua_mimepart.c | |
parent | 56e236efa012c4be6b3893314ce4d3a570e16327 (diff) | |
download | rspamd-0b979e1351d1d5ff6d42f42391469ce366c18154.tar.gz rspamd-0b979e1351d1d5ff6d42f42391469ce366c18154.zip |
[Project] Lua_magic: Adopt lua_magic stuff in mime_types
Diffstat (limited to 'src/lua/lua_mimepart.c')
-rw-r--r-- | src/lua/lua_mimepart.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index dfc4ee8fa..fdc793ad8 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -365,19 +365,26 @@ LUA_FUNCTION_DEF (mimepart, get_type_full); /*** * @method mime_part:get_detected_type() - * Extract content-type string of the mime part. Use libmagic detection + * Extract content-type string of the mime part. Use lua_magic detection * @return {string,string} content type in form 'type','subtype' */ LUA_FUNCTION_DEF (mimepart, get_detected_type); /*** * @method mime_part:get_detected_type_full() - * Extract content-type string of the mime part with all attributes. Use libmagic detection + * Extract content-type string of the mime part with all attributes. Use lua_magic detection * @return {string,string,table} content type in form 'type','subtype', {attrs} */ LUA_FUNCTION_DEF (mimepart, get_detected_type_full); /*** + * @method mime_part:get_detected_ext() + * Returns a msdos extension name according to lua_magic detection + * @return {string} detected extension (see lua_magic.types) + */ +LUA_FUNCTION_DEF (mimepart, get_detected_ext); + +/*** * @method mime_part:get_cte() * Extract content-transfer-encoding for a part * @return {string} content transfer encoding (e.g. `base64` or `7bit`) @@ -523,6 +530,7 @@ static const struct luaL_reg mimepartlib_m[] = { LUA_INTERFACE_DEF (mimepart, get_type), LUA_INTERFACE_DEF (mimepart, get_type_full), LUA_INTERFACE_DEF (mimepart, get_detected_type), + LUA_INTERFACE_DEF (mimepart, get_detected_ext), LUA_INTERFACE_DEF (mimepart, get_detected_type_full), LUA_INTERFACE_DEF (mimepart, get_cte), LUA_INTERFACE_DEF (mimepart, get_filename), @@ -1495,6 +1503,26 @@ lua_mimepart_get_detected_type_full (lua_State * L) } static gint +lua_mimepart_get_detected_ext (lua_State * L) +{ + LUA_TRACE_POINT; + struct rspamd_mime_part *part = lua_check_mimepart (L); + + if (part == NULL) { + return luaL_error (L, "invalid arguments"); + } + + if (part->detected_ext) { + lua_pushstring (L, part->detected_ext); + } + else { + lua_pushnil (L); + } + + return 1; +} + +static gint lua_mimepart_get_cte (lua_State * L) { LUA_TRACE_POINT; |