]> source.dussan.org Git - rspamd.git/commitdiff
Add function to test whether textpart is utf.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 31 Mar 2015 12:27:00 +0000 (13:27 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 31 Mar 2015 12:27:00 +0000 (13:27 +0100)
src/lua/lua_task.c

index e8814e871ce39f6f78c8513fd151570e80bab591..96292bee82c79bf69a039813290f8c375da41a29 100644 (file)
@@ -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