From: Vsevolod Stakhov Date: Tue, 31 Mar 2015 12:27:00 +0000 (+0100) Subject: Add function to test whether textpart is utf. X-Git-Tag: 0.9.0~379 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3ef64be4a40f1a57914573d8f686a398652640b;p=thirdparty%2Frspamd.git Add function to test whether textpart is utf. --- diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index e8814e871c..96292bee82 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