From: Vsevolod Stakhov Date: Mon, 15 Aug 2016 16:58:07 +0000 (+0100) Subject: [Feature] Allow to get digest of a mime part from lua X-Git-Tag: 1.3.4~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1534fdca8c1d35ede2ce89c3604f344b8f74e5f5;p=rspamd.git [Feature] Allow to get digest of a mime part from lua --- diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 6cf0b8f23..b8f7d8f85 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -282,6 +282,13 @@ LUA_FUNCTION_DEF (mimepart, is_text); */ LUA_FUNCTION_DEF (mimepart, get_text); +/*** + * @method mime_part:get_digest() + * Returns the unique digest for this mime part + * @return {string} 128 characters hex string with digest of the part + */ +LUA_FUNCTION_DEF (mimepart, get_digest); + static const struct luaL_reg mimepartlib_m[] = { LUA_INTERFACE_DEF (mimepart, get_content), LUA_INTERFACE_DEF (mimepart, get_length), @@ -296,6 +303,7 @@ static const struct luaL_reg mimepartlib_m[] = { LUA_INTERFACE_DEF (mimepart, get_archive), LUA_INTERFACE_DEF (mimepart, is_text), LUA_INTERFACE_DEF (mimepart, get_text), + LUA_INTERFACE_DEF (mimepart, get_digest), {"__tostring", rspamd_lua_class_tostring}, {NULL, NULL} }; @@ -802,6 +810,24 @@ lua_mimepart_get_text (lua_State * L) return 1; } +static gint +lua_mimepart_get_digest (lua_State * L) +{ + struct rspamd_mime_part *part = lua_check_mimepart (L); + gchar digestbuf[rspamd_cryptobox_HASHBYTES * 2 + 1]; + + if (part == NULL) { + return luaL_error (L, "invalid arguments"); + } + + memset (digestbuf, 0, sizeof (digestbuf)); + rspamd_encode_hex_buf (part->digest, sizeof (part->digest), + digestbuf, sizeof (digestbuf)); + lua_pushstring (L, digestbuf); + + return 1; +} + void luaopen_textpart (lua_State * L) {