Changed Notify.php
authorAlan <alan@roojs.com>
Fri, 18 Aug 2023 03:55:45 +0000 (11:55 +0800)
committerAlan <alan@roojs.com>
Fri, 18 Aug 2023 03:55:45 +0000 (11:55 +0800)
Notify.php

index 7bef8f8..07c0823 100644 (file)
@@ -255,7 +255,7 @@ class Pman_Core_Notify extends Pman
                 $this->queue[] = clone($w);
                 $total--;
             }
-            
+          
             $this->logecho("BATCH SIZE: Queue=".  count($this->queue) . " TOTAL = " . $total  );
             
             if (empty($this->queue)) {
@@ -275,7 +275,14 @@ class Pman_Core_Notify extends Pman
                 sleep(3);
                 continue;
             }
-            $email = $p->person() ? $p->person()->email : $p->to_email;
+            // not sure what happesn if person email and to_email is empty!!?
+            $email = empty($p->to_email) ? ($p->person() ? $p->person()->email : $p->to_email) : $p->to_email;
+            
+            $black = $this->isBlacklisted($email);
+            if ($black !== false) {
+                $this->updateServer($p, $black);
+            }
+             
             
             if ($this->poolHasDomain($email) > $this->max_to_domain) {
                 
@@ -321,17 +328,41 @@ class Pman_Core_Notify extends Pman
         exit;
     }
     
+    
+    function isBlacklisted($email)
+    {
+        // return current server id..
+        if (empty($ff->Core_Notify['servers'])) {
+            return false;
+        }
+      
+        if (!isset($ff->Core_Notify['servers'][gethostname()]['blacklisted'])) {
+            return false;
+        }
+       
+        // get the domain..
+        $ea = explode('@',$email);
+        $dom = strtolower(array_pop($ea));
+        if (!in_array($dom, $ff->Core_Notify['servers'][gethostname()]['blacklisted'] )) {
+            return false;
+        }
+        return array_search(gethostname(),array_keys($ff->Core_Notify['servers']));
+    }
+    
     // this sequentially distributes requeued emails.. - to other servers.
-    function updateServer($w)
+    function updateServer($w, $exclude = -1)
     {
         $ff = HTML_FlexyFramework::get();
         static $num = 0;
         if (empty($ff->Core_Notify['servers'])) {
             return;
         }
-        $num++;
+        $num = ($num+1) % count(array_keys($ff->Core_Notify['servers']));
+        if ($exclude == $num ) {
+            $num = ($num+1) % count(array_keys($ff->Core_Notify['servers']));
+        }
         // next server..
-        $w->server_id = $num % count(array_keys($ff->Core_Notify['servers']));
+        $w->server_id = $num;
          
     }