require_once("bounce_driver.class.php"); if($_GET['eml']){ $bounce = file_get_contents("eml/".$_GET['eml']); $bounce = BounceHandler::init_bouncehandler($bounce, 'string'); list($head, $body) = preg_split("/\r\n\r\n/", $bounce, 2); } else{ print "select a bounce email to view the parse"; if ($handle = opendir('eml')) { echo "
Files:
\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if($file=='.' || $file=='..') continue; echo "$fileDownload source code"; exit; } echo "
Attempts to parse Multipart reports for hard bounces, according to RFC1892 (RFC 1892 - The Multipart/Report Content Type for the Reporting of Mail System Administrative Messages) and RFC1894 (RFC 1894 - An Extensible Message Format for Delivery Status Notifications). We can reuse this for any well-formed bounces.
"; echo ""; print_r($head_hash); echo ""; if (BounceHandler::is_RFC1892_multipart_report($head_hash) === TRUE){ print "
Postfix adds an appropriate X- header (X-Postfix-Sender:), so you do not need to create one via phpmailer. RFC's call for an optional Original-recipient field, but mandatory Final-recipient field is a fair substitute.
"; $boundary = $head_hash['Content-type']['boundary']; $mime_sections = BounceHandler::parse_body_into_mime_sections($body, $boundary); $rpt_hash = BounceHandler::parse_machine_parsable_body_part($mime_sections['machine_parsable_body_part']); echo ""; print_r($rpt_hash); echo ""; echo "
It's all in the status code, if you can find one.
"; for($i=0; $i$scode"; echo BounceHandler::fetch_status_messages($scode); echo "\n"; } echo "
is not the same as the reported status code, but it seems to be more descriptive, so it should be extracted (if possible).";
for($i=0; $i
\n";
echo BounceHandler::get_recipient($rpt_hash['per_recipient'][$i]);
$dcode = $rpt_hash['per_recipient'][$i]['Diagnostic-code']['text'];
if($dcode){
echo "$dcode
";
echo BounceHandler::fetch_status_messages($dcode);
}
else{
echo "couldn't decode
";
}
echo "
Just in case we don't have an Original-recipient: field, or a X-Postfix-Sender: field, we can retrieve information from the (optional) returned message body part
\n"; $head = BounceHandler::get_head_from_returned_message_body_part($mime_sections); echo "From: ".$head['From']."
To: ".$head['To']."
Subject: ".$head['Subject']."
Three parts: [first_body_part], [machine_parsable_body_part], and [returned_message_body_part]
"; echo ""; print_r($mime_sections); echo ""; /* $status_code = BounceHandler::format_status_code($rpt_hash['per_recipient'][$i]['Status']); $status_code_msg = BounceHandler::fetch_status_messages($status_code['code']); $status_code_remote_msg = $status_code['text']; $diag_code = BounceHandler::format_status_code($rpt_hash['per_recipient'][$i]['Diagnostic-code']['text']); $diag_code_msg = BounceHandler::fetch_status_messages($diag_code['code']); $diag_code_remote_msg = $diag_code['text']; */ ?>