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 { ...@@ -515,15 +515,23 @@ class MailFetcher {
return false; return false;
} }
function getOriginalMessage($mid) { function getOriginalMessageHeaders($mid) {
if (!($body = $this->getPart($mid, 'message/rfc822'))) if (!($body = $this->getPart($mid, 'message/rfc822'))) {
return null; // 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); $msg = new Mail_Parse($body);
if (!$msg->decode()) if (!$msg->decode())
return null; return null;
return $msg->struct; return $msg->struct->headers;
} }
function getPriority($mid) { function getPriority($mid) {
...@@ -619,9 +627,9 @@ class MailFetcher { ...@@ -619,9 +627,9 @@ class MailFetcher {
if ($this->isBounceNotice($mid)) { if ($this->isBounceNotice($mid)) {
// Fetch the original References and assign to 'references' // Fetch the original References and assign to 'references'
if ($msg = $this->getOriginalMessage($mid)) { if ($headers = $this->getOriginalMessageHeaders($mid)) {
$vars['references'] = $msg->headers['references']; $vars['references'] = $headers['references'];
unset($vars['in-reply-to']); $vars['in-reply-to'] = @$headers['in-reply-to'] ?: null;
} }
// Fetch deliver status report // Fetch deliver status report
$vars['message'] = $this->getDeliveryStatusMessage($mid); $vars['message'] = $this->getDeliveryStatusMessage($mid);
......
...@@ -268,11 +268,17 @@ class Mail_Parse { ...@@ -268,11 +268,17 @@ class Mail_Parse {
return false; return false;
} }
function getOriginalMessage() { function getOriginalMessageHeaders() {
foreach ($this->struct->parts as $p) { foreach ($this->struct->parts as $p) {
$ctype = $p->ctype_primary.'/'.$p->ctype_secondary; $ctype = $p->ctype_primary.'/'.$p->ctype_secondary;
if (strtolower($ctype) === 'message/rfc822') 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; return null;
} }
...@@ -604,8 +610,10 @@ class EmailDataParser { ...@@ -604,8 +610,10 @@ class EmailDataParser {
if ($parser->isBounceNotice()) { if ($parser->isBounceNotice()) {
// Fetch the original References and assign to 'references' // Fetch the original References and assign to 'references'
if ($msg = $parser->getOriginalMessage()) if ($headers = $parser->getOriginalMessageHeaders()) {
$data['references'] = $msg->headers['references']; $data['references'] = $headers['references'];
$data['in-reply-to'] = @$headers['in-reply-to'] ?: null;
}
// Fetch deliver status report // Fetch deliver status report
$data['message'] = $parser->getDeliveryStatusMessage(); $data['message'] = $parser->getDeliveryStatusMessage();
$data['thread-type'] = 'N'; $data['thread-type'] = 'N';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment