diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-08 13:42:09 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-08 13:42:09 +0100 |
commit | d5efd0314056eca477e01e5fecb64c814f47d4cb (patch) | |
tree | 51599bc9c6c6fc7dadc405424e6a6939be550481 | |
parent | 58f7e9aa83e40fbfdc525760e935cde617aed28d (diff) | |
download | rspamd-d5efd0314056eca477e01e5fecb64c814f47d4cb.tar.gz rspamd-d5efd0314056eca477e01e5fecb64c814f47d4cb.zip |
Add lua bindings for headers folding.
-rw-r--r-- | src/lua/lua_util.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 8b3a13786..24c1bd676 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -113,6 +113,16 @@ LUA_FUNCTION_DEF (util, levenshtein_distance); */ LUA_FUNCTION_DEF (util, parse_addr); +/*** + * @function util.fold_header(name, value) + * Fold rfc822 header according to the folding rules + * + * @param {string} name name of the header + * @param {string} value value of the header + * @return {string} Folded value of the header + */ +LUA_FUNCTION_DEF (util, fold_header); + static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, create_event_base), LUA_INTERFACE_DEF (util, load_rspamd_config), @@ -125,6 +135,7 @@ static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, parse_html), LUA_INTERFACE_DEF (util, levenshtein_distance), LUA_INTERFACE_DEF (util, parse_addr), + LUA_INTERFACE_DEF (util, fold_header), {NULL, NULL} }; @@ -593,6 +604,30 @@ lua_util_parse_addr (lua_State *L) } static gint +lua_util_fold_header (lua_State *L) +{ + const gchar *name, *value; + GString *folded; + + name = luaL_checkstring (L, 1); + value = luaL_checkstring (L, 2); + + if (name && value) { + folded = rspamd_header_value_fold (name, value); + + if (folded) { + lua_pushlstring (L, folded->str, folded->len); + g_string_free (folded, TRUE); + + return 1; + } + } + + lua_pushnil (L); + return 1; +} + +static gint lua_load_util (lua_State * L) { lua_newtable (L); |