Created
November 19, 2014 14:41
-
-
Save briedis/fac72fd1cb1146f3ad71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
private function _processMessage($messageBody){ | |
$re = new Returned__item; | |
/** @noinspection PhpDynamicAsStaticMethodCallInspection */ | |
$body = \Mail_Mimedecode::decode([ | |
'include_bodies' => true, | |
'decode_bodies' => true, | |
'decode_headers' => true, | |
'input' => $messageBody | |
]); | |
if(PEAR::isError($body)){ | |
self::error("MIME parse: " . $body->getMessage()); | |
return $re; | |
} | |
$mailTo = $body->headers['to']; | |
// Izgūstam paša e-pasta id | |
if(preg_match('/^info\+(\d+)@.*$/', $mailTo, $matches)){ | |
$re->mailId = $matches[1]; | |
}else{ | |
// Ja nav meilaId, tad nezinam, kas tas ir | |
return $re; | |
} | |
$parts = is_array($body->parts) ? $body->parts : []; | |
// Izķeksējām ārā atgriešanas iemeslu | |
foreach($parts as $v){ | |
if(strtolower($v->ctype_secondary) == 'delivery-status'){ | |
if(preg_match('/Code:(.*)/s', trim($v->body), $matches)){ | |
$reason = str_replace('smtp;', '', $matches[1]); | |
$reason = trim(preg_replace('/\n|\s+/', ' ', $reason)); | |
if(strpos($reason, ':')){ | |
$reason = explode(':', $reason); // Piemēram: "550 5.1.1 <[email protected]>: Recipient address rejected: User unknown" | |
$reason = trim(array_pop($reason)); | |
} | |
$re->reason = $reason; | |
} | |
break; | |
} | |
} | |
return $re; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment