aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-10-14 21:29:31 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-10-14 21:29:31 +0100
commit57bf1e47ddbda63545fdf33a312062d7f41c812e (patch)
tree9199ec0b8afc0d1207626d8d45e6d65698e3906f
parentd325b95656c091b75e0520d71ac865eb7bb047eb (diff)
downloadrspamd-57bf1e47ddbda63545fdf33a312062d7f41c812e.tar.gz
rspamd-57bf1e47ddbda63545fdf33a312062d7f41c812e.zip
[Minor] Lua_task: Add get_headers method
-rw-r--r--lualib/lua_mime.lua12
-rw-r--r--src/lua/lua_task.c31
2 files changed, 43 insertions, 0 deletions
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
@@ -424,6 +424,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`
* Mods is a table with the following structure:
@@ -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),
@@ -3114,6 +3122,29 @@ lua_task_has_header (lua_State * L)
}
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)
{
LUA_TRACE_POINT;