aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-13 12:26:29 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-13 12:26:29 +0100
commitda5d88e6bda4320fbdbe78a07ea277320098009f (patch)
tree083e7d32cc0e2d621592a8303d5889be145c0740 /src/lua
parent16c229e069e0b28f463484b2e894471b95ccd3a6 (diff)
downloadrspamd-da5d88e6bda4320fbdbe78a07ea277320098009f.tar.gz
rspamd-da5d88e6bda4320fbdbe78a07ea277320098009f.zip
Add textpart:get_words_count method
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_mimepart.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index d8e04024d..dc97de3db 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -79,6 +79,12 @@ LUA_FUNCTION_DEF (textpart, get_raw_length);
*/
LUA_FUNCTION_DEF (textpart, get_lines_count);
/***
+ * @method mime_part:get_words_count()
+ * Get words number in the part
+ * @return {integer} number of words in the part
+ */
+LUA_FUNCTION_DEF (textpart, get_words_count);
+/***
* @method text_part:is_empty()
* Returns `true` if the specified part is empty
* @return {bool} whether a part is empty
@@ -115,6 +121,7 @@ static const struct luaL_reg textpartlib_m[] = {
LUA_INTERFACE_DEF (textpart, get_length),
LUA_INTERFACE_DEF (textpart, get_raw_length),
LUA_INTERFACE_DEF (textpart, get_lines_count),
+ LUA_INTERFACE_DEF (textpart, get_words_count),
LUA_INTERFACE_DEF (textpart, is_empty),
LUA_INTERFACE_DEF (textpart, is_html),
LUA_INTERFACE_DEF (textpart, get_html),
@@ -339,6 +346,26 @@ lua_textpart_get_lines_count (lua_State * L)
}
static gint
+lua_textpart_get_words_count (lua_State *L)
+{
+ struct mime_text_part *part = lua_check_textpart (L);
+
+ if (part == NULL) {
+ lua_pushnil (L);
+ return 1;
+ }
+
+ if (IS_PART_EMPTY (part) || part->normalized_words == NULL) {
+ lua_pushnumber (L, 0);
+ }
+ else {
+ lua_pushnumber (L, part->normalized_words->len);
+ }
+
+ return 1;
+}
+
+static gint
lua_textpart_is_empty (lua_State * L)
{
struct mime_text_part *part = lua_check_textpart (L);