diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-06-21 19:06:01 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-06-21 19:06:30 +0100 |
commit | 159c71b504e538f0e8135172129dd5acdce7880b (patch) | |
tree | 9621dacd50f5fc3c1f979b9c7ad18042d9e94a51 /src/lua/lua_mimepart.c | |
parent | d7fd796275d2edd16da117521b4eef29bea21864 (diff) | |
download | rspamd-159c71b504e538f0e8135172129dd5acdce7880b.tar.gz rspamd-159c71b504e538f0e8135172129dd5acdce7880b.zip |
[Feature] Add text_part:get_stats function
Diffstat (limited to 'src/lua/lua_mimepart.c')
-rw-r--r-- | src/lua/lua_mimepart.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index d83125044..75b270189 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -108,6 +108,18 @@ LUA_FUNCTION_DEF (textpart, get_urls_length); */ LUA_FUNCTION_DEF (textpart, get_lines_count); /*** + * @method mime_part:get_stats() + * Returns a table with the following data: + * - `lines`: number of lines + * - `spaces`: number of spaces + * - `double_spaces`: double spaces + * - `empty_lines`: number of empty lines + * - `non_ascii_characters`: number of non ascii characters + * - `ascii_characters`: number of ascii characters + * @return {table} table of stats + */ +LUA_FUNCTION_DEF (textpart, get_stats); +/*** * @method mime_part:get_words_count() * Get words number in the part * @return {integer} number of words in the part @@ -161,6 +173,7 @@ static const struct luaL_reg textpartlib_m[] = { LUA_INTERFACE_DEF (textpart, get_html), LUA_INTERFACE_DEF (textpart, get_language), LUA_INTERFACE_DEF (textpart, get_mimepart), + LUA_INTERFACE_DEF (textpart, get_stats), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; @@ -715,6 +728,55 @@ lua_textpart_get_mimepart (lua_State * L) return 1; } +/*** + * @method mime_part:get_stats() + * Returns a table with the following data: + * - + * - `lines`: number of lines + * - `spaces`: number of spaces + * - `double_spaces`: double spaces + * - `empty_lines`: number of empty lines + * - `non_ascii_characters`: number of non ascii characters + * - `ascii_characters`: number of ascii characters + * @return {table} table of stats + */ +static gint +lua_textpart_get_stats (lua_State * L) +{ + struct rspamd_mime_text_part *part = lua_check_textpart (L); + + if (part != NULL) { + lua_createtable (L, 0, 7); + + lua_pushstring (L, "lines"); + lua_pushnumber (L, part->nlines); + lua_settable (L, -3); + lua_pushstring (L, "empty_lines"); + lua_pushnumber (L, part->empty_lines); + lua_settable (L, -3); + lua_pushstring (L, "spaces"); + lua_pushnumber (L, part->spaces); + lua_settable (L, -3); + lua_pushstring (L, "non_spaces"); + lua_pushnumber (L, part->non_spaces); + lua_settable (L, -3); + lua_pushstring (L, "double_spaces"); + lua_pushnumber (L, part->double_spaces); + lua_settable (L, -3); + lua_pushstring (L, "ascii_characters"); + lua_pushnumber (L, part->ascii_chars); + lua_settable (L, -3); + lua_pushstring (L, "non_ascii_characters"); + lua_pushnumber (L, part->non_ascii_chars); + lua_settable (L, -3); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + /* Mimepart implementation */ static gint |