]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add method to get raw headers of a mime part
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 17 Dec 2018 12:33:03 +0000 (12:33 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 17 Dec 2018 12:33:03 +0000 (12:33 +0000)
src/lua/lua_mimepart.c

index 3019cf577e521caecaa5a4d53604f89f47b3c2f1..56fc0d3029d531ee31da96586bfb155f94e979a5 100644 (file)
@@ -301,6 +301,15 @@ LUA_FUNCTION_DEF (mimepart, get_header_full);
  * @return {number} number of header's occurrencies or 0 if not found
  */
 LUA_FUNCTION_DEF (mimepart, get_header_count);
+
+/***
+ * @method mimepart:get_raw_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_raw_headers);
+
+
 /***
  * @method mime_part:get_content()
  * Get the parsed content of part
@@ -479,6 +488,7 @@ static const struct luaL_reg mimepartlib_m[] = {
        LUA_INTERFACE_DEF (mimepart, get_header_raw),
        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, is_image),
        LUA_INTERFACE_DEF (mimepart, get_image),
        LUA_INTERFACE_DEF (mimepart, is_archive),
@@ -1236,7 +1246,7 @@ lua_mimepart_get_type_common (lua_State * L, struct rspamd_content_type *ct,
        }
 
        if (ct->boundary.len > 0) {
-               lua_pushstring (L, "charset");
+               lua_pushstring (L, "boundary");
                lua_pushlstring (L, ct->boundary.begin, ct->boundary.len);
                lua_settable (L, -3);
        }
@@ -1393,6 +1403,28 @@ lua_mimepart_get_header_count (lua_State * L)
        return lua_mimepart_get_header_common (L, RSPAMD_TASK_HEADER_PUSH_COUNT);
 }
 
+static gint
+lua_mimepart_get_raw_headers (lua_State *L)
+{
+       LUA_TRACE_POINT;
+       struct rspamd_mime_part *part = lua_check_mimepart (L);
+       struct rspamd_lua_text *t;
+
+       if (part) {
+               t = lua_newuserdata (L, sizeof (*t));
+               rspamd_lua_setclass (L, "rspamd{text}", -1);
+               t->start = part->raw_headers_str;
+               t->len = part->raw_headers_len;
+               t->flags = 0;
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+
+       return 1;
+}
+
 static gint
 lua_mimepart_is_image (lua_State * L)
 {