]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] SpamAssassin: Import fun.lua into main namespace
authorAndrew Lewis <nerf@judo.za.org>
Tue, 19 Jul 2016 11:32:38 +0000 (12:32 +0100)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 19 Jul 2016 11:32:38 +0000 (12:32 +0100)
src/plugins/lua/spamassassin.lua

index 07868b7891b2e4c675564de90a28d03f12b9e523..3cf345b2b8763c5439a2f7951ddefb534fb59192 100644 (file)
@@ -23,7 +23,7 @@ local rspamd_expression = require "rspamd_expression"
 local rspamd_mempool = require "rspamd_mempool"
 local rspamd_trie = require "rspamd_trie"
 local util = require "rspamd_util"
-local _ = require "fun"
+require "fun" ()
 
 --local dumper = require 'pl.pretty'.dump
 
@@ -189,7 +189,7 @@ local function handle_header_def(hline, cur_rule)
         ordinary = false
       end
 
-      _.each(function(func)
+      each(function(func)
           if func == 'addr' then
             cur_param['function'] = function(str)
               local addr_parsed = util.parse_addr(str)
@@ -226,7 +226,7 @@ local function handle_header_def(hline, cur_rule)
             rspamd_logger.warnx(rspamd_config, 'Function %1 is not supported in %2',
               func, cur_rule['symbol'])
           end
-        end, _.tail(args))
+        end, tail(args))
 
         local function split_hdr_param(param, headers)
           for i,h in ipairs(headers) do
@@ -553,11 +553,11 @@ local function maybe_parse_sa_function(line)
 end
 
 local function words_to_re(words, start)
-  return table.concat(_.totable(_.drop_n(start, words)), " ");
+  return table.concat(totable(drop_n(start, words)), " ");
 end
 
 local function process_tflags(rule, flags)
-  _.each(function(flag)
+  each(function(flag)
     if flag == 'publish' then
       rule['publish'] = true
     elseif flag == 'multiple' then
@@ -567,7 +567,7 @@ local function process_tflags(rule, flags)
     elseif flag == 'nice' then
       rule['nice'] = true
     end
-  end, _.drop_n(1, flags))
+  end, drop_n(1, flags))
 
   if rule['re'] then
     if rule['maxhits'] then
@@ -654,7 +654,7 @@ local function process_sa_conf(f)
       if string.match(l, '^ifplugin') then
         local ls = split(l)
 
-        if not _.any(function(pl)
+        if not any(function(pl)
             if pl == ls[2] then return true end
             return false
             end, known_plugins) then
@@ -663,7 +663,7 @@ local function process_sa_conf(f)
         end
       elseif string.match(l, '^if !plugin%(') then
          local pname = string.match(l, '^if !plugin%(([A-Za-z:]+)%)')
-         if _.any(function(pl)
+         if any(function(pl)
            if pl == pname then return true end
            return false
          end, known_plugins) then
@@ -680,11 +680,11 @@ local function process_sa_conf(f)
     local slash = string.find(l, '/')
 
     -- Skip comments
-    words = _.totable(_.take_while(
+    words = totable(take_while(
       function(w) return string.sub(w, 1, 1) ~= '#' end,
-      _.filter(function(w)
+      filter(function(w)
           return w ~= "" end,
-      _.iter(split(l)))))
+      iter(split(l)))))
 
     if words[1] == "header" or words[1] == 'mimeheader' then
       -- header SYMBOL Header ~= /regexp/
@@ -939,9 +939,9 @@ local function process_sa_conf(f)
     elseif words[1] == "score" then
       scores[words[2]] = parse_score(words)
     elseif words[1] == 'freemail_domains' then
-      _.each(function(dom)
+      each(function(dom)
           table.insert(freemail_domains, '@' .. dom)
-        end, _.drop_n(1, words))
+        end, drop_n(1, words))
     elseif words[1] == 'blacklist_from' then
       sa_lists['from_blacklist'][words[2]] = 1
       sa_lists['elts'] = sa_lists['elts'] + 1
@@ -965,8 +965,8 @@ local function process_sa_conf(f)
     elseif words[1] == 'replace_post' then
       process_replace(words, replace['post'])
     elseif words[1] == 'replace_rules' then
-      _.each(function(r) table.insert(replace['rules'], r) end,
-        _.drop_n(1, words))
+      each(function(r) table.insert(replace['rules'], r) end,
+        drop_n(1, words))
     end
     end)()
   end
@@ -978,7 +978,7 @@ end
 -- Now check all valid rules and add the according rspamd rules
 
 local function calculate_score(sym, rule)
-  if _.all(function(c) return c == '_' end, _.take_n(2, _.iter(sym))) then
+  if all(function(c) return c == '_' end, take_n(2, iter(sym))) then
     return 0.0
   end
 
@@ -1025,7 +1025,7 @@ local function apply_replacements(str)
   local function check_specific_tag(prefix, s, tbl)
     local replacement = nil
     local ret = s
-    _.each(function(n, t)
+    each(function(n, t)
       local ns,matches = string.gsub(s, string.format("<%s%s>", prefix, n), "")
       if matches > 0 then
         replacement = t
@@ -1058,7 +1058,7 @@ local function apply_replacements(str)
   local function replace_all_tags(s)
     local str, matches
     str = s
-    _.each(function(n, t)
+    each(function(n, t)
         str,matches = string.gsub(str, string.format("<%s>", n),
           string.format("%s%s%s", pre, t, post))
     end, replace['tags'])
@@ -1077,12 +1077,12 @@ local function apply_replacements(str)
 end
 
 local function parse_atom(str)
-  local atom = table.concat(_.totable(_.take_while(function(c)
+  local atom = table.concat(totable(take_while(function(c)
     if string.find(', \t()><+!|&\n', c) then
       return false
     end
     return true
-  end, _.iter(str))), '')
+  end, iter(str))), '')
 
   return atom
 end
@@ -1130,7 +1130,7 @@ local function post_process()
   local ntags = {}
   local function rec_replace_tags(tag, tagv)
     if ntags[tag] then return ntags[tag] end
-    _.each(function(n, t)
+    each(function(n, t)
       if n ~= tag then
         local s, matches = string.gsub(tagv, string.format("<%s>", n), t)
         if matches > 0 then
@@ -1143,14 +1143,14 @@ local function post_process()
     return ntags[tag]
   end
 
-  _.each(function(n, t)
+  each(function(n, t)
     rec_replace_tags(n, t)
   end, replace['tags'])
-  _.each(function(n, t)
+  each(function(n, t)
     replace['tags'][n] = t
   end, ntags)
 
-  _.each(function(r)
+  each(function(r)
     local rule = rules[r]
 
     if rule['re_expr'] and rule['re'] then
@@ -1176,14 +1176,14 @@ local function post_process()
     end
   end, replace['rules'])
 
-  _.each(function(key, score)
+  each(function(key, score)
     if rules[key] then
       rules[key]['score'] = score
     end
   end, scores)
 
   -- Header rules
-  _.each(function(k, r)
+  each(function(k, r)
     local f = function(task)
 
       local raw = false
@@ -1217,7 +1217,7 @@ local function post_process()
       end
 
       -- Slow path
-      _.each(function(h)
+      each(function(h)
         local headers = {}
         local hname = h['header']
 
@@ -1293,13 +1293,13 @@ local function post_process()
     --rspamd_config:register_symbol(k, calculate_score(k), f)
     atoms[k] = f
   end,
-  _.filter(function(k, r)
+  filter(function(k, r)
       return r['type'] == 'header' and r['header']
   end,
   rules))
 
   -- Custom function rules
-  _.each(function(k, r)
+  each(function(k, r)
     local f = function(task)
       local res = r['function'](task)
       if res and res > 0 then
@@ -1316,13 +1316,13 @@ local function post_process()
     --rspamd_config:register_symbol(k, calculate_score(k), f)
     atoms[k] = f
   end,
-    _.filter(function(k, r)
+    filter(function(k, r)
       return r['type'] == 'function' and r['function']
     end,
       rules))
 
   -- Parts rules
-  _.each(function(k, r)
+  each(function(k, r)
     local f = function(task)
       if not r['re'] then
         rspamd_logger.errx(task, 're is missing for rule %s', k)
@@ -1343,12 +1343,12 @@ local function post_process()
     --rspamd_config:register_symbol(k, calculate_score(k), f)
     atoms[k] = f
   end,
-  _.filter(function(k, r)
+  filter(function(k, r)
       return r['type'] == 'part'
   end, rules))
 
   -- SA body rules
-  _.each(function(k, r)
+  each(function(k, r)
     local f = function(task)
       if not r['re'] then
         rspamd_logger.errx(task, 're is missing for rule %s', k)
@@ -1369,12 +1369,12 @@ local function post_process()
     --rspamd_config:register_symbol(k, calculate_score(k), f)
     atoms[k] = f
   end,
-  _.filter(function(k, r)
+  filter(function(k, r)
       return r['type'] == 'sabody' or r['type'] == 'message' or r['type'] == 'sarawbody'
   end, rules))
 
   -- URL rules
-  _.each(function(k, r)
+  each(function(k, r)
     local f = function(task)
       if not r['re'] then
         rspamd_logger.errx(task, 're is missing for rule %s', k)
@@ -1392,12 +1392,12 @@ local function post_process()
     --rspamd_config:register_symbol(k, calculate_score(k), f)
     atoms[k] = f
   end,
-    _.filter(function(k, r)
+    filter(function(k, r)
       return r['type'] == 'uri'
     end,
       rules))
   -- Meta rules
-  _.each(function(k, r)
+  each(function(k, r)
       local expression = nil
       -- Meta function callback
       local meta_cb = function(task)
@@ -1443,13 +1443,13 @@ local function post_process()
         end
       end
     end,
-    _.filter(function(k, r)
+    filter(function(k, r)
         return r['type'] == 'meta'
       end,
       rules))
 
   -- Check meta rules for foreign symbols and register dependencies
-  _.each(function(k, r)
+  each(function(k, r)
       if r['expression'] then
         local expr_atoms = r['expression']:atoms()
 
@@ -1481,13 +1481,13 @@ local function post_process()
         end
       end
     end,
-    _.filter(function(k, r)
+    filter(function(k, r)
       return r['type'] == 'meta'
     end,
     rules))
 
   -- Set missing symbols
-  _.each(function(key, score)
+  each(function(key, score)
     if not scores_added[key] then
       rspamd_config:set_metric_symbol({
             name = key, score = score,