NotifySend.php
[Pman.Core] / NotifySend.php
1 <?php
2 require_once 'Pman.php';
3
4 /**
5  * notification script sender - designed to be run by the Notify script - with many children running
6  * in parallel.
7  *
8  * called with an id of a core_notify element
9  *
10  * uses core_notify - to find an event to object and person.
11  *
12  * uses Events table to log failures
13  * 
14  * 
15  * calls $object->toEmail($person,$last_send, $notify) to generate an email struct with
16  *  array (
17  *      headers =>
18  *      recipients =>
19  *      body =>
20  *  )
21  *
22  *
23  * Note uses configuration
24  *
25  * Pman_Core_NotifySend[host] = 'localhost' << to override direct sending..
26  * Mail[helo] << helo host name
27  * Mail[socket_options] << any socket option.
28  */
29 class Pman_Core_NotifySend_Exception_Success extends Exception {}
30 class Pman_Core_NotifySend_Exception_Fail extends Exception {}
31
32
33 class Pman_Core_NotifySend extends Pman
34 {
35     static $cli_desc = "Send out single notification email (usually called from  Core/Notify)";
36     
37     static $cli_opts = array(
38         'debug' => array(
39             'desc' => 'Turn on debugging (see DataObjects debugLevel )',
40             'default' => 0,
41             'short' => 'v',
42             'min' => 0,
43             'max' => 0,
44             
45         ),
46         'DB_DataObject-debug' => array(
47             'desc' => 'Turn on debugging (see DataObjects debugLevel )',
48             'default' => 0,
49             'short' => 'd',
50             'min' => 1,
51             'max' => 1,
52             
53         ),
54         'force' => array(
55             'desc' => 'Force redelivery, even if it has been sent before or not queued...',
56             'default' => 0,
57             'short' => 'f',
58             'min' => 0,
59             'max' => 0,
60         ),
61         'send-to' => array(
62             'desc' => 'Send the message to this address, rather than the one listed.',
63             'default' => '',
64             'short' => 't',
65             'min' => 0,
66             'max' => 1,
67         )
68         
69         
70         
71     );
72     var $table = 'core_notify';
73     var $error_handler = 'die';
74     
75     function getAuth()
76     {
77         $ff = HTML_FlexyFramework::get();
78         if (!$ff->cli) {
79             $this->errorHandler("access denied");
80         }
81         //HTML_FlexyFramework::ensureSingle(__FILE__, $this);
82         return true;
83         
84     }
85    
86     function get($id,$opts=array())
87     {
88
89         //print_r($opts);
90         if (!empty($opts['DB_DataObject-debug'])) {
91             DB_DataObject::debugLevel($opts['DB_DataObject-debug']);
92         }
93         
94         //DB_DataObject::debugLevel(1);
95         //date_default_timezone_set('UTC');
96         // phpinfo();exit;
97         $force = empty($opts['force']) ? 0 : 1;
98         
99         $w = DB_DataObject::factory($this->table);
100
101         if (!$w->get($id)) {
102             $this->errorHandler("invalid id\n");
103         }
104
105         if (!$force && !empty($w->sent) && strtotime($w->act_when) < strtotime($w->sent)) {
106              
107             $this->errorHandler("already sent - repeat to early\n");
108         }
109         if (!empty($opts['debug'])) {
110             print_r($w);
111             $ff = HTML_FlexyFramework::get();
112             if (!isset($ff->Core_Mailer)) {
113                 $ff->Core_Mailer = array();
114             }
115             HTML_FlexyFramework::get()->Core_Mailer['debug'] = true;
116         }
117         
118         $sent = (empty($w->sent) || preg_match('/^0000/', $w->sent)) ? false : true;
119         
120         if (!$force && (!empty($w->msgid) || $sent)) {
121             $ww = clone($w);
122             if (!$sent) {   // fix sent.
123                 $w->sent = $w->sent == '0000-00-00 00:00:00' ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
124                 $w->update($ww);
125             }    
126             $this->errorHandler("message has been sent already.\n");
127         }
128         
129         $o = $w->object();
130         
131         if ($o === false)  {
132              
133             $ev = $this->addEvent('NOTIFY', $w,   "Notification event cleared (underlying object does not exist)" );
134             $w->flagSent($ev, '');
135             $this->errorHandler(date('Y-m-d h:i:s ') . $ev->remarks);
136         }
137      
138         
139         
140         $p = $w->person();
141         
142         if (isset($p->active) && empty($p->active)) {
143             $ev = $this->addEvent('NOTIFY', $w, "Notification event cleared (not user not active any more)" );;
144              $w->flagSent($ev, '');
145             $this->errorHandler(date('Y-m-d h:i:s ') . $ev->remarks);
146         }
147         // has it failed mutliple times..
148         
149         if (!empty($w->field) && isset($p->{$w->field .'_fails'}) && $p->{$w->field .'_fails'} > 9) {
150             $ev = $this->addEvent('NOTIFY', $w, "Notification event cleared (user has to many failures)" );;
151             $w->flagSent($ev, '');
152             $this->errorHandler(date('Y-m-d h:i:s ') . $ev->remarks);
153         }
154         
155         // let's work out the last notification sent to this user..
156         $l = DB_DataObject::factory($this->table);
157         
158         $lar = array(
159                 'ontable' => $w->ontable,
160                 'onid' => $w->onid,
161         );
162         // only newer version of the database us this..
163         if (isset($w->person_table)) {
164             $personid_col = strtolower($w->person_table).'_id';
165             if (isset($w->{$personid_col})) {
166                 $lar[$personid_col] = $w->{$personid_col};
167             }
168         }
169         
170         
171         $l->setFrom( $lar );       
172         $l->whereAdd('id != '. $w->id);
173         $l->orderBy('sent DESC');
174         $l->limit(1);
175         $ar = $l->fetchAll('sent');
176         $last = empty($ar) ? date('Y-m-d H:i:s', 0) : $ar[0];
177         
178         // find last event..
179         $ev = DB_DataObject::factory('Events');
180         $ev->on_id = $w->id;                           // int(11)
181         $ev->on_table = $this->table;
182         $ev->limit(1);
183         $ev->orderBy('event_when DESC');
184         $ar = $ev->fetchAll('event_when');
185         $last_event = empty($ar) ? 0 : $ar[0];
186         $next_try_min = 5;
187         if ($last_event) {
188             $next_try_min = floor((time() - strtotime($last_event)) / 60) * 2;
189         }
190         $next_try = $next_try_min . ' MINUTES';
191          
192         // this may modify $p->email. (it will not update it though)
193         $email =  $this->makeEmail($o, $p, $last, $w, $force);
194         
195         if ($email === true)  {
196             $ev = $this->addEvent('NOTIFY', $w, "Notification event cleared (not required any more) - toEmail=true" );;
197             $w->flagSent($ev, '');
198             $this->errorHandler(date('Y-m-d h:i:s ') . $ev->remarks);
199         }
200         if (is_a($email, 'PEAR_Error')) {
201             $email =array(
202                 'error' => $email->toString()
203             );
204         }
205         
206         if (empty($p) && !empty($email['recipients'])) {
207             // make a fake person..
208             $p = (object) array(
209                 'email' => $email['recipients']
210             );
211         }
212          
213         if ($email === false || isset($email['error']) || empty($p)) {
214             // object returned 'false' - it does not know how to send it..
215             $ev = $this->addEvent('NOTIFYFAIL', $w, isset($email['error'])  ? $email['error'] : "INTERNAL ERROR  - We can not handle " . $w->ontable); 
216             $w->flagSent($ev, '');
217             $this->errorHandler(date('Y-m-d h:i:s ') . $ev->remarks);
218         }
219         
220          
221         
222         if (isset($email['later'])) {
223             
224             if (false == $this->server->updateNotifyToNextServer($w, $email['later'])) {
225                 // we could not find another server - we can try again.
226                 $pp = clone($w);
227                 $w->act_when = $email['later'];
228                 $w->update($pp);
229             }
230  
231             $this->errorHandler(date('Y-m-d h:i:s ') . " Delivery postponed by email creator to {$email['later']}");
232         }
233         
234          
235         if (empty($email['headers']['Message-Id'])) {
236             $HOST = gethostname();
237             $email['headers']['Message-Id'] = "<{$this->table}-{$id}@{$HOST}>";
238             
239         }
240         
241         
242             
243         
244         //$p->email = 'alan@akbkhome.com'; //for testing..
245         //print_r($email);exit;
246         // should we fetch the watch that caused it.. - which should contain the method to call..
247         // --send-to=test@xxx.com
248        
249         if (!empty($email['send-to'])) {
250             $p->email = $email['send-to'];
251         }
252          if (!empty($opts['send-to'])) {
253             $p->email = $opts['send-to'];
254         }
255         
256             // since some of them have spaces?!?!
257         $p->email = trim($p->email);
258       
259         
260         require_once 'Validate.php';
261         if (!Validate::email($p->email, true)) {
262             $ev = $this->addEvent('NOTIFYFAIL', $w, "INVALID ADDRESS: " . $p->email);
263             $ww = clone($w);
264             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
265             $w->msgid = '';
266             $w->event_id = $ev->id;
267             $w->to_email = $p->email; 
268             $w->update($ww);
269             $this->errorHandler(date('Y-m-d h:i:s ') . "INVALID ADDRESS: " . $p->email. "\n");
270             
271         }
272         
273         
274         $ff = HTML_FlexyFramework::get();
275         
276         $explode_email = explode('@', $p->email);
277         $dom = array_pop($explode_email);
278         
279         $mxs = $this->mxs($dom);
280         $ww = clone($w);
281
282         // we might fail doing this...
283         // need to handle temporary failure..
284        
285         
286           // we try for 2 days..
287         $retry = 15;
288         if (strtotime($w->act_start) <  strtotime('NOW - 1 HOUR')) {
289             // older that 1 hour.
290             $retry = 60;
291         }
292         
293         if (strtotime($w->act_start) <  strtotime('NOW - 1 DAY')) {
294             // older that 1 day.
295             $retry = 120;
296         }
297         if (strtotime($w->act_start) <  strtotime('NOW - 2 DAY')) {
298             // older that 1 day.
299             $retry = 240;
300         }
301         
302         if (empty($mxs)) {
303             // only retry for 1 day if the MX issue..
304             if ($retry < 240) {
305                 $this->addEvent('NOTIFY', $w, 'MX LOOKUP FAILED ' . $dom );
306                 $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
307                 $this->updateServer($w);
308                 $w->update($ww);
309                 $this->errorHandler(date('Y-m-d h:i:s') . " - MX LOOKUP FAILED {$dom}\n");
310             }
311             
312             $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - BAD DOMAIN - ". $p->email );
313             $w->sent =   $w->sqlValue('NOW()'); // why not updated - used to leave as is?
314             $w->msgid = '';
315             $w->event_id = $ev->id;
316             $w->to_email = $p->email; 
317             $w->update($ww);
318             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED -  BAD DOMAIN - {$p->email} \n");
319             
320             
321         }
322         
323         
324         
325         
326         if (!$force && strtotime($w->act_start) <  strtotime('NOW - 3 DAY')) {
327             $ev = $this->addEvent('NOTIFYFAIL', $w, "BAD ADDRESS - GIVE UP - ". $p->email );
328             $w->sent =  $w->sqlValue('NOW()'); 
329             $w->msgid = '';
330             $w->event_id = $ev->id;
331             $w->to_email = $p->email; 
332             $w->update($ww);
333             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED -  GAVE UP TO OLD - {$p->email} \n");
334         }
335         
336         
337         
338         $w->to_email = $p->email; 
339         //$this->addEvent('NOTIFY', $w, 'GREYLISTED ' . $p->email . ' ' . $res->toString());
340         // we can only update act_when if it has not been sent already (only happens when running in force mode..)
341         // set act when if it's empty...
342         $w->act_when =  (!$w->act_when || $w->act_when == '0000-00-00 00:00:00') ? date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES')) : $w->act_when;
343         
344         $w->update($ww);
345         
346         $ww = clone($w);   
347         
348         $fail = false;
349         require_once 'Mail.php';
350         
351         $core_domain = DB_DataObject::factory('core_domain');
352         if(!$core_domain->get('domain', $dom)){
353             $core_domain = DB_DataObject::factory('core_domain');
354             $core_domain->setFrom(array(
355                 'domain' => $dom
356             ));
357             $core_domain->insert();
358         }
359          
360         
361         $this->initHelo();
362         
363         if (!isset($ff->Mail['helo'])) {
364             $this->errorHandler("config Mail[helo] is not set");
365         }
366         
367         
368                         
369         foreach($mxs as $mx) {
370             
371            
372             $this->debug_str = '';
373             $this->debug("Trying SMTP: $mx / HELO {$ff->Mail['helo']}");
374             $mailer = Mail::factory('smtp', array(
375                     'host'    => $mx ,
376                     'localhost' => $ff->Mail['helo'],
377                     'timeout' => 15,
378                     'socket_options' =>  isset($ff->Mail['socket_options']) ? $ff->Mail['socket_options'] : null,
379                     //'debug' => isset($opts['debug']) ?  1 : 0,
380                     'debug' => 1,
381                     'debug_handler' => array($this, 'debugHandler')
382             ));
383             
384             // if the host is the mail host + it's authenticated add auth details
385             // this normally will happen if you sent  Pman_Core_NotifySend['host']
386              
387             
388             if (isset($ff->Mail['host']) && $ff->Mail['host'] == $mx && !empty($ff->Mail['auth'] )) {
389                 
390                 $mailer->auth = true;
391                 $mailer->username = $ff->Mail['username'];
392                 $mailer->password = $ff->Mail['password'];        
393             }
394             
395             if(!empty($ff->Core_Notify) && !empty($ff->Core_Notify['routes'])){
396                 
397                 // we might want to regex 'office365 as a mx host 
398                 foreach ($ff->Core_Notify['routes'] as $server => $settings){
399                     if(!in_array($dom, $settings['domains'])){
400                         continue;
401                     }
402                     
403                     // what's the minimum timespan.. - if we have 60/hour.. that's 1 every minute.
404                     // if it's newer that '1' minute...
405                     // then shunt it..
406                     
407                     $settings['rate'] = isset( $settings['rate']) ?  $settings['rate']  : 360;
408                     
409                     $seconds = floor((60 * 60) / $settings['rate']);
410                     
411                     $core_notify = DB_DataObject::factory($this->table);
412                     $core_notify->domain_id = $core_domain->id;
413                     $core_notify->whereAdd("
414                         sent >= NOW() - INTERVAL $seconds SECOND
415                     ");
416                     
417                     if($core_notify->count()){
418                         $old = clone($w);
419                         $w->act_when = date("Y-m-d H:i:s", time() + $seconds);
420                         $this->updateServer($w);
421                         $w->update($old);
422                         $this->errorHandler(date('Y-m-d h:i:s ') . " Too many emails sent by {$dom}");
423                     }
424                      
425                     
426                     
427                     $mailer->host = $server;
428                     $mailer->auth = isset($settings['auth']) ? $settings['auth'] : true;
429                     $mailer->username = $settings['username'];
430                     $mailer->password = $settings['password'];
431                     if (isset($settings['port'])) {
432                         $mailer->port = $settings['port'];
433                     }
434                     if (isset($settings['socket_options'])) {
435                         $mailer->socket_options = $settings['socket_options'];
436                         
437                     }
438                     
439                     
440                     break;
441                 }
442                 
443             }
444         
445             
446             $res = $mailer->send($p->email, $email['headers'], $email['body']);
447              
448             
449             if ($res === true) {
450                 // success....
451                 
452                 $successEventName = (empty($email['successEventName'])) ? 'NOTIFYSENT' : $email['successEventName'];
453                 
454                 $ev = $this->addEvent($successEventName, $w, "{$w->to_email} - {$email['headers']['Subject']}");
455                 
456                 $ev->writeEventLog($this->debug_str);
457                 
458                 if(strtotime($w->act_when) > strtotime("NOW")){
459                     $w->act_when = date('Y-m-d H:i:s');
460                 }
461                 
462                 $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
463                 $w->msgid = $email['headers']['Message-Id'];
464                 $w->event_id = $ev->id; // sent ok.. - no need to record it..
465                 $w->domain_id = $core_domain->id;
466                 $w->update($ww);
467                 
468                 // enable cc in notify..
469                 if (!empty($email['headers']['Cc'])) {
470                     $cmailer = Mail::factory('smtp',  isset($ff->Mail) ? $ff->Mail : array() );
471                     $email['headers']['Subject'] = "(CC): " . $email['headers']['Subject'];
472                     $cmailer->send($email['headers']['Cc'],
473                                   $email['headers'], $email['body']);
474                     
475                 }
476                 
477                 if (!empty($email['bcc'])) {
478                     $cmailer = Mail::factory('smtp', isset($ff->Mail) ? $ff->Mail : array() );
479                     $email['headers']['Subject'] = "(CC): " . $email['headers']['Subject'];
480                     $res = $cmailer->send($email['bcc'],
481                                   $email['headers'], $email['body']);
482                     if (!$res || is_a($res, 'PEAR_Error')) {
483                         echo "could not send bcc..\n";
484                     } else {
485                         echo "Sent BCC to {$email['bcc']}\n";
486                     }
487                 }
488                 
489                 
490                 $this->errorHandler(date('Y-m-d h:i:s') . " - SENT {$w->id} - {$w->to_email} \n", true);
491             }
492             // what type of error..
493             $code = empty($res->userinfo['smtpcode']) ? -1 : $res->userinfo['smtpcode'];
494             if (!empty($res->code) && $res->code == 10001) {
495                 // fake greylist if timed out.
496                 $code = 421;
497             }
498             
499             if ($code < 0) {
500                 $this->debug($res->message);
501                 continue; // try next mx... ??? should we wait??? - nope we did not even connect..
502             }
503             // give up after 2 days..
504             if (in_array($code, array( 421, 450, 451, 452))   && $next_try_min < (2*24*60)) {
505                 // try again later..
506                 // check last event for this item..
507                 //$errmsg=  $fail ? ($res->userinfo['smtpcode'] . ': ' .$res->toString()) :  " - UNKNOWN ERROR";
508                 $errmsg=  $res->userinfo['smtpcode'] . ': ' .$res->message ;
509                 if (!empty($res->userinfo['smtptext'])) {
510                     $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
511                 }
512                 //print_r($res);
513                 $this->addEvent('NOTIFY', $w, 'GREYLISTED - ' . $errmsg);
514                 $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
515                 $this->updateServer($w);
516                 $w->domain_id = $core_domain->id;
517                 $w->update($ww);
518                 
519                 
520                 $this->errorHandler(date('Y-m-d h:i:s') . " - GREYLISTED -  $errmsg \n");
521             }
522             $fail = true;
523             break;
524         }
525         if ($fail || $next_try_min > (2*24*60)) {
526         // fail.. = log and give up..
527             $errmsg=  $fail ? ($res->userinfo['smtpcode'] . ': ' .$res->toString()) :  " - UNKNOWN ERROR";
528             if (isset($res->userinfo['smtptext'])) {
529                 $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
530             }
531             
532             $ev = $this->addEvent('NOTIFYFAIL', $w, ($fail ? "FAILED - " : "RETRY TIME EXCEEDED - ") .
533                        $errmsg);
534             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
535             $w->msgid = '';
536             $w->event_id = $ev->id;
537             $w->domain_id = $core_domain->id;
538             $w->update($ww);
539             $this->errorHandler(date('Y-m-d h:i:s') . ' - FAILED - '. ($fail ? $res->toString() : "RETRY TIME EXCEEDED\n"));
540         }
541         
542         // handle no host availalbe forever...
543         if (strtotime($w->act_start) < strtotime('NOW - 3 DAYS')) {
544             $ev = $this->addEvent('NOTIFYFAIL', $w, "RETRY TIME EXCEEDED - ". $p->email);
545             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
546             $w->msgid = '';
547             $w->event_id = $ev->id;
548             $w->domain_id = $core_domain->id;
549             $w->update($ww);
550             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED - RETRY TIME EXCEEDED\n");
551         }
552         
553         
554         $this->addEvent('NOTIFY', $w, 'NO HOST CAN BE CONTACTED:' . $p->email);
555         $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
556         
557         $this->updateServer($w);
558         
559         $w->domain_id = $core_domain->id;
560         $w->update($ww);
561         $this->errorHandler(date('Y-m-d h:i:s') ." - NO HOST AVAILABLE\n");
562
563         
564     }
565     function mxs($fqdn)
566     {
567         $ff = HTML_FlexyFramework::get();
568         if (isset($ff->Pman_Core_NotifySend['host'])) {
569             return array($ff->Pman_Core_NotifySend['host']);
570         }
571         
572         $mx_records = array();
573         $mx_weight = array();
574         $mxs = array();
575         if (!getmxrr($fqdn, $mx_records, $mx_weight)) {
576             if (!checkdnsrr($fqdn)) {
577                 return false;
578             }
579             return array($fqdn);
580         }
581         
582         asort($mx_weight,SORT_NUMERIC);
583         
584         foreach($mx_weight as $k => $weight) {
585             if (!empty($mx_records[$k])) {
586                 $mxs[] = $mx_records[$k];
587             }
588         }
589         return empty($mxs) ? false : $mxs;
590     }
591     
592     /**
593      * wrapper to call object->toEmail()
594      *
595      * return
596      *   {
597         headers : {AssocArray},
598         body: {String}
599         
600         // optional..
601         error :  {String} // error message in log.
602         send-to: {String} // use to override rcpt
603          
604      }
605      **/
606     function makeEmail($object, $rcpt, $last_sent_date, $notify, $force =false)
607     {
608         $m = 'notify'. $notify->evtype;
609         //var_dump(get_class($object) . '::' .$m);
610         if (!empty($notify->evtype) && method_exists($object,$m)) {
611             echo "calling :" . get_class($object) . '::' .$m . "\n";
612             return $object->$m($rcpt, $last_sent_date, $notify, $force);
613         }
614         
615         $type = explode('::', $notify->evtype);
616         
617         if(!empty($type[1]) && method_exists($object,$type[1])){
618             $m = $type[1];
619             echo "calling :" . get_class($object) . '::' .$m . "\n";
620             return $object->$m($rcpt, $last_sent_date, $notify, $force);
621         }
622         // fallback if evtype is empty..
623         
624         if (method_exists($object, 'toMailerData')) {
625             return $object->toMailerData(array(
626                 'rcpts'=>$rcpt,
627                 'person'=>$rcpt, // added as mediaoutreach used this?
628             )); //this is core_email - i think it's only used for testing...
629             //var_Dump($object);
630             //exit;
631         }
632         if (method_exists($object, 'toEmail')) {
633             return $object->toEmail($rcpt, $last_sent_date, $notify, $force);
634         }
635         // no way to send this.. - this needs to handle core_notify how we have used it for the approval stuff..
636         
637         return false;
638     }
639     
640     function debug($str)
641     {
642         if (empty($this->cli_args['debug'])) {
643             return;
644             
645         }
646         echo $str . "\n";
647     }
648     function output()
649     {
650         $this->errorHandler("done\n");
651     }
652     var $debug_str = '';
653     
654     function debugHandler ($smtp, $message)
655     {
656         $this->debug_str .= strlen($this->debug_str) ? "\n" : '';
657         $this->debug_str .= $message;
658         //echo $message ."\n";
659     }
660     
661     function errorHandler($msg, $success = false)
662     {
663         if($this->error_handler == 'exception'){
664             if($success){
665                 throw new Pman_Core_NotifySend_Exception_Success($msg);
666             }
667             
668             throw new Pman_Core_NotifySend_Exception_Fail($msg);
669         }
670         
671         die($msg ."\n");
672         
673         
674     }
675     
676     function updateServer($w)
677     {
678         $ff = HTML_FlexyFramework::get();
679          
680         if (empty($ff->Core_Notify['servers'])) {
681             return;
682         }
683         // some classes dont support server routing
684         if (!property_exists($w, 'server_id')) {
685             return;
686         }
687         // next server..
688         $w->server_id = ($w->server_id + 1) % count(array_keys($ff->Core_Notify['servers']));
689          
690     }
691     
692      function initHelo()
693     {
694         $ff = HTML_FlexyFramework::get();
695         
696         if (isset($ff->Core_Notify['servers-non-pool'])  &&
697             isset($ff->Core_Notify['servers-non-pool'][gethostname()]) &&
698             isset($ff->Core_Notify['servers-non-pool'][gethostname()]['helo']) ) {
699             $ff->Mail['helo'] = $ff->Core_Notify['servers-non-pool'][gethostname()]['helo'];
700             return;
701         }
702         
703         if (empty($ff->Core_Notify['servers'])) {
704             return;
705         }
706         if (!isset($ff->Core_Notify['servers'][gethostname()]) || !isset($ff->Core_Notify['servers'][gethostname()]['helo']) ) {
707             $this->jerr("Core_Notify['servers']['" . gethostname() . "']['helo'] not set");
708         }
709         $ff->Mail['helo'] = $ff->Core_Notify['servers'][gethostname()]['helo'];
710         
711     }
712     
713 }