From e3079ec0183ba274ef58822f548e020249be23fa Mon Sep 17 00:00:00 2001
From: Vsevolod Stakhov <vsevolod@highsecure.ru>
Date: Fri, 1 Jun 2018 12:18:58 +0100
Subject: [Minor] Add mimepart:get_raw_content method

---
 src/lua/lua_mimepart.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 9c1d826d7..080bf4662 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -264,10 +264,16 @@ end
 LUA_FUNCTION_DEF (mimepart, get_header_full);
 /***
  * @method mime_part:get_content()
- * Get the raw content of part
+ * Get the parsed content of part
  * @return {text} opaque text object (zero-copy if not casted to lua string)
  */
 LUA_FUNCTION_DEF (mimepart, get_content);
+/***
+ * @method mime_part:get_raw_content()
+ * Get the raw content of part
+ * @return {text} opaque text object (zero-copy if not casted to lua string)
+ */
+LUA_FUNCTION_DEF (mimepart, get_raw_content);
 /***
  * @method mime_part:get_length()
  * Get length of the content of the part
@@ -395,6 +401,7 @@ LUA_FUNCTION_DEF (mimepart, headers_foreach);
 
 static const struct luaL_reg mimepartlib_m[] = {
 	LUA_INTERFACE_DEF (mimepart, get_content),
+	LUA_INTERFACE_DEF (mimepart, get_raw_content),
 	LUA_INTERFACE_DEF (mimepart, get_length),
 	LUA_INTERFACE_DEF (mimepart, get_type),
 	LUA_INTERFACE_DEF (mimepart, get_type_full),
@@ -917,6 +924,26 @@ lua_mimepart_get_content (lua_State * L)
 	return 1;
 }
 
+static gint
+lua_mimepart_get_raw_content (lua_State * L)
+{
+	struct rspamd_mime_part *part = lua_check_mimepart (L);
+	struct rspamd_lua_text *t;
+
+	if (part == NULL) {
+		lua_pushnil (L);
+		return 1;
+	}
+
+	t = lua_newuserdata (L, sizeof (*t));
+	rspamd_lua_setclass (L, "rspamd{text}", -1);
+	t->start = part->raw_data.begin;
+	t->len = part->raw_data.len;
+	t->flags = 0;
+
+	return 1;
+}
+
 static gint
 lua_mimepart_get_length (lua_State * L)
 {
-- 
cgit v1.2.3