aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-29 15:43:13 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-29 15:43:13 +0100
commit9803c45058f5e7671a6686249c31ba32228df5a0 (patch)
treecaf279fd063e2c672ea4f720d2903dc893c62c41 /src
parent48de4f8df4c808f14030006add82a34b75523b3e (diff)
downloadrspamd-9803c45058f5e7671a6686249c31ba32228df5a0.tar.gz
rspamd-9803c45058f5e7671a6686249c31ba32228df5a0.zip
Add line counts to lua mimepart API.
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_mimepart.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index e83ba1770..f1012811a 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -68,6 +68,12 @@ LUA_FUNCTION_DEF (textpart, get_content);
*/
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
* @return {bool} whether a 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),
@@ -289,6 +296,26 @@ lua_textpart_get_length (lua_State * L)
}
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)
{
struct mime_text_part *part = lua_check_textpart (L);