]> source.dussan.org Git - rspamd.git/commitdiff
Adopt SA 'exists' function.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 26 Feb 2015 17:53:19 +0000 (17:53 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 26 Feb 2015 17:53:19 +0000 (17:53 +0000)
src/plugins/lua/spamassassin.lua

index bb96fb2e8c377231aa66a6e908804ef8f0841525..f9a2e6901d73c3526c0af850f383e75355264bdb 100644 (file)
@@ -69,17 +69,36 @@ local function process_sa_conf(f)
     local slash = string.find(l, '/')
     
     words = _.totable(_.filter(function(w) return w ~= "" end, _.iter(split(l))))
-    if words[1] == "header" and slash then
+    if words[1] == "header" then
       -- header SYMBOL Header ~= /regexp/
       if valid_rule then
         insert_cur_rule()
       end
-      cur_rule['type'] = 'header'
-      cur_rule['symbol'] = words[2]
-      cur_rule['header'] = words[3]
-      cur_rule['re_expr'] = words_to_re(words, 4)
-      cur_rule['re'] = rspamd_regexp.create_cached(cur_rule['re_expr'])
-      if cur_rule['re'] then valid_rule = true end
+      if slash then
+        cur_rule['type'] = 'header'
+        cur_rule['symbol'] = words[2]
+        cur_rule['header'] = words[3]
+        cur_rule['re_expr'] = words_to_re(words, 4)
+        cur_rule['re'] = rspamd_regexp.create_cached(cur_rule['re_expr'])
+        if cur_rule['re'] then valid_rule = true end
+      else
+        -- Maybe we know the function and can convert it
+        local s,e = string.find(words[3], 'exists:')
+        if e then
+           local h = _.foldl(function(acc, s) return acc .. s end,
+            '', _.drop_n(e, words[3]))
+           cur_rule['type'] = 'function'
+           cur_rule['symbol'] = words[2]
+           cur_rule['header'] = h
+           cur_rule['function'] = function(task)
+            if task:get_header(h) then
+              return true
+            end
+            return false
+           end
+           valid_rule = true
+        end
+      end
     elseif words[1] == "body" and slash then
       -- body SYMBOL /regexp/
       if valid_rule then
@@ -175,6 +194,24 @@ _.each(function(k, r)
       return r['type'] == 'header' and r['header']
     end,
     rules))
+    
+-- Custom function rules
+-- Header rules
+_.each(function(k, r)
+    local f = function(task)
+      if r['function'](task) then
+        task:insert_result(k, 1.0)
+      end
+    end
+    rspamd_config:register_symbol(k, calculate_score(k), f)
+    if r['score'] then
+      rspamd_config:set_metric_symbol(k, r['score'], r['description'])
+    end
+  end,
+  _.filter(function(k, r)
+      return r['type'] == 'function' and r['function']
+    end,
+    rules))
 
 -- Parts rules
 _.each(function(k, r)