diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-12-17 16:52:46 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-12-17 16:52:46 +0000 |
commit | fb63f8504023cc6cb0b8cf17911cbbc215a4940c (patch) | |
tree | 429217aa25db0db2a152df0ffe2adbdf2a56bb0b | |
parent | 9d6b1b71b6fb63d13d0cd026118340c0bf8c82af (diff) | |
download | rspamd-fb63f8504023cc6cb0b8cf17911cbbc215a4940c.tar.gz rspamd-fb63f8504023cc6cb0b8cf17911cbbc215a4940c.zip |
[Minor] Lua_mimepart: Add get_parent method
-rw-r--r-- | src/lua/lua_mimepart.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 09ccdf47d..50cdaa7b7 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) |