NotifySend.php
[Pman.Core] / NotifySend.php
index 6adb538..b709424 100644 (file)
@@ -356,6 +356,15 @@ class Pman_Core_NotifySend extends Pman
         $fail = false;
         require_once 'Mail.php';
         
+        $core_domain = DB_DataObject::factory($core_domain);
+        if(!$core_domain->get('domain', $dom)){
+            $core_domain = DB_DataObject::factory($core_domain);
+            $core_domain->setFrom(array(
+                'domain' => $dom
+            ));
+            $core_domain->insert();
+        }
+                        
         foreach($mxs as $mx) {
             
             if (!isset($ff->Mail['helo'])) {
@@ -377,24 +386,41 @@ class Pman_Core_NotifySend extends Pman
             // this normally will happen if you sent  Pman_Core_NotifySend['host']
             if (isset($ff->Mail['host']) && $ff->Mail['host'] == $mx && !empty($ff->Mail['auth'] )) {
                 
+                $username = $ff->Mail['username'] ;
+                $password = $ff->Mail['password'] ;
+                
                 if(!empty($ff->Core_Notify)){
                     
-                    $preferHost = false;
-                    
                     foreach ($ff->Core_Notify['routes'] as $server => $settings){
                         if(!in_array($dom, $settings['domains'])){
                             continue;
                         }
                         
+                        $core_notify = DB_DataObject::factory('core_notify');
+                        $core_notify->domain_id = $core_domain->id;
+                        $core_notify->whereAdd("
+                            sent >= NOW - INTERVAL 1 HOUR
+                        ");
+                        
+                        if($core_notify->count() >= $settings['rate']){
+                            $old = clone($w);
+                            $w->act_when = date("Y-m-d H:i:s", strtotime('+1 HOUR'));
+                            $w->update($old);
+                            $this->errorHandler(date('Y-m-d h:i:s ') . " Too many emails sent by {$dom}");
+                        }
+                        
                         $mailer->host = $server;
+                        $username = $settings['username'];
+                        $password = $settings['password'];
                         
+                        break;
                     }
                     
                 }
                 
                 $mailer->auth = true;
-                $mailer->username = $ff->Mail['username'] ;
-                $mailer->password = $ff->Mail['password'] ;        
+                $mailer->username = $username;
+                $mailer->password = $password;        
             }
             
             $res = $mailer->send($p->email, $email['headers'], $email['body']);
@@ -410,6 +436,7 @@ class Pman_Core_NotifySend extends Pman
                 $w->sent = date('Y-m-d H:i:s');
                 $w->msgid = $email['headers']['Message-Id'];
                 $w->event_id = $ev->id; // sent ok.. - no need to record it..
+                $w->domain_id = $core_domain->id;
                 $w->update($ww);
                 
                 // enable cc in notify..
@@ -459,6 +486,7 @@ class Pman_Core_NotifySend extends Pman
                 //print_r($res);
                 $this->addEvent('NOTIFY', $w, 'GREYLISTED - ' . $errmsg);
                 $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
+                $w->domain_id = $core_domain->id;
                 $w->update($ww);