diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-23 16:11:25 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-23 16:11:25 +0100 |
commit | a3cfc0f8bde8975daf7f448ca19e31cf245fe7c1 (patch) | |
tree | a685b19c6806b15206051e9df73080c279d52598 /src/lua/lua_mimepart.c | |
parent | fa56db1cf6956a6418342d10a9efcf4677ac35a2 (diff) | |
download | rspamd-a3cfc0f8bde8975daf7f448ca19e31cf245fe7c1.tar.gz rspamd-a3cfc0f8bde8975daf7f448ca19e31cf245fe7c1.zip |
Add textpart:get_raw_length method
Diffstat (limited to 'src/lua/lua_mimepart.c')
-rw-r--r-- | src/lua/lua_mimepart.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index d14af08a2..2cf7ef355 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_raw_length() + * Get length of the **raw** content of the part (e.g. HTML with tags unstripped) + * @return {integer} length of part in **bytes** + */ +LUA_FUNCTION_DEF (textpart, get_raw_length); +/*** * @method mime_part:get_lines_count() * Get lines number in the part * @return {integer} number of lines in the part @@ -108,6 +114,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_raw_length), LUA_INTERFACE_DEF (textpart, get_lines_count), LUA_INTERFACE_DEF (textpart, is_empty), LUA_INTERFACE_DEF (textpart, is_html), @@ -282,7 +289,7 @@ lua_textpart_get_length (lua_State * L) return 1; } - if (IS_PART_EMPTY (part)) { + if (IS_PART_EMPTY (part) || part->content == NULL) { lua_pushnumber (L, 0); } else { @@ -293,6 +300,26 @@ lua_textpart_get_length (lua_State * L) } static gint +lua_textpart_get_raw_length (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) || part->orig == NULL) { + lua_pushnumber (L, 0); + } + else { + lua_pushnumber (L, part->orig->len); + } + + return 1; +} + +static gint lua_textpart_get_lines_count (lua_State * L) { struct mime_text_part *part = lua_check_textpart (L); |