commit 3e85c63: [Rework] get rid of util:parse_addr duplicating the util:parse_mail_address, replace where used
Jan Smutny
js at excello.cz
Fri Apr 17 15:35:10 UTC 2020
Author: Jan Smutny
Date: 2020-04-17 13:50:50 +0200
URL: https://github.com/rspamd/rspamd/commit/3e85c63f09661ab1df51a17ffffffbc4ffa6e2d1
[Rework] get rid of util:parse_addr duplicating the util:parse_mail_address, replace where used
---
src/lua/lua_util.c | 69 ----------------------------------------
src/plugins/lua/spamassassin.lua | 4 +--
utils/sa_trivial_convert.lua | 4 +--
3 files changed, 4 insertions(+), 73 deletions(-)
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index f33a46d0d..d2efc9cb2 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -152,29 +152,6 @@ LUA_FUNCTION_DEF (util, parse_html);
*/
LUA_FUNCTION_DEF (util, levenshtein_distance);
-/***
- * @function util.parse_addr(str, [pool])
- * Parse rfc822 address to components. Returns a table of components:
- *
- * - `name`: name of address (e.g. Some User)
- * - `addr`: address part (e.g. user at example.com)
- * - `user` - user part (if present) of the address, e.g. `blah`
- * - `domain` - domain part (if present), e.g. `foo.com`
- * - `flags` - table with following keys set to true if given condition fulfilled:
- * - [valid] - valid SMTP address in conformity with https://tools.ietf.org/html/rfc5321#section-4.1.
- * - [ip] - domain is IPv4/IPv6 address
- * - [braced] - angled `<blah at foo.com>` address
- * - [quoted] - quoted user part
- * - [empty] - empty address
- * - [backslash] - user part contains backslash
- * - [8bit] - contains 8bit characters
- **
- * @param {string} str input string
- * @param {rspamd_mempool} pool memory pool to use
- * @return {table/tables} parsed list of mail addresses
- */
-LUA_FUNCTION_DEF (util, parse_addr);
-
/***
* @function util.fold_header(name, value, [how, [stop_chars]])
* Fold rfc822 header according to the folding rules
@@ -669,7 +646,6 @@ static const struct luaL_reg utillib_f[] = {
LUA_INTERFACE_DEF (util, tanh),
LUA_INTERFACE_DEF (util, parse_html),
LUA_INTERFACE_DEF (util, levenshtein_distance),
- LUA_INTERFACE_DEF (util, parse_addr),
LUA_INTERFACE_DEF (util, fold_header),
LUA_INTERFACE_DEF (util, is_uppercase),
LUA_INTERFACE_DEF (util, humanize_number),
@@ -1487,51 +1463,6 @@ lua_util_levenshtein_distance (lua_State *L)
return 1;
}
-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)
{
diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua
index 2ba0b6228..798578856 100644
--- a/src/plugins/lua/spamassassin.lua
+++ b/src/plugins/lua/spamassassin.lua
@@ -232,7 +232,7 @@ local function handle_header_def(hline, cur_rule)
fun.each(function(func)
if func == 'addr' then
cur_param['function'] = function(str)
- local addr_parsed = util.parse_addr(str)
+ local addr_parsed = util.parse_mail_address(str)
local ret = {}
if addr_parsed then
for _,elt in ipairs(addr_parsed) do
@@ -246,7 +246,7 @@ local function handle_header_def(hline, cur_rule)
end
elseif func == 'name' then
cur_param['function'] = function(str)
- local addr_parsed = util.parse_addr(str)
+ local addr_parsed = util.parse_mail_address(str)
local ret = {}
if addr_parsed then
for _,elt in ipairs(addr_parsed) do
diff --git a/utils/sa_trivial_convert.lua b/utils/sa_trivial_convert.lua
index 4725dabd5..56a01adfa 100644
--- a/utils/sa_trivial_convert.lua
+++ b/utils/sa_trivial_convert.lua
@@ -52,7 +52,7 @@ local function handle_header_def(hline, cur_rule)
fun.each(function(func)
if func == 'addr' then
cur_param['function'] = function(str)
- local addr_parsed = util.parse_addr(str)
+ local addr_parsed = util.parse_mail_address(str)
local ret = {}
if addr_parsed then
for _,elt in ipairs(addr_parsed) do
@@ -66,7 +66,7 @@ local function handle_header_def(hline, cur_rule)
end
elseif func == 'name' then
cur_param['function'] = function(str)
- local addr_parsed = util.parse_addr(str)
+ local addr_parsed = util.parse_mail_address(str)
local ret = {}
if addr_parsed then
for _,elt in ipairs(addr_parsed) do
More information about the Commits
mailing list