commit 9eaf83a: [Minor] Lua_util: Add method mime_header_encode

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Dec 27 18:28:11 UTC 2018


Author: Vsevolod Stakhov
Date: 2018-12-18 15:51:11 +0000
URL: https://github.com/rspamd/rspamd/commit/9eaf83a15b4ddaef0a2b107cdf8876695d8b57d8

[Minor] Lua_util: Add method mime_header_encode

---
 src/lua/lua_util.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 4fa05f6dd..0fd442709 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -21,6 +21,7 @@
 #include "contrib/uthash/utlist.h"
 #include "libmime/email_addr.h"
 #include "libmime/content_type.h"
+#include "libmime/mime_headers.h"
 #include "linenoise.h"
 #include <math.h>
 #include <glob.h>
@@ -564,6 +565,14 @@ LUA_FUNCTION_DEF (util, get_hostname);
  */
 LUA_FUNCTION_DEF (util, parse_content_type);
 
+/***
+ *  @function util.mime_header_encode(hdr)
+ * Encodes header if needed
+ * @param {string} hdr input header
+ * @return encoded header
+ */
+LUA_FUNCTION_DEF (util, mime_header_encode);
+
 
 static const struct luaL_reg utillib_f[] = {
 	LUA_INTERFACE_DEF (util, create_event_base),
@@ -618,6 +627,7 @@ static const struct luaL_reg utillib_f[] = {
 	LUA_INTERFACE_DEF (util, isatty),
 	LUA_INTERFACE_DEF (util, get_hostname),
 	LUA_INTERFACE_DEF (util, parse_content_type),
+	LUA_INTERFACE_DEF (util, mime_header_encode),
 	LUA_INTERFACE_DEF (util, pack),
 	LUA_INTERFACE_DEF (util, unpack),
 	LUA_INTERFACE_DEF (util, packsize),
@@ -2598,6 +2608,26 @@ lua_util_parse_content_type (lua_State *L)
 	return 1;
 }
 
+
+static gint
+lua_util_mime_header_encode (lua_State *L)
+{
+	LUA_TRACE_POINT;
+	gsize len;
+	const gchar *hdr = luaL_checklstring (L, 1, &len);
+	gchar *encoded;
+
+	if (!hdr) {
+		return luaL_error (L, "invalid arguments");
+	}
+
+	encoded = rspamd_mime_header_encode (hdr, len);
+	lua_pushstring (L, encoded);
+	g_free (encoded);
+
+	return 1;
+}
+
 static gint
 lua_util_is_valid_utf8 (lua_State *L)
 {


More information about the Commits mailing list