From: Vsevolod Stakhov Date: Fri, 5 Aug 2016 11:56:31 +0000 (+0100) Subject: [Feature] Add method to get urls length in a text part X-Git-Tag: 1.3.2~33 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f11b865a106c5cb8310745f92e84fa2866237e26;p=rspamd.git [Feature] Add method to get urls length in a text part --- diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 9f58dfa8c..6cf0b8f23 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -75,6 +75,12 @@ LUA_FUNCTION_DEF (textpart, get_length); * @return {integer} length of part in **bytes** */ LUA_FUNCTION_DEF (textpart, get_raw_length); +/*** + * @method mime_part:get_urls_length() + * Get length of the urls within the part + * @return {integer} length of urls in **bytes** + */ +LUA_FUNCTION_DEF (textpart, get_urls_length); /*** * @method mime_part:get_lines_count() * Get lines number in the part @@ -125,6 +131,7 @@ static const struct luaL_reg textpartlib_m[] = { LUA_INTERFACE_DEF (textpart, get_content_oneline), LUA_INTERFACE_DEF (textpart, get_length), LUA_INTERFACE_DEF (textpart, get_raw_length), + LUA_INTERFACE_DEF (textpart, get_urls_length), LUA_INTERFACE_DEF (textpart, get_lines_count), LUA_INTERFACE_DEF (textpart, get_words_count), LUA_INTERFACE_DEF (textpart, is_empty), @@ -427,6 +434,32 @@ lua_textpart_get_raw_length (lua_State * L) return 1; } +static gint +lua_textpart_get_urls_length (lua_State * L) +{ + struct rspamd_mime_text_part *part = lua_check_textpart (L); + GList *cur; + guint total = 0; + struct rspamd_process_exception *ex; + + if (part == NULL) { + lua_pushnil (L); + return 1; + } + + for (cur = part->exceptions; cur != NULL; cur = g_list_next (cur)) { + ex = cur->data; + + if (ex->type == RSPAMD_EXCEPTION_URL) { + total += ex->len; + } + } + + lua_pushnumber (L, total); + + return 1; +} + static gint lua_textpart_get_lines_count (lua_State * L) {