From ac621624cf4813b29ebf284910d3c4a152589b52 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Wed, 29 Jan 2014 10:22:29 -0600 Subject: [PATCH] test: Add regression test for mail header matching Fixes a few E_NOTICE messages Drops bounce checking inside autoReply checking --- include/class.filter.php | 25 ++++++++++++++----------- include/class.mailparse.php | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/class.filter.php b/include/class.filter.php index ad0b46ee5..80081aa8a 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -824,13 +824,16 @@ class TicketFilter { $headers = Mail_Parse::splitHeaders($headers); $auto_headers = array( - 'Auto-Submitted' => 'AUTO-REPLIED', + 'Auto-Submitted' => array('AUTO-REPLIED', 'AUTO-GENERATED'), 'Precedence' => array('AUTO_REPLY', 'BULK', 'JUNK', 'LIST'), - 'Subject' => array('OUT OF OFFICE', 'AUTO-REPLY:', 'AUTORESPONSE'), + 'X-Precedence' => array('AUTO_REPLY', 'BULK', 'JUNK', 'LIST'), 'X-Autoreply' => 'YES', 'X-Auto-Response-Suppress' => array('ALL', 'DR', 'RN', 'NRN', 'OOF', 'AutoReply'), - 'X-Autoresponse' => '', - 'X-Auto-Reply-From' => '' + 'X-Autoresponse' => '*', + 'X-AutoReply-From' => '*', + 'X-Autorespond' => '*', + 'X-Mail-Autoreply' => '*', + 'X-Autogenerated' => 'REPLY', ); foreach ($auto_headers as $header=>$find) { @@ -846,19 +849,17 @@ class TicketFilter { foreach ($find as $f) if (strpos($value, $f) === 0) return true; + } elseif ($find === '*') { + return true; } elseif (strpos($value, $find) === 0) { return true; } } - # Bounces also counts as auto-responses. - if(self::isBounce($headers)) - return true; - return false; } - function isBounce($headers) { + static function isBounce($headers) { if($headers && !is_array($headers)) $headers = Mail_Parse::splitHeaders($headers); @@ -867,15 +868,17 @@ class TicketFilter { 'From' => array('stripos', array('MAILER-DAEMON', '<>'), null, false), 'Subject' => array('stripos', - array('DELIVERY FAILURE', 'DELIVERY STATUS', 'UNDELIVERABLE:'), 0), + array('DELIVERY FAILURE', 'DELIVERY STATUS', + 'UNDELIVERABLE:', 'Undelivered Mail Returned'), 0), 'Return-Path' => array('strcmp', array('<>'), 0), 'Content-Type' => array('stripos', array('report-type=delivery-status'), null, false), + 'X-Failed-Recipients' => array('strpos', array('@'), null, false) ); foreach ($bounce_headers as $header => $find) { if(!isset($headers[$header])) continue; - list($func, $searches, $pos, $neg) = $find; + @list($func, $searches, $pos, $neg) = $find; if(!($value = $headers[$header]) || !is_array($searches)) continue; diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 3356cb9bf..687efa0ee 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -96,7 +96,7 @@ class Mail_Parse { foreach ($headers as $hdr) { list($name, $val) = explode(": ", $hdr, 2); # Create list of values if header is specified more than once - if ($array[$name] && $as_array) { + if (isset($array[$name]) && $as_array) { if (is_array($array[$name])) $array[$name][] = $val; else $array[$name] = array($array[$name], $val); } else { -- GitLab