]> source.dussan.org Git - rspamd.git/commitdiff
Add line counts to lua mimepart API.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Apr 2015 14:43:13 +0000 (15:43 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Apr 2015 14:43:13 +0000 (15:43 +0100)
src/lua/lua_mimepart.c

index e83ba1770537b1246880e972b3e5880877aee373..f1012811ae0f6c03c40d1d681ef12d87c685add0 100644 (file)
@@ -67,6 +67,12 @@ LUA_FUNCTION_DEF (textpart, get_content);
  * @return {integer} length of part in **bytes**
  */
 LUA_FUNCTION_DEF (textpart, get_length);
+/***
+ * @method mime_part:get_lines_count()
+ * Get lines number in the part
+ * @return {integer} number of lines in the part
+ */
+LUA_FUNCTION_DEF (textpart, get_lines_count);
 /***
  * @method text_part:is_empty()
  * Returns `true` if the specified part is empty
@@ -106,6 +112,7 @@ static const struct luaL_reg textpartlib_m[] = {
        LUA_INTERFACE_DEF (textpart, is_utf),
        LUA_INTERFACE_DEF (textpart, get_content),
        LUA_INTERFACE_DEF (textpart, get_length),
+       LUA_INTERFACE_DEF (textpart, get_lines_count),
        LUA_INTERFACE_DEF (textpart, is_empty),
        LUA_INTERFACE_DEF (textpart, is_html),
        LUA_INTERFACE_DEF (textpart, get_fuzzy),
@@ -288,6 +295,26 @@ lua_textpart_get_length (lua_State * L)
        return 1;
 }
 
+static gint
+lua_textpart_get_lines_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)) {
+               lua_pushnumber (L, 0);
+       }
+       else {
+               lua_pushnumber (L, part->nlines);
+       }
+
+       return 1;
+}
+
 static gint
 lua_textpart_is_empty (lua_State * L)
 {