diff options
author | Jan Smutny <js@excello.cz> | 2020-04-17 15:28:37 +0200 |
---|---|---|
committer | Jan Smutny <js@excello.cz> | 2020-04-17 15:34:37 +0200 |
commit | d04d3d983dfce9a1e00cdbceaa3b4439432c4a98 (patch) | |
tree | 54c225bce4451a6cf8077c39cf92f9ba91162c04 /src | |
parent | 3e85c63f09661ab1df51a17ffffffbc4ffa6e2d1 (diff) | |
download | rspamd-d04d3d983dfce9a1e00cdbceaa3b4439432c4a98.tar.gz rspamd-d04d3d983dfce9a1e00cdbceaa3b4439432c4a98.zip |
[Rework] add alias util:parse_addr for util:parse_mail_address
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_util.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index d2efc9cb2..e7f18db2b 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -651,6 +651,7 @@ static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, humanize_number), LUA_INTERFACE_DEF (util, get_tld), LUA_INTERFACE_DEF (util, glob), + {"parse_addr", lua_util_parse_mail_address}, LUA_INTERFACE_DEF (util, parse_mail_address), LUA_INTERFACE_DEF (util, strlen_utf8), LUA_INTERFACE_DEF (util, lower_utf8), @@ -1464,6 +1465,51 @@ lua_util_levenshtein_distance (lua_State *L) } static gint +lua_util_parse_addr (lua_State *L) +{ + LUA_TRACE_POINT; + GPtrArray *addrs; + gsize len; + const gchar *str = luaL_checklstring (L, 1, &len); + rspamd_mempool_t *pool; + gboolean own_pool = FALSE; + + if (str) { + + if (lua_type (L, 2) == LUA_TUSERDATA) { + pool = rspamd_lua_check_mempool (L, 2); + + if (pool == NULL) { + return luaL_error (L, "invalid arguments"); + } + } + else { + pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), + "lua util", 0); + own_pool = TRUE; + } + + addrs = rspamd_email_address_from_mime (pool, str, len, NULL); + + if (addrs == NULL) { + lua_pushnil (L); + } + else { + lua_push_emails_address_list (L, addrs, 0); + } + + if (own_pool) { + rspamd_mempool_delete (pool); + } + } + else { + lua_pushnil (L); + } + + return 1; +} + +static gint lua_util_fold_header (lua_State *L) { LUA_TRACE_POINT; |