aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mimepart.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-15 17:58:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-15 17:58:07 +0100
commit1534fdca8c1d35ede2ce89c3604f344b8f74e5f5 (patch)
treeb63ed19fcd64a369f3e7d77b1d2026d75f874a03 /src/lua/lua_mimepart.c
parent96df62e1b8e6f72fbecb38f9354691a490aa5f90 (diff)
downloadrspamd-1534fdca8c1d35ede2ce89c3604f344b8f74e5f5.tar.gz
rspamd-1534fdca8c1d35ede2ce89c3604f344b8f74e5f5.zip
[Feature] Allow to get digest of a mime part from lua
Diffstat (limited to 'src/lua/lua_mimepart.c')
-rw-r--r--src/lua/lua_mimepart.c26
1 files changed, 26 insertions, 0 deletions
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)
{