]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_util: Add method mime_header_encode
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 18 Dec 2018 15:51:11 +0000 (15:51 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 18 Dec 2018 15:51:11 +0000 (15:51 +0000)
src/lua/lua_util.c

index 4fa05f6dd8daa67ef7d2f7776208dd7dfd27e275..0fd4427092e9bb39847dab46895b1599cfb30b9f 100644 (file)
@@ -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)
 {