From: Vsevolod Stakhov Date: Tue, 1 Aug 2017 07:12:38 +0000 (+0100) Subject: [Minor] Add task:get_principal_recipient method X-Git-Tag: 1.7.0~776 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=634582d5d00ca0b15eb533fd4cde468120430ab6;p=rspamd.git [Minor] Add task:get_principal_recipient method --- 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 @@ -341,6 +341,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. @@ -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), @@ -2559,6 +2572,28 @@ lua_task_set_from (lua_State *L) return 1; } +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) {