]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add method to get urls length in a text part
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Aug 2016 11:56:31 +0000 (12:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 5 Aug 2016 12:05:45 +0000 (13:05 +0100)
src/lua/lua_mimepart.c

index 9f58dfa8ce47f07a85bd08bfdc0fd9ee57220ae7..6cf0b8f23b74472673bc9e02c267c2ca1c2b4043 100644 (file)
@@ -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)
 {