Browse Source

[Minor] Lua_util: Add method mime_header_encode

tags/1.9.0
Vsevolod Stakhov 5 years ago
parent
commit
9eaf83a15b
1 changed files with 30 additions and 0 deletions
  1. 30
    0
      src/lua/lua_util.c

+ 30
- 0
src/lua/lua_util.c View 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)
{

Loading…
Cancel
Save