Skip to content
Snippets Groups Projects
Commit 09279cdd authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #871 from greezybacon/issue/rfc1892


bounce: Handle rfc/1892 style bounce notices

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents db79dfb6 42b7c57d
No related branches found
No related tags found
No related merge requests found
......@@ -515,15 +515,23 @@ class MailFetcher {
return false;
}
function getOriginalMessage($mid) {
if (!($body = $this->getPart($mid, 'message/rfc822')))
return null;
function getOriginalMessageHeaders($mid) {
if (!($body = $this->getPart($mid, 'message/rfc822'))) {
// Handle rfc1892 style bounces
if (!($body = $this->getPart($mid, 'text/rfc822-headers'))) {
return null;
}
else {
// Add a junk body for the parser
$body .= "\n\nIgnored";
}
}
$msg = new Mail_Parse($body);
if (!$msg->decode())
return null;
return $msg->struct;
return $msg->struct->headers;
}
function getPriority($mid) {
......@@ -619,9 +627,9 @@ class MailFetcher {
if ($this->isBounceNotice($mid)) {
// Fetch the original References and assign to 'references'
if ($msg = $this->getOriginalMessage($mid)) {
$vars['references'] = $msg->headers['references'];
unset($vars['in-reply-to']);
if ($headers = $this->getOriginalMessageHeaders($mid)) {
$vars['references'] = $headers['references'];
$vars['in-reply-to'] = @$headers['in-reply-to'] ?: null;
}
// Fetch deliver status report
$vars['message'] = $this->getDeliveryStatusMessage($mid);
......
......@@ -268,11 +268,17 @@ class Mail_Parse {
return false;
}
function getOriginalMessage() {
function getOriginalMessageHeaders() {
foreach ($this->struct->parts as $p) {
$ctype = $p->ctype_primary.'/'.$p->ctype_secondary;
if (strtolower($ctype) === 'message/rfc822')
return $p->parts[0];
return $p->parts[0]->headers;
// Handle rfc1892 style bounces
if (strtolower($ctype) === 'text/rfc822-headers') {
$T = new Mail_mimeDecode($p->body . "\n\nIgnored");
if ($struct = $T->decode())
return $struct->headers;
}
}
return null;
}
......@@ -604,8 +610,10 @@ class EmailDataParser {
if ($parser->isBounceNotice()) {
// Fetch the original References and assign to 'references'
if ($msg = $parser->getOriginalMessage())
$data['references'] = $msg->headers['references'];
if ($headers = $parser->getOriginalMessageHeaders()) {
$data['references'] = $headers['references'];
$data['in-reply-to'] = @$headers['in-reply-to'] ?: null;
}
// Fetch deliver status report
$data['message'] = $parser->getDeliveryStatusMessage();
$data['thread-type'] = 'N';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment