NotifySend.php
[Pman.Core] / NotifySend.php
index e7e1e46..e6a8404 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'])) {
@@ -387,16 +396,7 @@ class Pman_Core_NotifySend extends Pman
                             continue;
                         }
                         
-                        $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();
-                        }
-                        
-                        $core_notify = DB_DataObject::factory('core_notify');
+                        $core_notify = DB_DataObject::factory($this->table);
                         $core_notify->domain_id = $core_domain->id;
                         $core_notify->whereAdd("
                             sent >= NOW - INTERVAL 1 HOUR
@@ -407,14 +407,12 @@ class Pman_Core_NotifySend extends Pman
                             $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}");
-                            return;
                         }
                         
                         $mailer->host = $server;
                         $username = $settings['username'];
                         $password = $settings['password'];
                         
-                        
                         break;
                     }
                     
@@ -438,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..
@@ -487,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);
                 
                 
@@ -507,6 +507,7 @@ class Pman_Core_NotifySend extends Pman
             $w->sent = date('Y-m-d H:i:s');
             $w->msgid = '';
             $w->event_id = $ev->id;
+            $w->domain_id = $core_domain->id;
             $w->update($ww);
             $this->errorHandler(date('Y-m-d h:i:s') . ' - FAILED - '. ($fail ? $res->toString() : "RETRY TIME EXCEEDED\n"));
         }
@@ -517,6 +518,7 @@ class Pman_Core_NotifySend extends Pman
             $w->sent = date('Y-m-d H:i:s');
             $w->msgid = '';
             $w->event_id = $ev->id;
+            $w->domain_id = $core_domain->id;
             $w->update($ww);
             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED - RETRY TIME EXCEEDED\n");
         }
@@ -524,6 +526,7 @@ class Pman_Core_NotifySend extends Pman
         
         $this->addEvent('NOTIFY', $w, 'NO HOST CAN BE CONTACTED:' . $p->email);
         $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + 5 MINUTES'));
+        $w->domain_id = $core_domain->id;
         $w->update($ww);
         $this->errorHandler(date('Y-m-d h:i:s') ." - NO HOST AVAILABLE\n");