aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-17 14:36:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-17 14:36:22 +0000
commit4eda8b70db67079e85a5978f7f4585a0f6a61f10 (patch)
treec4dd2f5eb1da11d25f6e21a308e52c8bc83877ad /src/lua
parent8bc7d8632f0afa88da01a1c86379daf755e4c168 (diff)
downloadrspamd-4eda8b70db67079e85a5978f7f4585a0f6a61f10.tar.gz
rspamd-4eda8b70db67079e85a5978f7f4585a0f6a61f10.zip
[Minor] Lua_mimepart: Add method to get part boundary
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.h1
-rw-r--r--src/lua/lua_mimepart.c39
2 files changed, 40 insertions, 0 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 31d7f852b..4c82be640 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -7,6 +7,7 @@
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
+#include <stdbool.h>
#include "rspamd.h"
#include "ucl.h"
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 340da7aa2..c45030791 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -421,6 +421,15 @@ LUA_FUNCTION_DEF (mimepart, get_archive);
* @return {bool} true if a part is is a multipart part
*/
LUA_FUNCTION_DEF (mimepart, is_multipart);
+
+/***
+ * @method mime_part:get_boundary()
+ * Returns boundary for a part (extracted from parent multipart for normal parts and
+ * from the part itself for multipart)
+ * @return {string} boundary value or nil
+ */
+LUA_FUNCTION_DEF (mimepart, get_boundary);
+
/***
* @method mime_part:get_children()
* Returns rspamd_mimepart table of part's childer. Returns nil if mime part is not multipart
@@ -484,6 +493,7 @@ static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, get_detected_type_full),
LUA_INTERFACE_DEF (mimepart, get_cte),
LUA_INTERFACE_DEF (mimepart, get_filename),
+ LUA_INTERFACE_DEF (mimepart, get_boundary),
LUA_INTERFACE_DEF (mimepart, get_header),
LUA_INTERFACE_DEF (mimepart, get_header_raw),
LUA_INTERFACE_DEF (mimepart, get_header_full),
@@ -1354,6 +1364,35 @@ lua_mimepart_get_filename (lua_State * L)
}
static gint
+lua_mimepart_get_boundary (lua_State * L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_mime_part *part = lua_check_mimepart (L), *parent;
+
+ if (part == NULL) {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ if (IS_CT_MULTIPART (part->ct)) {
+ lua_pushlstring (L, part->specific.mp->boundary.begin,
+ part->specific.mp->boundary.len);
+ }
+ else {
+ parent = part->parent_part;
+
+ if (!parent || !IS_CT_MULTIPART (parent->ct)) {
+ lua_pushnil (L);
+ }
+ else {
+ lua_pushlstring (L, parent->specific.mp->boundary.begin,
+ parent->specific.mp->boundary.len);
+ }
+ }
+
+ return 1;
+}
+
+static gint
lua_mimepart_get_header_common (lua_State *L, enum rspamd_lua_task_header_type how)
{
struct rspamd_mime_part *part = lua_check_mimepart (L);