diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-12 14:17:42 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-12 14:17:42 +0100 |
commit | ccb38eaf7f4026c0f749e9400bfb9f7eeea4d774 (patch) | |
tree | 9a77642a004e8ab16baf8752a97bcbad0aab9a26 /src/lua | |
parent | ccbea4cd96f78ba8be54987d9cd1b6e37805217f (diff) | |
download | rspamd-ccb38eaf7f4026c0f749e9400bfb9f7eeea4d774.tar.gz rspamd-ccb38eaf7f4026c0f749e9400bfb9f7eeea4d774.zip |
[Feature] Add more functions to extract data from text parts
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_mimepart.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 39ab9c8a3..9f58dfa8c 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -47,11 +47,23 @@ end LUA_FUNCTION_DEF (textpart, is_utf); /*** * @method text_part:get_content() - * Get the text of the part + * Get the text of the part (html tags stripped) * @return {text} `UTF8` encoded content of the part (zero-copy if not converted to a lua string) */ LUA_FUNCTION_DEF (textpart, get_content); /*** + * @method text_part:get_raw_content() + * Get the original text of the part + * @return {text} `UTF8` encoded content of the part (zero-copy if not converted to a lua string) + */ +LUA_FUNCTION_DEF (textpart, get_raw_content); +/*** + * @method text_part:get_content_oneline() + *Get the text of the part (html tags and newlines stripped) + * @return {text} `UTF8` encoded content of the part (zero-copy if not converted to a lua string) + */ +LUA_FUNCTION_DEF (textpart, get_content_oneline); +/*** * @method text_part:get_length() * Get length of the text of the part * @return {integer} length of part in **bytes** @@ -109,6 +121,8 @@ LUA_FUNCTION_DEF (textpart, get_mimepart); static const struct luaL_reg textpartlib_m[] = { LUA_INTERFACE_DEF (textpart, is_utf), LUA_INTERFACE_DEF (textpart, get_content), + LUA_INTERFACE_DEF (textpart, get_raw_content), + 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_lines_count), @@ -334,6 +348,46 @@ lua_textpart_get_content (lua_State * L) } static gint +lua_textpart_get_raw_content (lua_State * L) +{ + struct rspamd_mime_text_part *part = lua_check_textpart (L); + struct rspamd_lua_text *t; + + if (part == NULL || IS_PART_EMPTY (part)) { + lua_pushnil (L); + return 1; + } + + t = lua_newuserdata (L, sizeof (*t)); + rspamd_lua_setclass (L, "rspamd{text}", -1); + t->start = part->orig->data; + t->len = part->orig->len; + t->own = FALSE; + + return 1; +} + +static gint +lua_textpart_get_content_oneline (lua_State * L) +{ + struct rspamd_mime_text_part *part = lua_check_textpart (L); + struct rspamd_lua_text *t; + + if (part == NULL || IS_PART_EMPTY (part)) { + lua_pushnil (L); + return 1; + } + + t = lua_newuserdata (L, sizeof (*t)); + rspamd_lua_setclass (L, "rspamd{text}", -1); + t->start = part->stripped_content->data; + t->len = part->stripped_content->len; + t->own = FALSE; + + return 1; +} + +static gint lua_textpart_get_length (lua_State * L) { struct rspamd_mime_text_part *part = lua_check_textpart (L); |