aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-18 17:23:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-18 17:23:22 +0000
commita8eb1a9f1fd59741f4b4a8c1c79155161f574857 (patch)
tree63b934fe2e61f8d1e67278f9fa89fcad76c686a9 /src/lua
parent6292e6da71860030d5336c0f751c335bfa5c14a7 (diff)
downloadrspamd-a8eb1a9f1fd59741f4b4a8c1c79155161f574857.tar.gz
rspamd-a8eb1a9f1fd59741f4b4a8c1c79155161f574857.zip
[Minor] Add task:get_reply_sender method
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_task.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 8e1a851b4..c762eb173 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -424,6 +424,16 @@ LUA_FUNCTION_DEF (task, get_recipients);
* @return {string} principal recipient
*/
LUA_FUNCTION_DEF (task, get_principal_recipient);
+/***
+ * @method task:get_reply_sender()
+ * Returns a single string with address that should be used to reply on a message
+ *
+ * - reply-to header
+ * - from header
+ * - smtp from as a last resort
+ * @return {address} email address
+ */
+LUA_FUNCTION_DEF (task, get_sender);
/***
* @method task:set_recipients([type], {rcpt1, rcpt2...})
@@ -1039,6 +1049,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_recipients),
LUA_INTERFACE_DEF (task, set_recipients),
LUA_INTERFACE_DEF (task, get_principal_recipient),
+ LUA_INTERFACE_DEF (task, get_reply_sender),
LUA_INTERFACE_DEF (task, has_from),
LUA_INTERFACE_DEF (task, get_from),
LUA_INTERFACE_DEF (task, set_from),
@@ -3275,6 +3286,44 @@ lua_task_get_principal_recipient (lua_State *L)
}
static gint
+lua_task_get_reply_sender (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_task *task = lua_check_task (L, 1);
+ struct rspamd_mime_header *rh;
+
+ if (task) {
+ GPtrArray *ar;
+
+ ar = rspamd_message_get_header_array (task, "Reply-To", false);
+
+ if (ar && ar->len == 1) {
+ rh = (struct rspamd_mime_header *)g_ptr_array_index (ar, 0);
+ lua_pushstring (L, rh->decoded);
+ }
+ else if (task->from_mime && task->from_mime->len == 1) {
+ struct rspamd_email_address *addr;
+
+ addr = (struct rspamd_email_address *)g_ptr_array_index (task->from_mime, 0);
+
+ lua_pushlstring (L, addr->addr, addr->addr_len);
+ }
+ else if (task->from_envelope) {
+ lua_pushlstring (L, task->from_envelope->addr,
+ task->from_envelope->addr_len);
+ }
+ else {
+ lua_pushnil (L);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
lua_task_get_user (lua_State *L)
{
LUA_TRACE_POINT;