From: Vsevolod Stakhov Date: Thu, 23 Jul 2015 15:11:25 +0000 (+0100) Subject: Add textpart:get_raw_length method X-Git-Tag: 1.0.0~300 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a3cfc0f8bde8975daf7f448ca19e31cf245fe7c1;p=rspamd.git Add textpart:get_raw_length method --- 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 @@ -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_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 @@ -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 { @@ -292,6 +299,26 @@ lua_textpart_get_length (lua_State * L) return 1; } +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) {