From d821fa1eb3db12446ce83dd78d4563b0a5c75fd8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 9 Feb 2017 16:37:34 +0000 Subject: [PATCH] [Feature] Store all received headers in lua --- src/libmime/message.h | 1 + src/libmime/mime_headers.c | 1 + src/lua/lua_task.c | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libmime/message.h b/src/libmime/message.h index 2e0bd6bd5..da816ad43 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -111,6 +111,7 @@ struct received_header { gchar *by_hostname; gchar *for_mbox; rspamd_inet_addr_t *addr; + struct rspamd_mime_header *hdr; time_t timestamp; enum rspamd_received_type type; }; diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index 35c13d1f3..bff84efcc 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -37,6 +37,7 @@ rspamd_mime_header_check_special (struct rspamd_task *task, case 0x88705DC4D9D61ABULL: /* received */ recv = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct received_header)); + recv->hdr = rh; rspamd_smtp_recieved_parse (task, rh->decoded, strlen (rh->decoded), recv); g_ptr_array_add (task->received, recv); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index c59ae33dc..d7fabd213 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1548,15 +1548,19 @@ lua_task_get_received_headers (lua_State * L) for (i = 0; i < task->received->len; i ++) { rh = g_ptr_array_index (task->received, i); + lua_createtable (L, 0, 9); + rspamd_lua_table_set (L, "raw", rh->hdr->decoded); + if (G_UNLIKELY (rh->from_ip == NULL && rh->real_ip == NULL && rh->real_hostname == NULL && rh->by_hostname == NULL && rh->timestamp == 0 && rh->for_mbox == NULL)) { + lua_rawseti (L, -2, k ++); + continue; } - lua_createtable (L, 0, 8); rspamd_lua_table_set (L, "from_hostname", rh->from_hostname); rspamd_lua_table_set (L, "from_ip", rh->from_ip); rspamd_lua_table_set (L, "real_hostname", rh->real_hostname); @@ -1592,6 +1596,7 @@ lua_task_get_received_headers (lua_State * L) proto = "unknown"; break; } + lua_pushstring (L, proto); lua_settable (L, -3); -- 2.39.5