From ccb38eaf7f4026c0f749e9400bfb9f7eeea4d774 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 12 Jul 2016 14:17:42 +0100 Subject: [PATCH] [Feature] Add more functions to extract data from text parts --- src/lua/lua_mimepart.c | 56 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 39ab9c8a30..9f58dfa8ce 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -47,10 +47,22 @@ 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 @@ -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), @@ -333,6 +347,46 @@ lua_textpart_get_content (lua_State * L) return 1; } +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) { -- 2.47.3