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