]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_task: Add get_headers method
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 14 Oct 2021 20:29:31 +0000 (21:29 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 14 Oct 2021 20:29:31 +0000 (21:29 +0100)
lualib/lua_mime.lua
src/lua/lua_task.c

index ad38d3c32f91087ef732ef26701e8ad3e1dd60b9..f84cc4d4e076e21b3ed157022fa0510cc66ee89f 100644 (file)
@@ -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
index 42cdd22f0be38bbc55c43f7c4cbc8a02d1df8181..29d253217a5612cd34a0571cb99025e8f9005920 100644 (file)
@@ -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)
 {