commit 57bf1e4: [Minor] Lua_task: Add get_headers method

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Oct 14 20:35:06 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-10-14 21:29:31 +0100
URL: https://github.com/rspamd/rspamd/commit/57bf1e47ddbda63545fdf33a312062d7f41c812e (HEAD -> master)

[Minor] Lua_task: Add get_headers method

---
 lualib/lua_mime.lua | 12 ++++++++++++
 src/lua/lua_task.c  | 31 +++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/lualib/lua_mime.lua b/lualib/lua_mime.lua
index ad38d3c32..f84cc4d4e 100644
--- a/lualib/lua_mime.lua
+++ b/lualib/lua_mime.lua
@@ -572,4 +572,16 @@ exports.modify_headers = function(task, hdr_alterations)
   end
 end
 
+--[[[
+-- @function lua_mime.message_to_ucl(task)
+-- Exports a message to an ucl object
+--]]
+exports.message_to_ucl = function(task)
+  local result = {}
+  result.size = task:get_size()
+  result.digest = task:get_digest()
+
+  return result
+end
+
 return exports
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 42cdd22f0..29d253217 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -423,6 +423,13 @@ LUA_FUNCTION_DEF (task, get_header_count);
  */
 LUA_FUNCTION_DEF (task, get_raw_headers);
 
+/***
+ * @method task:get_headers([need_modified=false])
+ * Get all headers of a message in the same format as get_header_full
+ * @return {table of headers data} all headers for a message
+ */
+LUA_FUNCTION_DEF (task, get_headers);
+
 /***
  * @method task:modify_header(name, mods)
  * Modify an existing or non-existing header with the name `name`
@@ -1243,6 +1250,7 @@ static const struct luaL_reg tasklib_m[] = {
 	LUA_INTERFACE_DEF (task, get_header_full),
 	LUA_INTERFACE_DEF (task, get_header_count),
 	LUA_INTERFACE_DEF (task, get_raw_headers),
+	LUA_INTERFACE_DEF (task, get_headers),
 	LUA_INTERFACE_DEF (task, modify_header),
 	LUA_INTERFACE_DEF (task, get_received_headers),
 	LUA_INTERFACE_DEF (task, get_queue_id),
@@ -3113,6 +3121,29 @@ lua_task_has_header (lua_State * L)
 	return lua_task_get_header_common (L, RSPAMD_TASK_HEADER_PUSH_HAS);
 }
 
+static gint
+lua_task_get_headers (lua_State *L)
+{
+	LUA_TRACE_POINT;
+	struct rspamd_task *task = lua_check_task (L, 1);
+
+	if (task && task->message) {
+		struct rspamd_mime_header *cur;
+
+		lua_createtable (L, rspamd_mime_headers_count(MESSAGE_FIELD(task, raw_headers)), 0);
+		DL_FOREACH(MESSAGE_FIELD(task, headers_order), cur) {
+			rspamd_lua_push_header_array(L, cur->name, cur, RSPAMD_TASK_HEADER_PUSH_FULL,
+					false);
+		}
+	}
+	else {
+		return luaL_error (L, "invalid arguments");
+	}
+
+
+	return 1;
+}
+
 static gint
 lua_task_get_raw_headers (lua_State *L)
 {


More information about the Commits mailing list