hide popup message if failure is handled - not sure what knock on effect this may...
[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         if (!$force && strtotime($w->act_when) < strtotime($w->sent)) {
105             
106             
107             $this->errorHandler("send 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) { 
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,
134                             "Notification event cleared (underlying object does not exist)" );;
135             $ww = clone($w);
136             $w->sent = $w->sent == '0000-00-00 00:00:00' ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
137             $w->msgid = '';
138             $w->event_id = $ev->id;
139             $w->update($ww);
140             $this->errorHandler(date('Y-m-d h:i:s ') . 
141                      "Notification event cleared (underlying object does not exist)" 
142                     ."\n");
143         }
144      
145         
146         
147         $p = $w->person();
148         
149         if (isset($p->active) && empty($p->active)) {
150             $ev = $this->addEvent('NOTIFY', $w,
151                             "Notification event cleared (not user not active any more)" );;
152             $ww = clone($w);
153             $w->sent = $w->sent == '0000-00-00 00:00:00' ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
154             $w->msgid = '';
155             $w->event_id = $ev->id;
156             $w->update($ww);
157             $this->errorHandler(date('Y-m-d h:i:s ') . 
158                      "Notification event cleared (not user not active any more)" 
159                     ."\n");
160             $this->errorHandler("message has been sent already.\n");
161         }
162         
163         
164         // let's work out the last notification sent to this user..
165         $l = DB_DataObject::factory($this->table);
166         
167         $lar = array(
168                 'ontable' => $w->ontable,
169                 'onid' => $w->onid,
170         );
171         // only newer version of the database us this..
172         $personid_col = strtolower($w->person_table).'_id';
173         if (isset($w->{$personid_col})) {
174             $lar[$personid_col] = $w->{$personid_col};
175         }
176         
177         
178         $l->setFrom( $lar );       
179         $l->whereAdd('id != '. $w->id);
180         $l->orderBy('sent DESC');
181         $l->limit(1);
182         $ar = $l->fetchAll('sent');
183         $last = empty($ar) ? date('Y-m-d H:i:s', 0) : $ar[0];
184         
185         // find last event..
186         $ev = DB_DataObject::factory('Events');
187         $ev->on_id = $w->id;                           // int(11)
188         $ev->on_table = $this->table;
189         $ev->limit(1);
190         $ev->orderBy('event_when DESC');
191         $ar = $ev->fetchAll('event_when');
192         $last_event = empty($ar) ? 0 : $ar[0];
193         $next_try_min = 5;
194         if ($last_event) {
195             $next_try_min = floor((time() - strtotime($last_event)) / 60) * 2;
196         }
197         $next_try = $next_try_min . ' MINUTES';
198          
199         // this may modify $p->email. (it will not update it though)
200         $email =  $this->makeEmail($o, $p, $last, $w, $force);
201         
202         if ($email === true)  {
203             
204             $ev = $this->addEvent('NOTIFY', $w,
205                             "Notification event cleared (not required any more)" );;
206             $ww = clone($w);
207             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
208             $w->msgid = '';
209             $w->event_id = $ev->id;
210             $w->update($ww);
211             $this->errorHandler(date('Y-m-d h:i:s ') . 
212                      "Notification event cleared (not required any more)" 
213                     ."\n");
214         }
215         if (is_a($email, 'PEAR_Error')) {
216             $email =array(
217                 'error' => $email->toString()
218             );
219         }
220         
221         if (empty($p) && !empty($email['recipients'])) {
222             // make a fake person..
223             $p = (object) array(
224                 'email' => $email['recipients']
225             );
226         }
227          
228         if ($email === false || isset($email['error']) || empty($p)) {
229             // object returned 'false' - it does not know how to send it..
230             $ev = $this->addEvent('NOTIFY', $w, isset($email['error'])  ?
231                             $email['error'] : "INTERNAL ERROR  - We can not handle " . $w->ontable); 
232             $ww = clone($w);
233             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
234             $w->msgid = '';
235             $w->event_id = $ev->id;
236             $w->update($ww);
237             $this->errorHandler(date('Y-m-d h:i:s ') . 
238                     (isset($email['error'])  ?
239                             $email['error'] : "INTERNAL ERROR  - We can not handle " . $w->ontable)
240                     ."\n");
241         }
242         
243         
244         if (isset($email['later'])) {
245             $old = clone($w);
246             $w->act_when = $email['later'];
247             $w->update($old);
248             $this->errorHandler(date('Y-m-d h:i:s ') . " Delivery postponed by email creator to {$email['later']}");
249         }
250         
251          
252         if (empty($email['headers']['Message-Id'])) {
253             $HOST = gethostname();
254             $email['headers']['Message-Id'] = "<{$this->table}-{$id}@{$HOST}>";
255             
256         }
257         
258         
259             
260         
261         //$p->email = 'alan@akbkhome.com'; //for testing..
262         //print_r($email);exit;
263         // should we fetch the watch that caused it.. - which should contain the method to call..
264         // --send-to=test@xxx.com
265        
266         if (!empty($email['send-to'])) {
267             $p->email = $email['send-to'];
268         }
269          if (!empty($opts['send-to'])) {
270             $p->email = $opts['send-to'];
271         }
272         
273             // since some of them have spaces?!?!
274         $p->email = trim($p->email);
275       
276         
277         require_once 'Validate.php';
278         if (!Validate::email($p->email, true)) {
279             $ev = $this->addEvent('NOTIFY', $w, "INVALID ADDRESS: " . $p->email);
280             $ww = clone($w);
281             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
282             $w->msgid = '';
283             $w->event_id = $ev->id;
284             $w->update($ww);
285             $this->errorHandler(date('Y-m-d h:i:s ') . "INVALID ADDRESS: " . $p->email. "\n");
286             
287         }
288         
289         
290         $ff = HTML_FlexyFramework::get();
291         
292         $explode_email = explode('@', $p->email);
293         $dom = array_pop($explode_email);
294         
295         $mxs = $this->mxs($dom);
296         $ww = clone($w);
297
298         // we might fail doing this...
299         // need to handle temporary failure..
300        
301         
302           // we try for 3 days..
303         $retry = 5;
304         if (strtotime($w->act_start) <  strtotime('NOW - 1 HOUR')) {
305             // older that 1 hour.
306             $retry = 15;
307         }
308         
309         if (strtotime($w->act_start) <  strtotime('NOW - 1 DAY')) {
310             // older that 1 day.
311             $retry = 60;
312         }
313         if (strtotime($w->act_start) <  strtotime('NOW - 2 DAY')) {
314             // older that 1 day.
315             $retry = 120;
316         }
317         
318         if ($mxs === false) {
319             // only retry for 2 day son the MX issue..
320             if ($retry < 120) {
321                 $this->addEvent('NOTIFY', $w, 'MX LOOKUP FAILED ' . $dom );
322                 $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
323                 $w->update($ww);
324                 $this->errorHandler(date('Y-m-d h:i:s') . " - MX LOOKUP FAILED\n");
325             }
326             
327             $ev = $this->addEvent('NOTIFY', $w, "BAD ADDRESS - BAD DOMAIN - ". $p->email );
328             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
329             $w->msgid = '';
330             $w->event_id = $ev->id;
331             $w->update($ww);
332             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED -  BAD EMAIL - {$p->email} \n");
333             
334             
335         }
336         
337         
338         
339         
340         if (!$force && strtotime($w->act_start) <  strtotime('NOW - 14 DAY')) {
341             $ev = $this->addEvent('NOTIFY', $w, "BAD ADDRESS - GIVE UP - ". $p->email );
342             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') :$w->sent; // do not update if sent.....
343             $w->msgid = '';
344             $w->event_id = $ev->id;
345             $w->update($ww);
346             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED -  GAVE UP TO OLD - {$p->email} \n");
347         }
348         
349         
350         
351         $w->to_email = $p->email; 
352         //$this->addEvent('NOTIFY', $w, 'GREYLISTED ' . $p->email . ' ' . $res->toString());
353         // we can only update act_when if it has not been sent already (only happens when running in force mode..)
354         $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;
355         $w->update($ww);
356         
357         $ww = clone($w);   
358         
359         $fail = false;
360         require_once 'Mail.php';
361         
362         $core_domain = DB_DataObject::factory('core_domain');
363         if(!$core_domain->get('domain', $dom)){
364             $core_domain = DB_DataObject::factory('core_domain');
365             $core_domain->setFrom(array(
366                 'domain' => $dom
367             ));
368             $core_domain->insert();
369         }
370                         
371         foreach($mxs as $mx) {
372             
373             if (!isset($ff->Mail['helo'])) {
374                 $this->errorHandler("config Mail[helo] is not set");
375             }
376             $this->debug_str = '';
377             $this->debug("Trying SMTP: $mx / HELO {$ff->Mail['helo']}");
378             $mailer = Mail::factory('smtp', array(
379                     'host'    => $mx ,
380                     'localhost' => $ff->Mail['helo'],
381                     'timeout' => 15,
382                     'socket_options' =>  isset($ff->Mail['socket_options']) ? $ff->Mail['socket_options'] : null,
383                     //'debug' => isset($opts['debug']) ?  1 : 0,
384                     'debug' => 1,
385                     'debug_handler' => array($this, 'debugHandler')
386                 ));
387             
388             // if the host is the mail host + it's authenticated add auth details
389             // this normally will happen if you sent  Pman_Core_NotifySend['host']
390             if (isset($ff->Mail['host']) && $ff->Mail['host'] == $mx && !empty($ff->Mail['auth'] )) {
391                 
392                 $username = $ff->Mail['username'] ;
393                 $password = $ff->Mail['password'] ;
394                 
395                 if(!empty($ff->Core_Notify) && !empty($ff->Core_Notify['routes'])){
396                     
397                     foreach ($ff->Core_Notify['routes'] as $server => $settings){
398                         if(!in_array($dom, $settings['domains'])){
399                             continue;
400                         }
401                         
402                         // what's the minimum timespan.. - if we have 60/hour.. that's 1 every minute.
403                         // if it's newer that '1' minute...
404                         // then shunt it..
405                         
406                         $seconds = floor((60 * 60) / $settings['rate']);
407                         
408                         $core_notify = DB_DataObject::factory($this->table);
409                         $core_notify->domain_id = $core_domain->id;
410                         $core_notify->whereAdd("
411                             sent >= NOW() - INTERVAL $seconds SECONDS
412                         ");
413                         
414                         if($core_notify->count()){
415                             $old = clone($w);
416                             $w->act_when = date("Y-m-d H:i:s", time() + $seconds);
417                             $w->update($old);
418                             $this->errorHandler(date('Y-m-d h:i:s ') . " Too many emails sent by {$dom}");
419                         }
420                         
421                         // that make's this test obsolete...
422                         /*
423                         
424                         $core_notify = DB_DataObject::factory($this->table);
425                         $core_notify->domain_id = $core_domain->id;
426                         $core_notify->whereAdd("
427                             sent >= NOW() - INTERVAL 1 HOUR
428                         ");
429                         
430                         if($core_notify->count() >= $settings['rate']){
431                             $old = clone($w);
432                             $w->act_when = date("Y-m-d H:i:s", strtotime('+1 HOUR'));
433                             $w->update($old);
434                             $this->errorHandler(date('Y-m-d h:i:s ') . " Too many emails sent by {$dom}");
435                         }
436                         */
437                         
438                         
439                         
440                         $mailer->host = $server;
441                         $username = $settings['username'];
442                         $password = $settings['password'];
443                         
444                         break;
445                     }
446                     
447                 }
448                 
449                 $mailer->auth = true;
450                 $mailer->username = $username;
451                 $mailer->password = $password;        
452             }
453             
454             $res = $mailer->send($p->email, $email['headers'], $email['body']);
455              
456             
457             if ($res === true) {
458                 // success....
459                 
460                 $successEventName = (empty($email['successEventName'])) ? 'NOTIFYSENT' : $email['successEventName'];
461                 
462                 $ev = $this->addEvent($successEventName, $w, "{$w->to_email} - {$email['headers']['Subject']}");
463                 
464                 $ev->writeEventLog($this->debug_str);
465                 
466                 if(strtotime($w->act_when) > strtotime("NOW")){
467                     $w->act_when = date('Y-m-d H:i:s');
468                 }
469                 
470                 $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
471                 $w->msgid = $email['headers']['Message-Id'];
472                 $w->event_id = $ev->id; // sent ok.. - no need to record it..
473                 $w->domain_id = $core_domain->id;
474                 $w->update($ww);
475                 
476                 // enable cc in notify..
477                 if (!empty($email['headers']['Cc'])) {
478                     $cmailer = Mail::factory('smtp',  isset($ff->Mail) ? $ff->Mail : array() );
479                     $email['headers']['Subject'] = "(CC): " . $email['headers']['Subject'];
480                     $cmailer->send($email['headers']['Cc'],
481                                   $email['headers'], $email['body']);
482                     
483                 }
484                 
485                 if (!empty($email['bcc'])) {
486                     $cmailer = Mail::factory('smtp', isset($ff->Mail) ? $ff->Mail : array() );
487                     $email['headers']['Subject'] = "(CC): " . $email['headers']['Subject'];
488                     $res = $cmailer->send($email['bcc'],
489                                   $email['headers'], $email['body']);
490                     if (!$res || is_a($res, 'PEAR_Error')) {
491                         echo "could not send bcc..\n";
492                     } else {
493                         echo "Sent BCC to {$email['bcc']}\n";
494                     }
495                 }
496                 
497                 
498                 $this->errorHandler(date('Y-m-d h:i:s') . " - SENT {$w->id} - {$w->to_email} \n", true);
499             }
500             // what type of error..
501             $code = empty($res->userinfo['smtpcode']) ? -1 : $res->userinfo['smtpcode'];
502             if (!empty($res->code) && $res->code == 10001) {
503                 // fake greylist if timed out.
504                 $code = 421;
505             }
506             
507             if ($code < 0) {
508                 $this->debug($res->message);
509                 continue; // try next mx... ??? should we wait??? - nope we did not even connect..
510             }
511             // give up after 2 days..
512             if (in_array($code, array( 421, 450, 451, 452))   && $next_try_min < (2*24*60)) {
513                 // try again later..
514                 // check last event for this item..
515                 //$errmsg=  $fail ? ($res->userinfo['smtpcode'] . ': ' .$res->toString()) :  " - UNKNOWN ERROR";
516                 $errmsg=  $res->userinfo['smtpcode'] . ': ' .$res->message ;
517                 if (!empty($res->userinfo['smtptext'])) {
518                     $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
519                 }
520                 //print_r($res);
521                 $this->addEvent('NOTIFY', $w, 'GREYLISTED - ' . $errmsg);
522                 $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + ' . $retry . ' MINUTES'));
523                 $w->domain_id = $core_domain->id;
524                 $w->update($ww);
525                 
526                 
527                 $this->errorHandler(date('Y-m-d h:i:s') . " - GREYLISTED -  $errmsg \n");
528             }
529             $fail = true;
530             break;
531         }
532         if ($fail || $next_try_min > (2*24*60)) {
533         // fail.. = log and give up..
534             $errmsg=  $fail ? ($res->userinfo['smtpcode'] . ': ' .$res->toString()) :  " - UNKNOWN ERROR";
535             if (isset($res->userinfo['smtptext'])) {
536                 $errmsg=  $res->userinfo['smtpcode'] . ':' . $res->userinfo['smtptext'];
537             }
538             
539             $ev = $this->addEvent('NOTIFY', $w, ($fail ? "FAILED - " : "RETRY TIME EXCEEDED - ") .
540                        $errmsg);
541             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
542             $w->msgid = '';
543             $w->event_id = $ev->id;
544             $w->domain_id = $core_domain->id;
545             $w->update($ww);
546             $this->errorHandler(date('Y-m-d h:i:s') . ' - FAILED - '. ($fail ? $res->toString() : "RETRY TIME EXCEEDED\n"));
547         }
548         
549         // handle no host availalbe forever...
550         if (strtotime($w->act_start) < strtotime('NOW - 3 DAYS')) {
551             $ev = $this->addEvent('NOTIFY', $w, "RETRY TIME EXCEEDED - ". $p->email);
552             $w->sent = (!$w->sent || $w->sent == '0000-00-00 00:00:00') ? $w->sqlValue('NOW()') : $w->sent; // do not update if sent.....
553             $w->msgid = '';
554             $w->event_id = $ev->id;
555             $w->domain_id = $core_domain->id;
556             $w->update($ww);
557             $this->errorHandler(date('Y-m-d h:i:s') . " - FAILED - RETRY TIME EXCEEDED\n");
558         }
559         
560         
561         $this->addEvent('NOTIFY', $w, 'NO HOST CAN BE CONTACTED:' . $p->email);
562         $w->act_when = date('Y-m-d H:i:s', strtotime('NOW + 5 MINUTES'));
563         $w->domain_id = $core_domain->id;
564         $w->update($ww);
565         $this->errorHandler(date('Y-m-d h:i:s') ." - NO HOST AVAILABLE\n");
566
567         
568     }
569     function mxs($fqdn)
570     {
571         $ff = HTML_FlexyFramework::get();
572         if (isset($ff->Pman_Core_NotifySend['host'])) {
573             return array($ff->Pman_Core_NotifySend['host']);
574         }
575         
576         $mx_records = array();
577         $mx_weight = array();
578         $mxs = array();
579         if (!getmxrr($fqdn, $mx_records, $mx_weight)) {
580             if (!checkdnsrr($fqdn)) {
581                 return false;
582             }
583             return array($fqdn);
584         }
585         
586         asort($mx_weight,SORT_NUMERIC);
587         
588         foreach($mx_weight as $k => $weight) {
589             $mxs[] = $mx_records[$k];
590         }
591         return $mxs;
592     }
593     
594     /**
595      * wrapper to call object->toEmail()
596      *
597      * return
598      *   {
599         headers : {AssocArray},
600         body: {String}
601         
602         // optional..
603         error :  {String} // error message in log.
604         send-to: {String} // use to override rcpt
605          
606      }
607      **/
608     function makeEmail($object, $rcpt, $last_sent_date, $notify, $force =false)
609     {
610         $m = 'notify'. $notify->evtype;
611         //var_dump(get_class($object) . '::' .$m);
612         if (!empty($notify->evtype) && method_exists($object,$m)) {
613             echo "calling :" . get_class($object) . '::' .$m . "\n";
614             return $object->$m($rcpt, $last_sent_date, $notify, $force);
615         }
616         
617         $type = explode('::', $notify->evtype);
618         
619         if(!empty($type[1]) && method_exists($object,$type[1])){
620             $m = $type[1];
621             echo "calling :" . get_class($object) . '::' .$m . "\n";
622             return $object->$m($rcpt, $last_sent_date, $notify, $force);
623         }
624                 
625         if (method_exists($object, 'toMailerData')) {
626             return $object->toMailerData(array(
627                 'rcpts'=>$rcpt,
628                 'person'=>$rcpt, // added as mediaoutreach used this?
629             )); //this is core_email - i think it's only used for testing...
630             //var_Dump($object);
631             //exit;
632         }
633         
634         return $object->toEmail($rcpt, $last_sent_date, $notify, $force);
635     }
636     
637     function debug($str)
638     {
639         if (empty($this->cli_args['debug'])) {
640             return;
641             
642         }
643         echo $str . "\n";
644     }
645     function output()
646     {
647         $this->errorHandler("done\n");
648     }
649     var $debug_str = '';
650     
651     function debugHandler ($smtp, $message)
652     {
653         $this->debug_str .= strlen($this->debug_str) ? "\n" : '';
654         $this->debug_str .= $message;
655     }
656     
657     function errorHandler($msg, $success = false)
658     {
659         if($this->error_handler == 'exception'){
660             if($success){
661                 throw new Pman_Core_NotifySend_Exception_Success($msg);
662             }
663             
664             throw new Pman_Core_NotifySend_Exception_Fail($msg);
665         }
666         
667         die($msg);
668         
669         
670     }
671 }