diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-08-01 08:12:38 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-08-01 08:12:38 +0100 |
commit | 634582d5d00ca0b15eb533fd4cde468120430ab6 (patch) | |
tree | bf5af8cefdaf743d532bbe3596f9b182948fb2dc /src/lua/lua_task.c | |
parent | 6dbe8d02d8666d701cc19fa15fa53795260bbd15 (diff) | |
download | rspamd-634582d5d00ca0b15eb533fd4cde468120430ab6.tar.gz rspamd-634582d5d00ca0b15eb533fd4cde468120430ab6.zip |
[Minor] Add task:get_principal_recipient method
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r-- | src/lua/lua_task.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 6bc6a0e29..61ef6d075 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -342,6 +342,18 @@ LUA_FUNCTION_DEF (task, has_recipients); LUA_FUNCTION_DEF (task, get_recipients); /*** + * @method task:get_principal_recipient() + * Returns a single string with so called `principal recipient` for a message. The order + * of check is the following: + * + * - deliver-to request header + * - the first recipient (envelope) + * - the first recipient (mime) + * @return {string} principal recipient + */ +LUA_FUNCTION_DEF (task, get_principal_recipient); + +/*** * @method task:set_recipients([type], {rcpt1, rcpt2...}) * Sets sender for a task. This function accepts table that will be converted to the address. * If some fields are missing they are subsequently reconstructed by this function. E.g. if you @@ -841,6 +853,7 @@ static const struct luaL_reg tasklib_m[] = { LUA_INTERFACE_DEF (task, has_recipients), LUA_INTERFACE_DEF (task, get_recipients), LUA_INTERFACE_DEF (task, set_recipients), + LUA_INTERFACE_DEF (task, get_principal_recipient), LUA_INTERFACE_DEF (task, has_from), LUA_INTERFACE_DEF (task, get_from), LUA_INTERFACE_DEF (task, set_from), @@ -2560,6 +2573,28 @@ lua_task_set_from (lua_State *L) } static gint +lua_task_get_principal_recipient (lua_State *L) +{ + struct rspamd_task *task = lua_check_task (L, 1); + const gchar *r; + + if (task) { + r = rspamd_task_get_principal_recipient (task); + if (r != NULL) { + lua_pushstring (L, r); + } + else { + lua_pushnil (L); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + +static gint lua_task_get_user (lua_State *L) { struct rspamd_task *task = lua_check_task (L, 1); |