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>"; echo "<P>You could dereference the \$multiArray in a 'for loop', for example...</P>\n<PRE>\n foreach(\$multiArray as \$the){\n switch(\$the['action']){\n case 'failed':\n //do something\n kill_him(\$the['recipient']);\n break;\n case 'transient':\n //do something else\n \$num_attempts = delivery_attempts(\$the['recipient']);\n if(\$num_attempts > 10){\n kill_him(\$the['recipient']);\n }\n else{\n insert_into_queue(\$the['recipient'], (\$num_attempts+1));\n }\n break;\n case 'autoreply':\n //do something different\n postpone(\$the['recipient'], '7 days');\n break;\n default:\n //don't do anything\n break;\n }\n }\n\nOr, if it is an FBL, you could use the class variables to access the\ndata (Unlike Multipart-reports, FBL's report only one bounce)\nYou could also use them if the output array has only one index:\n\n if(\$bouncehandler->type == 'fbl'\n or count(\$bouncehandler->output) == 1)\n {\n echo \$bouncehandler->action : .... <i>{$bouncehandler->action}</i>\n echo \$bouncehandler->status : .... <i>{$bouncehandler->status}</i>\n echo \$bouncehandler->recipient : .... <i>{$bouncehandler->recipient}</i>\n echo \$bouncehandler->feedback_type : .... <i>{$bouncehandler->feedback_type}</i>\n }\n\nThese class variables are safe for all bounce types:\n\n echo \$bouncehandler->type : .... <i>{$bouncehandler->type}</i>\n echo \$bouncehandler->subject : .... <i>{$bouncehandler->subject}</i>\n echo \$bouncehandler->web_beacon_1 : .... <i>{$bouncehandler->web_beacon_1}</i>\n echo \$bouncehandler->web_beacon_2 : .... <i>{$bouncehandler->web_beacon_2}</i>\n echo \$bouncehandler->x_header_beacon_1 : .... <i>{$bouncehandler->x_header_beacon_1}</i>\n echo \$bouncehandler->x_header_beacon_2 : .... <i>{$bouncehandler->x_header_beacon_2}</i>\n\n</PRE>\n"; echo "<P>That's all you need to know, but if you want to get more complicated you can. All methods are public. See source code.</P><BR>"; echo "<hr><h2>Here is the parsed head</h2>\n"; $head_hash = $bouncehandler->parse_head($head); echo "<TEXTAREA COLS=100 ROWS=" . count($head_hash) * 2.7 . ">"; print_r($head_hash); echo "</TEXTAREA>"; if ($bouncehandler->is_hotmail_fbl) { echo "RRRRRR" . $bouncehandler->recipient; } exit; if ($bouncehandler->is_RFC1892_multipart_report($head_hash)) { print "<h2><font color=red>Looks like an RFC1892 multipart report</font></H2>"; } else { if ($bouncehandler->looks_like_an_FBL) { print "<h2><font color=red>It's a Feedback Loop, "; if ($bouncehandler->is_hotmail_fbl) { print " in Hotmail Doofus Format (HDF?)</font></H2>"; } else {
/** * 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>"; }