From 634582d5d00ca0b15eb533fd4cde468120430ab6 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 1 Aug 2017 08:12:38 +0100 Subject: [PATCH] [Minor] Add task:get_principal_recipient method --- src/lua/lua_task.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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) { -- 2.39.5