]> source.dussan.org Git - rspamd.git/commitdiff
Fix plugins.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Aug 2014 14:56:33 +0000 (15:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Aug 2014 14:56:33 +0000 (15:56 +0100)
conf/lua/hfilter.lua
conf/lua/rspamd.classifiers.lua
src/plugins/lua/forged_recipients.lua
src/plugins/lua/multimap.lua
src/plugins/lua/ratelimit.lua

index cfa6e3d22550465f485170cd86e05c3bbe0d6ed9..18fc995c14d1aaedf853e604c8e78f1430e19bb0 100644 (file)
@@ -229,7 +229,7 @@ local function hfilter(task)
     end
 
     -- MAILFROM checks --
-    local from = task:get_from()
+    local from = task:get_from(1)
     if from then
         --FROM host check
         for _,fr in ipairs(from) do
index de1e23506740055c446af471cd0578b3d4fb698f..d73d08178c445ef270aec981a27061ac5bb11a29 100644 (file)
@@ -14,7 +14,7 @@ local function get_specific_statfiles(classifier, task)
        -- More 5 recipients
        local st_many = classifier:get_statfile_by_label(many_recipients_label)
        if st_many then
-               rcpt = task:get_recipients()
+               rcpt = task:get_recipients(2)
                if rcpt and table.maxn(rcpt) > 5 then
                        print(table.maxn(rcpt))
                        table.foreach(st_many, function(i,v) table.insert(spec_st,v) end)
@@ -23,7 +23,7 @@ local function get_specific_statfiles(classifier, task)
        -- Undisclosed
        local st_undisc = classifier:get_statfile_by_label(undisclosed_recipients_label)
        if st_undisc then
-               rcpt = task:get_recipients()
+               rcpt = task:get_recipients(2)
                if rcpt and table.maxn(rcpt) == 0 then
                        table.foreach(st_undisc, function(i,v) table.insert(spec_st,v) end)
                end
index 9ad47a2592b5cd949d784c2108f9b13b52675aea..6fc1bcd8399b6219d292157362c0f7d287645e32 100644 (file)
@@ -6,11 +6,11 @@ local symbol_sender = 'FORGED_SENDER'
 
 function check_forged_headers(task)
        local msg = task:get_message()
-       local smtp_rcpt = task:get_recipients()
+       local smtp_rcpt = task:get_recipients(1)
        local res = false
        
        if smtp_rcpt then
-               local mime_rcpt = task:get_recipients_headers()
+               local mime_rcpt = task:get_recipients(2)
                local count = 0
                if mime_rcpt then 
                        count = table.maxn(mime_rcpt)
@@ -36,9 +36,9 @@ function check_forged_headers(task)
                end
        end
        -- Check sender
-       local smtp_from = task:get_from()
+       local smtp_from = task:get_from(1)
        if smtp_from then
-               local mime_from = task:get_from_headers()
+               local mime_from = task:get_from(2)
                if not mime_from or not (string.lower(mime_from[1]['addr']) == string.lower(smtp_from[1]['addr'])) then
                        task:insert_result(symbol_sender, 1)
                end
index aac0f5159041dc2a71eafad23ed2fa8f8b45b2a5..a4adab33762e6620d078bde38f9f6a1d25442ecc 100644 (file)
@@ -108,40 +108,6 @@ local function check_multimap(task)
                                                end
                                        end     
                                end
-                       else
-                               -- Get from headers
-                               local rcpts = task:get_recipients_headers()
-                               if rcpts then
-                                       for _,r in ipairs(rcpts) do
-                                               if r['addr'] then
-                                                       if rule['pattern'] then
-                                                               -- extract a part from header
-                                                               local _,_,ext = string.find(r['addr'], rule['pattern'])
-                                                               if ext then
-                                                                       if rule['cdb'] then
-                                                                               if rule['hash']:lookup(ext) then
-                                                                                       task:insert_result(rule['symbol'], 1)
-                                                                               end
-                                                                       else
-                                                                               if rule['hash']:get_key(ext) then
-                                                                                       task:insert_result(rule['symbol'], 1)
-                                                                               end
-                                                                       end
-                                                               end
-                                                       else
-                                                               if rule['cdb'] then
-                                                                       if rule['hash']:lookup(r['addr']) then
-                                                                               task:insert_result(rule['symbol'], 1)
-                                                                       end
-                                                               else
-                                                                       if rule['hash']:get_key(r['addr']) then
-                                                                               task:insert_result(rule['symbol'], 1)
-                                                                       end
-                                                               end
-                                                       end
-                                               end     
-                                       end
-                               end
                        end
                elseif rule['type'] == 'from' then
                        -- First try to get from field
@@ -176,40 +142,6 @@ local function check_multimap(task)
                                                end
                                        end     
                                end
-                       else
-                               -- Get from headers
-                               local from = task:get_from_headers()
-                               if from then
-                                       for _,r in ipairs(from) do
-                                               if r['addr'] then
-                                                       if rule['pattern'] then
-                                                               -- extract a part from header
-                                                               local _,_,ext = string.find(r['addr'], rule['pattern'])
-                                                               if ext then
-                                                                       if rule['cdb'] then
-                                                                               if rule['hash']:lookup(ext) then
-                                                                                       task:insert_result(rule['symbol'], 1)
-                                                                               end
-                                                                       else
-                                                                               if rule['hash']:get_key(ext) then
-                                                                                       task:insert_result(rule['symbol'], 1)
-                                                                               end
-                                                                       end
-                                                               end
-                                                       else
-                                                               if rule['cdb'] then
-                                                                       if rule['hash']:lookup(r['addr']) then
-                                                                               task:insert_result(rule['symbol'], 1)
-                                                                       end
-                                                               else
-                                                                       if rule['hash']:get_key(r['addr']) then
-                                                                               task:insert_result(rule['symbol'], 1)
-                                                                       end
-                                                               end
-                                                       end
-                                               end     
-                                       end
-                               end
                        end
                end
        end
index fc838dd9a2dbbeab9806694b4469b00945ec0b6d..fff966e1d80f0440c5262b4f3d72229221b3b5e5 100644 (file)
@@ -47,6 +47,7 @@ local function check_specific_limit (task, limit, key)
        --- Called when value was set on server
        local function rate_set_key_cb(task, err, data)
                if err then
+                 rspamd_logger.info('got error while getting limit: ' .. err)
                        upstream:fail()
                else
                        upstream:ok()
@@ -74,6 +75,7 @@ local function check_specific_limit (task, limit, key)
                        end
                end
                if err then
+                 rspamd_logger.info('got error while getting limit: ' .. err)
                        upstream:fail()
                end     
        end
@@ -88,6 +90,7 @@ local function set_specific_limit (task, limit, key)
        --- Called when value was set on server
        local function rate_set_key_cb(task, err, data)
                if err then
+                 rspamd_logger.info('got error while setting limit: ' .. err)
                        upstream:fail()
                else
                        upstream:ok()
@@ -112,6 +115,7 @@ local function set_specific_limit (task, limit, key)
                        rspamd_redis.make_request(task, upstream:get_ip_string(), upstream:get_port(), rate_set_key_cb, 
                                                        'SET %b %b', key, lstr)
                elseif err then
+                 rspamd_logger.info('got error while setting limit: ' .. err)
                        upstream:fail()
                end
        end
@@ -147,17 +151,6 @@ end
 
 --- Check or update ratelimit
 local function rate_test_set(task, func)
-       
-       -- Returns local part component of address
-       local function get_local_part(str)
-               pos,_ = string.find(str, '@', 0, true)
-               if not pos then
-                       return str
-               else
-                       return string.sub(str, 1, pos - 1)
-               end
-       end
-       
        -- Get initial task data
        local ip = task:get_from_ip()
        if ip and whitelisted_ip then
@@ -169,9 +162,6 @@ local function rate_test_set(task, func)
        -- Parse all rcpts 
        local rcpts = task:get_recipients()
        local rcpts_user = {}
-       if not rcpts then
-               rcpts = task:get_recipients_headers()
-       end
        if rcpts then
                if table.maxn(rcpts) > max_rcpt then
                        rspamd_logger.info(string.format('message <%s> contains %d recipients, maximum is %d',
@@ -179,24 +169,21 @@ local function rate_test_set(task, func)
                        return
                end
                for i,r in ipairs(rcpts) do
-                       rcpts_user[i] = get_local_part(r['addr'])
+                       rcpts_user[i] = r['user']
                end
        end
        -- Parse from
        local from = task:get_from()
        local from_user = ''
-       if not from then
-               from = task:get_from_headers()
-       end
        if from then
-               from_user = get_local_part(from[1]['addr'])
+               from_user = from[1]['user']
        end
        -- Get user (authuser)
        local auser = task:get_user()
        if auser then
                func(task, settings['user'], make_rate_key (auser, '<auth>', nil))
        end
-       
+
        if not from_user or not rcpts_user[1] then
                -- Nothing to check
                return