aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-18 15:51:11 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-18 15:51:11 +0000
commit9eaf83a15b4ddaef0a2b107cdf8876695d8b57d8 (patch)
tree9b529403fc6178658c80b552e01c7141fff06bac /src
parent597e2323758a22870f541817d4a3bcc05db42b05 (diff)
downloadrspamd-9eaf83a15b4ddaef0a2b107cdf8876695d8b57d8.tar.gz
rspamd-9eaf83a15b4ddaef0a2b107cdf8876695d8b57d8.zip
[Minor] Lua_util: Add method mime_header_encode
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_util.c30
1 files changed, 30 insertions, 0 deletions
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)
{