aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_mimepart.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-05 17:58:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-05 17:58:27 +0000
commit145ffe5a0671ff5ac28a2ecced78548f7f1cb0ac (patch)
tree7f94b740dfeb6ea8f4e93bd9d822173cc22c0660 /src/lua/lua_mimepart.c
parentdb804038ea664d0acff9c58bbb767754e115d036 (diff)
downloadrspamd-145ffe5a0671ff5ac28a2ecced78548f7f1cb0ac.tar.gz
rspamd-145ffe5a0671ff5ac28a2ecced78548f7f1cb0ac.zip
[Minor] Add ID to mime parts
Diffstat (limited to 'src/lua/lua_mimepart.c')
-rw-r--r--src/lua/lua_mimepart.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 78c3e05b9..33d1a3011 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -402,6 +402,13 @@ LUA_FUNCTION_DEF (mimepart, get_text);
* @return {string} 128 characters hex string with digest of the part
*/
LUA_FUNCTION_DEF (mimepart, get_digest);
+
+/***
+ * @method mime_part:get_id()
+ * Returns the order of the part in parts list
+ * @return {number} index of the part (starting from 1 as it is Lua API)
+ */
+LUA_FUNCTION_DEF (mimepart, get_id);
/***
* @method mime_part:is_broken()
* Returns true if mime part has incorrectly specified content type
@@ -444,6 +451,7 @@ static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, is_broken),
LUA_INTERFACE_DEF (mimepart, get_text),
LUA_INTERFACE_DEF (mimepart, get_digest),
+ LUA_INTERFACE_DEF (mimepart, get_id),
LUA_INTERFACE_DEF (mimepart, headers_foreach),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
@@ -1472,6 +1480,21 @@ lua_mimepart_get_digest (lua_State * L)
}
static gint
+lua_mimepart_get_id (lua_State * L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
+
+ if (part == NULL) {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ lua_pushnumber (L, part->id);
+
+ return 1;
+}
+
+static gint
lua_mimepart_headers_foreach (lua_State *L)
{
LUA_TRACE_POINT;