From: Vsevolod Stakhov Date: Mon, 17 Dec 2018 16:52:46 +0000 (+0000) Subject: [Minor] Lua_mimepart: Add get_parent method X-Git-Tag: 1.9.0~405 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb63f8504023cc6cb0b8cf17911cbbc215a4940c;p=thirdparty%2Frspamd.git [Minor] Lua_mimepart: Add get_parent method --- diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 09ccdf47da..50cdaa7b79 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -487,6 +487,13 @@ LUA_FUNCTION_DEF (mimepart, is_broken); * @param {table} params optional parameters */ LUA_FUNCTION_DEF (mimepart, headers_foreach); +/*** + * @method mime_part:get_parent() + * Returns parent part for this part + * @return {rspamd_mimepart} parent part or nil + */ +LUA_FUNCTION_DEF (mimepart, get_parent); + static const struct luaL_reg mimepartlib_m[] = { LUA_INTERFACE_DEF (mimepart, get_content), @@ -511,6 +518,7 @@ static const struct luaL_reg mimepartlib_m[] = { LUA_INTERFACE_DEF (mimepart, is_multipart), LUA_INTERFACE_DEF (mimepart, is_message), LUA_INTERFACE_DEF (mimepart, get_children), + LUA_INTERFACE_DEF (mimepart, get_parent), LUA_INTERFACE_DEF (mimepart, is_text), LUA_INTERFACE_DEF (mimepart, is_broken), LUA_INTERFACE_DEF (mimepart, is_attachment), @@ -1672,6 +1680,29 @@ lua_mimepart_get_children (lua_State * L) return 1; } +static gint +lua_mimepart_get_parent (lua_State * L) +{ + LUA_TRACE_POINT; + struct rspamd_mime_part *part = lua_check_mimepart (L); + struct rspamd_mime_part **pparent; + + if (part == NULL) { + return luaL_error (L, "invalid arguments"); + } + + if (part->parent_part) { + pparent = lua_newuserdata (L, sizeof (*pparent)); + *pparent = part->parent_part; + rspamd_lua_setclass (L, "rspamd{mimepart}", -1); + } + else { + lua_pushnil (L); + } + + return 1; +} + static gint lua_mimepart_get_text (lua_State * L)