]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Lua_selectors: Add languages selector
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Feb 2019 16:22:04 +0000 (16:22 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 22 Feb 2019 16:22:29 +0000 (16:22 +0000)
Issue: #2763

lualib/lua_selectors.lua

index 0a02edca9f9f12d425befde2776f3d0372a7f40e..b678ef17997ca2209211329bd9209307116c491b 100644 (file)
@@ -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)