From fd3444e7a595689809ad07150c74cc755c7e8d59 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 24 Apr 2017 16:59:10 +0100 Subject: [PATCH] [Minor] Add lua methods to detect if a part has 8bit characters --- src/lua/lua_mimepart.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 581a2c260..ae79880b2 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -45,6 +45,21 @@ end * @return {boolean} true if part is valid `UTF8` part */ LUA_FUNCTION_DEF (textpart, is_utf); + +/*** + * @method text_part:is_8bit_raw() + * Return TRUE if a part has raw 8bit characters + * @return {boolean} true if a part has raw 8bit characters + */ +LUA_FUNCTION_DEF (textpart, is_8bit_raw); + +/*** + * @method text_part:is_8bit() + * Return TRUE if a part has raw 8bit characters + * @return {boolean} true if a part has encoded 8bit characters + */ +LUA_FUNCTION_DEF (textpart, is_8bit); + /*** * @method text_part:get_content([type]) * Get the text of the part (html tags stripped). Optional `type` defines type of content to get: @@ -131,6 +146,8 @@ LUA_FUNCTION_DEF (textpart, get_mimepart); static const struct luaL_reg textpartlib_m[] = { LUA_INTERFACE_DEF (textpart, is_utf), + LUA_INTERFACE_DEF (textpart, is_8bit_raw), + LUA_INTERFACE_DEF (textpart, is_8bit), LUA_INTERFACE_DEF (textpart, get_content), LUA_INTERFACE_DEF (textpart, get_raw_content), LUA_INTERFACE_DEF (textpart, get_content_oneline), @@ -377,6 +394,47 @@ lua_textpart_is_utf (lua_State * L) } +static gint +lua_textpart_is_8bit_raw (lua_State * L) +{ + struct rspamd_mime_text_part *part = lua_check_textpart (L); + + if (part) { + if (part->flags & RSPAMD_MIME_TEXT_PART_FLAG_8BIT) { + lua_pushboolean (L, TRUE); + } + else { + lua_pushboolean (L, FALSE); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +static gint +lua_textpart_is_8bit (lua_State * L) +{ + struct rspamd_mime_text_part *part = lua_check_textpart (L); + + if (part) { + if (part->flags & RSPAMD_MIME_TEXT_PART_FLAG_8BIT_ENCODED) { + lua_pushboolean (L, TRUE); + } + else { + lua_pushboolean (L, FALSE); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + + static gint lua_textpart_get_content (lua_State * L) { -- 2.39.5