From 0dbb7cecdb08d15a623f68f0024ec9298fdccd2b Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 21 Nov 2014 16:29:57 -0800 Subject: [PATCH] Bounce-handling test option added. Correct path issue in perms notification. --- e107_admin/cron.php | 2 +- e107_admin/mailout.php | 64 +++++++++++++++++++++--- e107_handlers/bounce_handler.php | 86 ++++++++++++++++++++------------ 3 files changed, 113 insertions(+), 39 deletions(-) diff --git a/e107_admin/cron.php b/e107_admin/cron.php index 65183594e..72e953930 100644 --- a/e107_admin/cron.php +++ b/e107_admin/cron.php @@ -383,7 +383,7 @@ class cron_admin_ui extends e_admin_ui elseif (!$active) // show instructions { $setpwd_message = $frm->open("generate")."" - .LAN_CRON_15.":
".rtrim($_SERVER['DOCUMENT_ROOT'], '/').e_HTTP."cron.php token=".$pref['e_cron_pwd'].' >/dev/null 2>&1';
+				.LAN_CRON_15.":
".e_ROOT."cron.php token=".$pref['e_cron_pwd'].' >/dev/null 2>&1';
 				
 				$setpwd_message .= "
". LAN_CRON_16.""; if(e_DOMAIN && file_exists("/usr/local/cpanel/version")) diff --git a/e107_admin/mailout.php b/e107_admin/mailout.php index 451c6e441..15bb8051f 100644 --- a/e107_admin/mailout.php +++ b/e107_admin/mailout.php @@ -421,6 +421,10 @@ class mailout_main_ui extends e_admin_ui { $this->sendTestEmail(); // Send test email - uses standard 'single email' handler } + if(!empty($_POST['send_bounce_test'])) + { + $this->sendTestBounce(); + } elseif (isset($_POST['updateprefs'])) { $this->saveMailPrefs($mes); // TODO check if functional, $emessage -> $mes @@ -431,6 +435,29 @@ class mailout_main_ui extends e_admin_ui } + + private function sendTestBounce() + { + $mes = e107::getMessage(); + $pref = e107::getPref(); + + $sendto = $pref['mail_bounce_email']; + + $eml = array('subject'=>'Test Bounce', 'body' => 'Test Bounce Email address','e107_header'=>99999999, 'extra_header' => 'X-Bounce-Test: true'); + + if(e107::getEmail()->sendEmail($sendto, 'Bounce handler', $eml)) + { + $mes->addSuccess('Test Bounce sent to '.$sendto); + } + else + { + $mes->addError('Failed Bounce email sent to '.$sendto); + } + + + } + + private function sendTestEmail() { $mes = e107::getMessage(); @@ -840,7 +867,7 @@ class mailout_main_ui extends e_admin_ui $lastload = e107::getCache()->retrieve('emailLastBounce',FALSE,TRUE,TRUE); $lastBounce = round((time() - $lastload) / 60); - $lastBounceText = ($lastBounce > 1256474) ? "Never" : "".$lastBounce . " minutes ago."; + $lastBounceText = ($lastBounce > 1256474) ? "Never" : "".$lastBounce . " minutes ago."; $text = "
@@ -1065,22 +1092,45 @@ class mailout_main_ui extends e_admin_ui ".LAN_MAILOUT_32." - ".$frm->text('mail_bounce_email2', $pref['mail_bounce_email'], 40, 'size=xxlarge')." +
".$frm->text('mail_bounce_email2', $pref['mail_bounce_email'], 40, 'size=xlarge'); + + if(!empty($pref['mail_bounce_email'])) + { + $text .= $frm->admin_button('send_bounce_test','Send Test','primary','Test'); + } + + $text .= "
- ".LAN_MAILOUT_233."".(e_DOCROOT).e107::getFolder('handlers')."bounce_handler.php"; + ".LAN_MAILOUT_233."".(e_ROOT).e107::getFolder('handlers')."bounce_handler.php"; + + $status = ''; - if(!is_readable(e_HANDLER.'bounce_handler.php')) { - $text .= "
".LAN_MAILOUT_161.''; + $status = LAN_MAILOUT_161; } elseif(!is_executable(e_HANDLER.'bounce_handler.php')) // Seems to give wrong answers on Windoze { - $text .= "
".LAN_MAILOUT_162.''; + $status = LAN_MAILOUT_162; } - $text .= "
".LAN_MAILOUT_235." + else + { + // $text .= " ".ADMIN_TRUE_ICON; + } + + if(!empty($status)) + { + $text .= "  ".$status.""; + } + + + + $text .= "
".LAN_MAILOUT_235."
+ + + ".LAN_MAILOUT_236."".$lastBounceText." "; diff --git a/e107_handlers/bounce_handler.php b/e107_handlers/bounce_handler.php index b09149fc2..d336a9969 100644 --- a/e107_handlers/bounce_handler.php +++ b/e107_handlers/bounce_handler.php @@ -3,55 +3,79 @@ // WARNING, any echoed output from this script will be returned to the sender as a bounce message. - - $_E107['debug'] = false; - - + + $_E107['debug'] = true; + if (!defined('e107_INIT')) { - $_E107['cli'] = TRUE; - $class2 = realpath(dirname(__FILE__)."/../")."/class2.php"; - require_once($class2); -} + $_E107['cli'] = true; + $_E107['allow_guest'] = true; // allow to run while in members-only mode. + $_E107['no_forceuserupdate'] = true; + $_E107['no_maintenance'] = true; -if(ADMIN && varset($_GET['eml'])) -{ - $_E107['debug'] = true; + $class2 = realpath(dirname(__FILE__)."/../")."/class2.php"; + + @require_once($class2); } $bnc = new e107Bounce; -$process = (varset($_GET['eml']) && $_E107['debug']) ? $_GET['eml'].".eml" : FALSE; -$bnc->process($process); +$bnc->process(); + class e107Bounce { + private $debug = false; + private $source = false; + + function __construct() + { + if(ADMIN && vartrue($_GET['eml'])) + { + $this->debug = true; + $this->source = $_GET['eml'].".eml"; + } + } + function process($source='') { - global $_E107,$pref; - + + $pref = e107::getPref(); + e107::getCache()->CachePageMD5 = '_'; e107::getCache()->set('emailLastBounce',time(),TRUE,FALSE,TRUE); - $strEmail= (!$source) ? $this->mailRead(-1) : file_get_contents(e_HANDLER."eml/".$source); + $strEmail= ($this->source == false) ? $this->mailRead(-1) : file_get_contents(e_HANDLER."eml/".$this->source); - if(!$strEmail) + if(strpos($strEmail,'X-Bounce-Test: true')!==false) // Bounce Test from Admin Area. { - if($_E107['debug'] === true) + $this->debug = true; + } + + if(empty($strEmail)) // Failed. + { + if($this->debug === true && !empty($this->source)) { echo "Couldn't get email data"; } - return; + else + { + $message = "Empty Email!"; + } + + } + else + { + $multiArray = Bouncehandler::get_the_facts($strEmail); + $head = BounceHandler::parse_head($strEmail); + $message = null; + $identifier = deftrue('MAIL_IDENTIFIER', 'X-e107-id'); + $e107_userid = (isset($head[$identifier])) ? $head[$identifier] : $this->getHeader($strEmail, $identifier); } - $multiArray = Bouncehandler::get_the_facts($strEmail); - $head = BounceHandler::parse_head($strEmail); - $message = null; + - $identifier = deftrue('MAIL_IDENTIFIER', 'X-e107-id'); - $e107_userid = (isset($head[$identifier])) ? $head[$identifier] : $this->getHeader($strEmail, $identifier); - - if($_E107['debug']) + if($this->debug === true) { require_once(e_HANDLER."mail.php"); $message = "Your Bounce Handler is working. The data of the email you sent is displayed below.
"; @@ -61,13 +85,13 @@ class e107Bounce $message .= "A user-id was detected in the email you sent: ".$e107_userid."
"; } - $message .= "

Head

"; - $message .= print_a($head,true); - $message .= "

Emails Found

".print_r($multiArray,TRUE). "
"; + // $message .= "

Head

"; + // $message .= print_a($head,true); + // $message .= "

Emails Found

".print_r($multiArray,TRUE). "
"; $message .= "
".$strEmail. "
"; - if(varset($_GET['eml'])) + if(!empty($this->source )) { echo $message; } @@ -82,7 +106,7 @@ class e107Bounce { if($errors = $this->setUser_Bounced($e107_userid)) { - $mesage .= print_a($errors); + // $message .= print_a($errors,true); } }