From 58b0f4a46ca11f72aee84397262fc0518ee9fac8 Mon Sep 17 00:00:00 2001 From: DarkSorrow Date: Wed, 17 Dec 2014 16:28:36 +0100 Subject: [PATCH] Update bounce_driver.class.php Added a diagnostic attribute in the output when it is possible, and get the last code error of this value to get a more precise error code. --- bounce_driver.class.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bounce_driver.class.php b/bounce_driver.class.php index d9a140b..9f71119 100644 --- a/bounce_driver.class.php +++ b/bounce_driver.class.php @@ -78,9 +78,10 @@ class BounceHandler{ /**** INSTANTIATION *******************************************************/ public function __construct(){ - $this->output[0]['action'] = ""; - $this->output[0]['status'] = ""; - $this->output[0]['recipient'] = ""; + $this->output[0]['action'] = ''; + $this->output[0]['status'] = ''; + $this->output[0]['recipient'] = ''; + $this->output[0]['diagnostic'] = ''; require('bounce_responses.php'); $this->bouncelist = $bouncelist; $this->autorespondlist = $autorespondlist; @@ -107,7 +108,7 @@ public function get_the_facts($eml){ // parse the email into data structures $boundary = isset($this->head_hash['Content-type']['boundary']) ? $this->head_hash['Content-type']['boundary'] : ''; $mime_sections = $this->parse_body_into_mime_sections($body, $boundary); - $this->body_hash = split("\r\n", $body); + $this->body_hash = explode("\r\n", $body); $this->first_body_hash = isset($mime_sections['first_body_part']) ? $this->parse_head($mime_sections['first_body_part']) : array(); $this->looks_like_a_bounce = $this->is_a_bounce(); @@ -226,7 +227,7 @@ public function get_the_facts($eml){ // Busted Exim MTA // Up to 50 email addresses can be listed on each header. // There can be multiple X-Failed-Recipients: headers. - (not supported) - $arrFailed = split(',', $this->head_hash['X-failed-recipients']); + $arrFailed = explode(',', $this->head_hash['X-failed-recipients']); for($j=0; $joutput[$j]['recipient'] = trim($arrFailed[$j]); $this->output[$j]['status'] = $this->get_status_code_from_text($this->output[$j]['recipient'],0); @@ -504,7 +505,7 @@ function standard_parser($content){ // associative array orstr } elseif (isset($line) && isset($entity) && preg_match('/^\s+(.+)\s*/', $line) && $entity) { $line = trim($line); - if (strpos($array[2], '=?') !== FALSE) + if ((isset($array[2])) && (strpos($array[2], '=?') !== FALSE)) $line = iconv_mime_decode($array[2], ICONV_MIME_DECODE_CONTINUE_ON_ERROR, "UTF-8"); $hash[$entity] .= ' '. $line; } @@ -552,6 +553,7 @@ function parse_machine_parsable_body_part($str){ // temporary failure in this case. $ddc=''; $judgement=''; $ddc = $this->decode_diagnostic_code($temp['Diagnostic-code']['text']); + $this->output[0]['diagnostic'] = $ddc; $judgement = $this->get_action_from_status_code($ddc); if($judgement == 'transient'){ if(stristr($temp['Action'],'failed')!==FALSE){ @@ -672,11 +674,11 @@ function get_action_from_status_code($code){ } function decode_diagnostic_code($dcode){ - if(preg_match("/(\d\.\d\.\d)\s/", $dcode, $array)){ - return $array[1]; + if(preg_match_all("/(\d\.\d\.\d)\s/", $dcode, $array)){ + return end(end($array)); } - else if(preg_match("/(\d\d\d)\s/", $dcode, $array)){ - return $array[1]; + else if(preg_match_all("/(\d\d\d)\s/", $dcode, $array)){ + return end(end($array)); } }