commit 43c67de: [Minor] Lua_selectors: Add languages selector

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Feb 22 16:28:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-22 16:22:04 +0000
URL: https://github.com/rspamd/rspamd/commit/43c67de7e23f2018a6cc51a9d187aec9ad928387 (HEAD -> master)

[Minor] Lua_selectors: Add languages selector
Issue: #2763

---
 lualib/lua_selectors.lua | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua
index 0a02edca9..b678ef179 100644
--- a/lualib/lua_selectors.lua
+++ b/lualib/lua_selectors.lua
@@ -199,6 +199,27 @@ the second optional argument is optional hash type (`blake2`, `sha256`, `sha1`,
     end,
     ['description'] = 'Get all attachments files',
   },
+  -- Get languages for text parts
+  ['languages'] = {
+    ['get_value'] = function(task)
+      local text_parts = task:get_text_parts() or E
+      local languages = {}
+
+      for _,p in ipairs(text_parts) do
+        local lang = p:get_language()
+        if lang then
+          table.insert(languages, lang)
+        end
+      end
+
+      if #languages > 0 then
+        return languages,'string_list'
+      end
+
+      return nil
+    end,
+    ['description'] = 'Get languages for text parts',
+  },
   -- Get helo value
   ['helo'] = {
     ['get_value'] = function(task)


More information about the Commits mailing list