summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-05 12:56:31 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-05 13:05:45 +0100
commitf11b865a106c5cb8310745f92e84fa2866237e26 (patch)
tree20b831a248c432f0a507c3677985321c3d23ea71 /src/lua
parent34eea43c42c334b44a047fa58135530d8ee944d6 (diff)
downloadrspamd-f11b865a106c5cb8310745f92e84fa2866237e26.tar.gz
rspamd-f11b865a106c5cb8310745f92e84fa2866237e26.zip
[Feature] Add method to get urls length in a text part
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_mimepart.c33
1 files changed, 33 insertions, 0 deletions
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
@@ -76,6 +76,12 @@ LUA_FUNCTION_DEF (textpart, get_length);
*/
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
* @return {integer} number of lines 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),
@@ -428,6 +435,32 @@ lua_textpart_get_raw_length (lua_State * L)
}
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)
{
struct rspamd_mime_text_part *part = lua_check_textpart (L);