From: Vsevolod Stakhov Date: Mon, 24 Apr 2017 15:59:10 +0000 (+0100) Subject: [Minor] Add lua methods to detect if a part has 8bit characters X-Git-Tag: 1.6.0~328 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0d3cf178888070d4cd057507b8b0a9140c3dbaea;p=rspamd.git [Minor] Add lua methods to detect if a part has 8bit characters --- 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) {