fix #8131 - chinese translations
[Pman.Core] / NotifySend.php
index 6c2a3a8..f94ff33 100644 (file)
@@ -87,7 +87,9 @@ class Pman_Core_NotifySend extends Pman
    
     function get($id,$opts=array())
     {
-
+        //if ($this->database_is_locked()) {
+        //    die("LATER - DATABASE IS LOCKED");
+       // }
         //print_r($opts);
         if (!empty($opts['DB_DataObject-debug'])) {
             DB_DataObject::debugLevel($opts['DB_DataObject-debug']);
@@ -124,17 +126,30 @@ class Pman_Core_NotifySend extends Pman
             HTML_FlexyFramework::get()->Core_Mailer['debug'] = true;
         }
         
-        $sent = (empty($w->sent) || preg_match('/^0000/', $w->sent)) ? false : true;
+        $sent = (empty($w->sent) || strtotime( $w->sent) < 100 ) ? false : true;
         
         if (!$force && (!empty($w->msgid) || $sent)) {
             $ww = clone($w);
             if (!$sent) {   // fix sent.
-                $w->sent = $w->sent == '0000-00-00 00:00:00' ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
+                $w->sent = strtotime( $w->sent) < 100 ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
                 $w->update($ww);
             }    
             $this->errorHandler("message has been sent already.\n");
         }
         
+        // we have a bug with msgid not getting filled.
+        $cev = DB_DataObject::Factory('Events');
+        $cev->on_table =  $this->table;
+        $cev->on_id =  $w->id;
+        $cev->whereAdd("action IN ('NOTIFYSENT', 'NOTIFYFAIL')");
+        $cev->limit(1);
+        if ($cev->count()) {
+            $cev->find(true);
+            $w->flagDone($cev, $cev->action == 'NOTIFYSENT' ? 'alreadysent' : '');
+            $this->errorHandler( $cev->action . " (fix old) ".  $cev->remarks);
+        }
+        
+        
         $o = $w->object();
         
         if ($o === false)  {
@@ -229,7 +244,7 @@ class Pman_Core_NotifySend extends Pman
          
         
         if (isset($email['later'])) {
-            
+             
             $this->server->updateNotifyToNextServer($w, $email['later'],true);
              
             $this->errorHandler("Delivery postponed by email creator to {$email['later']}");
@@ -354,7 +369,8 @@ class Pman_Core_NotifySend extends Pman
             $this->errorHandler("config Mail[helo] is not set");
         }
         
-        
+        $email = DB_DataObject::factory('core_notify_sender')->filterEmail($email, $w);
+            
                         
         foreach($mxs as $mx) {
             
@@ -430,6 +446,8 @@ class Pman_Core_NotifySend extends Pman
                 
             }
         
+           
+            
             
             $res = $mailer->send($p->email, $email['headers'], $email['body']);
             if (is_object($res)) {
@@ -522,7 +540,11 @@ class Pman_Core_NotifySend extends Pman
                 $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
             }
             
-            if ($res->userinfo['smtpcode'] == 550) {
+            if ( $res->userinfo['smtpcode']> 500 ) {
+                
+                DB_DataObject::factory('core_notify_sender')->checkSmtpResponse($email, $w, $errmsg);
+
+                
                 if ($this->server->checkSmtpResponse($errmsg, $core_domain)) {
                     $ev = $this->addEvent('NOTIFY', $w, 'BLACKLISTED  - ' . $errmsg);
                     $this->server->updateNotifyToNextServer($w,  $retry_when,true);