aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-10-15 10:12:34 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-10-15 10:12:34 +0100
commitecc5f7d5dba938efd4ae09278e942135f40c9aa6 (patch)
tree8f83a81126c7bce8528ca1d5dfceed765ae2aec7
parent57bf1e47ddbda63545fdf33a312062d7f41c812e (diff)
downloadrspamd-ecc5f7d5dba938efd4ae09278e942135f40c9aa6.tar.gz
rspamd-ecc5f7d5dba938efd4ae09278e942135f40c9aa6.zip
[Minor] Add method to get headers from mime parts
-rw-r--r--src/lua/lua_mimepart.c32
-rw-r--r--src/lua/lua_task.c5
2 files changed, 35 insertions, 2 deletions
diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c
index 2018819e8..5c0c80c2d 100644
--- a/src/lua/lua_mimepart.c
+++ b/src/lua/lua_mimepart.c
@@ -329,6 +329,12 @@ LUA_FUNCTION_DEF (mimepart, get_header_count);
*/
LUA_FUNCTION_DEF (mimepart, get_raw_headers);
+/***
+ * @method mimepart:get_headers()
+ * Get all undecoded headers of a mime part as a string
+ * @return {rspamd_text} all raw headers for a message as opaque text
+ */
+LUA_FUNCTION_DEF (mimepart, get_headers);
/***
* @method mime_part:get_content()
@@ -568,6 +574,7 @@ static const struct luaL_reg mimepartlib_m[] = {
LUA_INTERFACE_DEF (mimepart, get_header_full),
LUA_INTERFACE_DEF (mimepart, get_header_count),
LUA_INTERFACE_DEF (mimepart, get_raw_headers),
+ LUA_INTERFACE_DEF (mimepart, get_headers),
LUA_INTERFACE_DEF (mimepart, is_image),
LUA_INTERFACE_DEF (mimepart, get_image),
LUA_INTERFACE_DEF (mimepart, is_archive),
@@ -1710,6 +1717,31 @@ lua_mimepart_get_raw_headers (lua_State *L)
}
static gint
+lua_mimepart_get_headers (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_mime_part *part = lua_check_mimepart (L);
+ bool need_modified = lua_isnoneornil(L, 2) ? false : lua_toboolean(L, 2);
+
+ if (part) {
+ struct rspamd_mime_header *cur;
+
+ lua_createtable (L, rspamd_mime_headers_count(part->raw_headers), 0);
+ LL_FOREACH2(part->headers_order, cur, ord_next) {
+ rspamd_lua_push_header_array(L, cur->name, cur, RSPAMD_TASK_HEADER_PUSH_FULL,
+ need_modified);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+
+ return 1;
+}
+
+
+static gint
lua_mimepart_is_image (lua_State * L)
{
LUA_TRACE_POINT;
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 29d253217..7f9eb0343 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -3126,14 +3126,15 @@ lua_task_get_headers (lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_task *task = lua_check_task (L, 1);
+ bool need_modified = lua_isnoneornil(L, 2) ? false : lua_toboolean(L, 2);
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) {
+ LL_FOREACH2(MESSAGE_FIELD(task, headers_order), cur, ord_next) {
rspamd_lua_push_header_array(L, cur->name, cur, RSPAMD_TASK_HEADER_PUSH_FULL,
- false);
+ need_modified);
}
}
else {