$bouncehandler->web_beacon_preg_1 = "/u=([0-9a-fA-F]{32})/"; $bouncehandler->web_beacon_preg_2 = "/m=(\\d*)/"; // find a web beacon in an X-header field (in the head section) $bouncehandler->x_header_search_1 = "X-ctnlist-suid"; //$bouncehandler->x_header_search_2 = "X-sumthin-sumpin"; if ($_GET['eml']) { echo "<HR><P><B>" . $_GET['eml'] . "</B> -- "; echo "<a href=\"testdriver1.php\">View a different bounce</a></P>"; $bounce = file_get_contents("eml/" . $_GET['eml']); echo "<P>Quick and dirty bounce handler:<BR>\n useage:\n <blockquote><code>\n require_once(\"bounce_driver.class.php\");<br>\n \$bouncehandler = new Bouncehandler();<br>\n \$multiArray = \$bouncehandler->get_the_facts(\$strEmail); , or<br>\n \$multiArray = \$bouncehandler->parse_email(\$strEmail);</code> (same thing)\n </blockquote>\n returns a multi-dimensional associative array of bounced recipient addresses and their SMTP status codes (if available)<br><br>\n <code>print_r(\$multiArray);</code>\n <P>"; $multiArray = $bouncehandler->get_the_facts($bounce); echo "<TEXTAREA COLS=100 ROWS=" . count($multiArray) * 8 . ">"; //print_r($bouncehandler); exit; print_r($multiArray); echo "</TEXTAREA>"; $bounce = $bouncehandler->init_bouncehandler($bounce, 'string'); list($head, $body) = preg_split("/\r\n\r\n/", $bounce, 2); } else { print "<OL><LI><a href=\"" . $_SERVER['PHP_SELF'] . "?testall=true\">Test All Sample Bounce E-mails</a>\n\n"; print "<LI>Or, select a bounce email to view the parsed results:</OL>\n"; $files = get_sorted_file_list('eml'); if (is_array($files)) { reset($files); echo "<P>Files:</P>\n"; foreach ($files as $file) { echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?eml=" . urlencode($file) . "\">{$file}</a><br>\n"; } } exit; } echo "<P>Will return recipient's email address, the RFC1893 error code, and the action. Action can be one of the following:\n<UL>\n<LI>'transient'(temporary problem),\n<LI>'failed' (permanent problem),\n<LI>'autoreply' (a vacation auto-response), or\n<LI>'' (nothing -- not classified).</UL>";
/** * Tests a single email. * * @param string $bounce Contents of the bounce email. * * @return void */ private function _testSingle($bounce) { $multiArray = $this->_bouncehandler->get_the_facts($bounce); echo "<TEXTAREA COLS=100 ROWS=" . count($multiArray) * 8 . ">"; print_r($multiArray); echo "</TEXTAREA>"; $bounce = $this->_bouncehandler->init_bouncehandler($bounce, 'string'); list($head, $body) = preg_split("/\r\n\r\n/", $bounce, 2); echo '<h2>Raw email:</h2><br />'; echo "<TEXTAREA COLS=100 ROWS=12>"; echo htmlspecialchars($bounce); echo "</TEXTAREA><br />"; echo "<h2>Parsed head</h2>\n"; $head_hash = $this->_bouncehandler->parse_head($head); echo "<TEXTAREA COLS=100 ROWS=" . count($head_hash) * 2.7 . ">"; print_r($head_hash); echo "</TEXTAREA><br />"; if ($this->_bouncehandler->is_RFC1892_multipart_report($head_hash)) { echo '<h2 style="color:red;">'; echo 'Looks like an RFC1892 multipart report'; echo '</h2>'; } else { if ($this->_bouncehandler->looks_like_an_FBL) { echo '<h2 style="color:red;">'; echo 'Looks like a feedback loop'; if ($this->_bouncehandler->is_hotmail_fbl) { echo ' in Hotmail Doofus Format (HDF?)'; } else { echo ' in Abuse Feedback Reporting format (ARF)'; } echo '</h2>'; echo "<TEXTAREA COLS=100 ROWS=12>"; print_r($this->_bouncehandler->fbl_hash); echo "</TEXTAREA>"; } else { echo "<h2 style='color:red;'>Not an RFC1892 multipart report</H2>"; echo "<TEXTAREA COLS=100 ROWS=100>"; print_r($body); echo "</TEXTAREA>"; exit; } } echo "<h2>Here is the parsed report</h2>\n"; echo '<p>Postfix adds an appropriate X- header (X-Postfix-Sender:), '; echo 'so you do not need to create one via phpmailer. RFC\'s call '; echo 'for an optional Original-recipient field, but mandatory '; echo 'Final-recipient field is a fair substitute.</p>'; $boundary = $head_hash['Content-type']['boundary']; $mime_sections = $this->_bouncehandler->parse_body_into_mime_sections($body, $boundary); $rpt_hash = $this->_bouncehandler->parse_machine_parsable_body_part($mime_sections['machine_parsable_body_part']); echo "<TEXTAREA COLS=100 ROWS=" . count($rpt_hash) * 16 . ">"; print_r($rpt_hash); echo "</TEXTAREA>"; echo "<h2>Here is the error status code</h2>\n"; echo "<P>It's all in the status code, if you can find one.</P>"; for ($i = 0; $i < count($rpt_hash['per_recipient']); $i++) { echo "<P>Report #" . ($i + 1) . "<BR>\n"; echo $this->_bouncehandler->find_recipient($rpt_hash['per_recipient'][$i]); $scode = $rpt_hash['per_recipient'][$i]['Status']; echo "<PRE>{$scode}</PRE>"; echo $this->_bouncehandler->fetch_status_messages($scode); echo "</P>\n"; } echo '<h2>The Diagnostic-code</h2>'; echo '<p>is not the same as the reported status code, but it seems '; echo 'to be more descriptive, so it should be extracted (if possible).'; for ($i = 0; $i < count($rpt_hash['per_recipient']); $i++) { echo "<P>Report #" . ($i + 1) . " <BR>\n"; echo $this->_bouncehandler->find_recipient($rpt_hash['per_recipient'][$i]); $dcode = $rpt_hash['per_recipient'][$i]['Diagnostic-code']['text']; if ($dcode) { echo "<PRE>{$dcode}</PRE>"; echo $this->_bouncehandler->fetch_status_messages($dcode); } else { echo "<PRE>couldn't decode</PRE>"; } echo "</P>\n"; } echo '<h2>Grab original To: and From:</h2>\\n'; echo '<p>Just in case we don\'t have an Original-recipient: field, or '; echo 'a X-Postfix-Sender: field, we can retrieve information from '; echo 'the (optional) returned message body part</p>' . PHP_EOL; $head = $this->_bouncehandler->get_head_from_returned_message_body_part($mime_sections); echo "<P>From: " . $head['From']; echo "<br>To: " . $head['To']; echo "<br>Subject: " . $head['Subject'] . "</P>"; echo "<h2>Here is the body in RFC1892 parts</h2>\n"; echo '<[>Three parts: [first_body_part], '; echo '[machine_parsable_body_part], and '; echo ' [returned_message_body_part]</p>'; echo "<TEXTAREA cols=100 rows=100>"; print_r($mime_sections); echo "</TEXTAREA>"; }