From f0a9da38f3df5b4efa75be07df129f49932f2526 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 29 Apr 2015 15:55:59 +0100 Subject: [PATCH] Allow to get mime part from text part in lua. --- src/lua/lua_mimepart.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index f1012811a..354dd3824 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -97,6 +97,12 @@ LUA_FUNCTION_DEF (textpart, get_fuzzy); * @return {string} short abbreviation (such as `ru`) for the script's language */ LUA_FUNCTION_DEF (textpart, get_language); +/*** + * @method text_part:get_mimepart() + * Returns the mime part object corresponding to this text part + * @return {mimepart} mimepart object + */ +LUA_FUNCTION_DEF (textpart, get_mimepart); /*** * @method text_part:compare_distance(other) * Calculates the difference to another text part. This function is intended to work with @@ -117,6 +123,7 @@ static const struct luaL_reg textpartlib_m[] = { LUA_INTERFACE_DEF (textpart, is_html), LUA_INTERFACE_DEF (textpart, get_fuzzy), LUA_INTERFACE_DEF (textpart, get_language), + LUA_INTERFACE_DEF (textpart, get_mimepart), LUA_INTERFACE_DEF (textpart, compare_distance), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} @@ -380,6 +387,26 @@ lua_textpart_get_language (lua_State * L) return 1; } +static gint +lua_textpart_get_mimepart (lua_State * L) +{ + struct mime_text_part *part = lua_check_textpart (L); + struct mime_part **pmime; + + if (part != NULL) { + if (part->mime_part != NULL) { + pmime = lua_newuserdata (L, sizeof (struct mime_part *)); + rspamd_lua_setclass (L, "rspamd{mimepart}", -1); + *pmime = part->mime_part; + + return 1; + } + } + + lua_pushnil (L); + return 1; +} + static gint lua_textpart_compare_distance (lua_State * L) { -- 2.39.5