]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to get task's subject
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 28 Mar 2017 13:36:07 +0000 (14:36 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 28 Mar 2017 13:36:07 +0000 (14:36 +0100)
src/lua/lua_task.c

index 36272ecfe2d80ec6c94b1087e8e1e891b265c75f..46fc5da94f673f6b233e3a19d0e45127b92a54ad 100644 (file)
@@ -195,6 +195,12 @@ LUA_FUNCTION_DEF (task, get_request_header);
  * @param {rspamd_text/string} value new header's value
  */
 LUA_FUNCTION_DEF (task, set_request_header);
+/***
+ * @method task:get_subject()
+ * Returns task subject (either from the protocol override or from a header)
+ * @return {string} value of a subject (decoded)
+ */
+LUA_FUNCTION_DEF (task, get_subject);
 /***
  * @method task:get_header(name[, case_sensitive])
  * Get decoded value of a header specified with optional case_sensitive flag.
@@ -817,6 +823,7 @@ static const struct luaL_reg tasklib_m[] = {
        LUA_INTERFACE_DEF (task, set_from_ip),
        LUA_INTERFACE_DEF (task, get_from_ip_num),
        LUA_INTERFACE_DEF (task, get_client_ip),
+       LUA_INTERFACE_DEF (task, get_subject),
        LUA_INTERFACE_DEF (task, get_helo),
        LUA_INTERFACE_DEF (task, set_helo),
        LUA_INTERFACE_DEF (task, get_hostname),
@@ -2586,6 +2593,27 @@ lua_task_get_helo (lua_State *L)
        return 1;
 }
 
+static gint
+lua_task_get_subject (lua_State *L)
+{
+       struct rspamd_task *task = lua_check_task (L, 1);
+
+       if (task) {
+               if (task->subject != NULL) {
+                       lua_pushstring (L, task->subject);
+                       return 1;
+               }
+               else {
+                       lua_pushnil (L);
+               }
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 static gint
 lua_task_set_helo (lua_State *L)
 {