]> source.dussan.org Git - rspamd.git/commitdiff
* Improve forged_recipients plugin [1]
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 16 Feb 2011 14:00:13 +0000 (17:00 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 16 Feb 2011 14:00:13 +0000 (17:00 +0300)
Add loading of local rules to rspamd.lua [1]

[1] Suggested by Victor Ustugov

conf/lua/rspamd.lua
src/plugins/lua/forged_recipients.lua

index 2f337aa9f1655e1b0d06a08e771a43fe4e01f5ec..e85a971d30bf785722811a92b2286d9b218f3bca 100644 (file)
@@ -40,3 +40,17 @@ reconf['R_EMPTY_IMAGE'] = function (task)
        return false
 end
 
+
+local function file_exists(filename)
+       local file = io.open(filename)
+       if file then
+               io.close(file)
+               return true
+       else
+               return false
+       end
+end
+
+if file_exists('rspamd.local.lua') then
+       dofile('rspamd.local.lua')
+end
index 6b6ec298bd98a026381b83eb7a110021014e6799..d082b386d343929906329b5b64ed2ab6e043d6dd 100644 (file)
@@ -31,7 +31,15 @@ function check_forged_headers(task)
                                end
                                if mime_rcpt then
                                        for _,mr in ipairs(mime_rcpt) do
-                                               if string.find(mr, sr) then
+                                               local i = string.find(mr, '<', 1, true)
+                                               if i then
+                                                   local j = string.find(mr, '>', i, true)
+                                                   if j then
+                                                       mr = string.sub(mr, i+1, j-1)
+                                                   end
+                                               end
+
+                                               if string.lower(mr) == string.lower(sr) then
                                                        res = true
                                                        break
                                                end
@@ -39,7 +47,14 @@ function check_forged_headers(task)
                                end
                                if mime_cc then
                                        for _,mr in ipairs(mime_cc) do
-                                               if string.find(mr, sr) then
+                                               local i = string.find(mr, '<', 1, true)
+                                               if i then
+                                                   local j = string.find(mr, '>', i, true)
+                                                   if j then
+                                                       mr = string.sub(mr, i+1, j-1)
+                                                   end
+                                               end
+                                               if string.lower(mr) == string.lower(sr) then
                                                        res = true
                                                        break
                                                end
@@ -57,7 +72,14 @@ function check_forged_headers(task)
        local smtp_from = task:get_from()
        if smtp_form then
                local mime_from = msg:get_header('From')
-               if not mime_from or not string.find(mime_from[0], smtp_from) then
+               local i = string.find(mime_from[0], '<', 1, true)
+               if i then
+                   local j = string.find(mime_from[0], '>', i, true)
+                   if j then
+                       mime_from[0] = string.sub(mime_from[0], i+1, j-1)
+                   end
+               end
+               if not mime_from or not (string.lower(mime_from[0]) == string.lower(smtp_from)) then
                        task:insert_result(symbol_sender, 1)
                end
        end