diff --git a/api/pipe.php b/api/pipe.php index 851e18f4a6951dab6b3d1c210a73aa038d4d825c..699e7400001c8f497a5bbd30b5d921ca353abe2b 100644 --- a/api/pipe.php +++ b/api/pipe.php @@ -106,10 +106,18 @@ if($ticket) { } elseif(($ticket=Ticket::create($var, $errors, 'email'))) { // create new ticket. $msgid=$ticket->getLastMsgId(); } else { // failure.... + + // report success on hard rejection if(isset($errors['errno']) && $errors['errno'] == 403) - api_exit(EX_SUCCESS); //report success on hard rejection + api_exit(EX_SUCCESS); - api_exit(EX_DATAERR,'Ticket create Failed '.implode("\n",$errors)."\n\n"); + // check if it's a bounce! + if($var['header'] && TicketFilter::isAutoBounce($var['header'])) { + $ost->logWarning('Bounced email', $var['message'], false); + api_exit(EX_SUCCESS); + } + + api_exit(EX_DATAERR, 'Ticket create Failed '.implode("\n",$errors)."\n\n"); } //Ticket created...save attachments if enabled. diff --git a/include/class.filter.php b/include/class.filter.php index 9c172edaabaf3f819df46e49e5fd2da33eb90d62..a70b4ddf04bedf2f71ae20a662308e71abb68856 100644 --- a/include/class.filter.php +++ b/include/class.filter.php @@ -866,6 +866,10 @@ class TicketFilter { * http://msdn.microsoft.com/en-us/library/ee219609(v=exchg.80).aspx */ /* static */ function isAutoResponse($headers) { + + if($headers && !is_array($headers)) + $headers = Mail_Parse::splitHeaders($headers); + $auto_headers = array( 'Auto-Submitted' => 'AUTO-REPLIED', 'Precedence' => array('AUTO_REPLY', 'BULK', 'JUNK', 'LIST'), @@ -875,21 +879,56 @@ class TicketFilter { 'X-Autoresponse' => '', 'X-Auto-Reply-From' => '' ); + foreach ($auto_headers as $header=>$find) { - if ($value = strtoupper($headers[$header])) { - # Search text must be found at the beginning of the header - # value. This is especially import for something like the - # subject line, where something like an autoreponse may - # appear somewhere else in the value. - if (is_array($find)) { - foreach ($find as $f) - if (strpos($value, $f) === 0) - return true; - } elseif (strpos($value, $find) === 0) { - return true; - } + if(!isset($headers[$header])) continue; + + $value = strtoupper($headers[$header]); + # Search text must be found at the beginning of the header + # value. This is especially import for something like the + # subject line, where something like an autoreponse may + # appear somewhere else in the value. + + if (is_array($find)) { + foreach ($find as $f) + if (strpos($value, $f) === 0) + return true; + } elseif (strpos($value, $find) === 0) { + return true; } } + + # Bounces also counts as auto-responses. + if(self::isAutoBounce($headers)) + return true; + + return false; + } + + function isAutoBounce($headers) { + + if($headers && !is_array($headers)) + $headers = Mail_Parse::splitHeaders($headers); + + $bounce_headers = array( + 'From' => array('<MAILER-DAEMON@MAILER-DAEMON>', 'MAILER-DAEMON', '<>'), + 'Subject' => array('DELIVERY FAILURE', 'DELIVERY STATUS', 'UNDELIVERABLE:'), + ); + + foreach ($bounce_headers as $header => $find) { + if(!isset($headers[$header])) continue; + + $value = strtoupper($headers[$header]); + + if (is_array($find)) { + foreach ($find as $f) + if (strpos($value, $f) === 0) + return true; + } elseif (strpos($value, $find) === 0) { + return true; + } + } + return false; } diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index dca6ac3dfbae94edd33bfb04332d004ecde616d4..fce15f537eb6125b5689ebef37879d267e90f850 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -378,7 +378,7 @@ class MailFetcher { //Is the email address banned? if($mailinfo['email'] && TicketFilter::isBanned($mailinfo['email'])) { //We need to let admin know... - $ost->logWarning('Ticket denied', 'Banned email - '.$mailinfo['email']); + $ost->logWarning('Ticket denied', 'Banned email - '.$mailinfo['email'], false); return true; //Report success (moved or delete) } @@ -421,6 +421,12 @@ class MailFetcher { if(isset($errors['errno']) && $errors['errno'] == 403) return true; + # check if it's a bounce! + if($var['header'] && TicketFilter::isAutoBounce($var['header'])) { + $ost->logWarning('Bounced email', $var['message'], false); + return true; + } + //TODO: Log error.. return null; }