]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add Lua API to get filename
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Mar 2018 17:49:35 +0000 (17:49 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Mar 2018 17:49:35 +0000 (17:49 +0000)
src/lua/lua_task.c

index a98f4d97aa25fa506b26907087e8db6be27d2548..89f35e90da1a54a91953e82d325fd0c0f8dd3f6a 100644 (file)
@@ -174,6 +174,13 @@ LUA_FUNCTION_DEF (task, has_urls);
  */
 LUA_FUNCTION_DEF (task, get_content);
 
+/***
+ * @method task:get_filename()
+ * Returns filename for a specific task
+ * @return {string|nil} filename or nil if unknown
+ */
+LUA_FUNCTION_DEF (task, get_filename);
+
 /***
  * @method task:get_rawbody()
  * Get raw body for the specified task
@@ -855,6 +862,7 @@ static const struct luaL_reg tasklib_m[] = {
        LUA_INTERFACE_DEF (task, has_urls),
        LUA_INTERFACE_DEF (task, get_urls),
        LUA_INTERFACE_DEF (task, get_content),
+       LUA_INTERFACE_DEF (task, get_filename),
        LUA_INTERFACE_DEF (task, get_rawbody),
        LUA_INTERFACE_DEF (task, get_emails),
        LUA_INTERFACE_DEF (task, get_text_parts),
@@ -1534,6 +1542,26 @@ lua_task_get_content (lua_State * L)
        return 1;
 }
 
+static gint
+lua_task_get_filename (lua_State * L)
+{
+       struct rspamd_task *task = lua_check_task (L, 1);
+
+       if (task) {
+               if (task->msg.fpath) {
+                       lua_pushstring (L, task->msg.fpath);
+               }
+               else {
+                       lua_pushnil (L);
+               }
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 static gint
 lua_task_get_rawbody (lua_State * L)
 {