From fa56db1cf6956a6418342d10a9efcf4677ac35a2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 23 Jul 2015 15:23:44 +0100 Subject: Add text_part:get_html() method. --- src/lua/lua_mimepart.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/lua/lua_mimepart.c') diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 323ebfd32..d14af08a2 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -85,6 +85,12 @@ LUA_FUNCTION_DEF (textpart, is_empty); * @return {bool} whether a part is HTML part */ LUA_FUNCTION_DEF (textpart, is_html); +/*** + * @method text_part:get_html() + * Returns html content of the specified part + * @return {html} html content + */ +LUA_FUNCTION_DEF (textpart, get_html); /*** * @method text_part:get_language() * Returns the code of the most used unicode script in the text part. Does not work with raw parts @@ -105,6 +111,7 @@ static const struct luaL_reg textpartlib_m[] = { LUA_INTERFACE_DEF (textpart, get_lines_count), LUA_INTERFACE_DEF (textpart, is_empty), LUA_INTERFACE_DEF (textpart, is_html), + LUA_INTERFACE_DEF (textpart, get_html), LUA_INTERFACE_DEF (textpart, get_language), LUA_INTERFACE_DEF (textpart, get_mimepart), {"__tostring", rspamd_lua_class_tostring}, @@ -335,6 +342,23 @@ lua_textpart_is_html (lua_State * L) return 1; } +static gint +lua_textpart_get_html (lua_State * L) +{ + struct mime_text_part *part = lua_check_textpart (L); + struct html_content **phc; + + if (part == NULL || part->html == NULL) { + lua_pushnil (L); + } + else { + phc = lua_newuserdata (L, sizeof (*phc)); + rspamd_lua_setclass (L, "rspamd{html}", -1); + *phc = part->html; + } + + return 1; +} static gint lua_textpart_get_language (lua_State * L) -- cgit v1.2.3