From a3ef64be4a40f1a57914573d8f686a398652640b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 31 Mar 2015 13:27:00 +0100 Subject: [PATCH] Add function to test whether textpart is utf. --- src/lua/lua_task.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index e8814e871..96292bee8 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -499,6 +499,8 @@ static const struct luaL_reg tasklib_m[] = { * This module provides access to text parts found in a message */ +LUA_FUNCTION_DEF (textpart, is_utf); + /*** * @method textpart:get_content() * Get parsed content of a part @@ -544,6 +546,7 @@ LUA_FUNCTION_DEF (textpart, get_language); LUA_FUNCTION_DEF (textpart, compare_distance); static const struct luaL_reg textpartlib_m[] = { + LUA_INTERFACE_DEF (textpart, is_utf), LUA_INTERFACE_DEF (textpart, get_content), LUA_INTERFACE_DEF (textpart, get_length), LUA_INTERFACE_DEF (textpart, is_empty), @@ -2025,6 +2028,26 @@ rspamd_config.R_EMPTY_IMAGE = function (task) end */ +/*** + * @method text_part:is_utf() + * Return TRUE if part is a valid utf text + * @return {boolean} true if part is valid `UTF8` part + */ +static gint +lua_textpart_is_utf (lua_State * L) +{ + struct mime_text_part *part = lua_check_textpart (L); + + if (part == NULL || part->is_empty) { + lua_pushboolean (L, FALSE); + return 1; + } + + lua_pushboolean (L, part->is_utf); + + return 1; +} + /*** * @method text_part:get_content() * Get the text of the part -- 2.39.5