Skip to content
Snippets Groups Projects
Commit a31333c1 authored by Jared Hancock's avatar Jared Hancock
Browse files

emails: Mail_Parse detects bounce emails

parent 97d3ccef
Branches
Tags
No related merge requests found
...@@ -39,7 +39,7 @@ class TicketApiController extends ApiController { ...@@ -39,7 +39,7 @@ class TicketApiController extends ApiController {
if(!strcasecmp($format, 'email')) { if(!strcasecmp($format, 'email')) {
$supported = array_merge($supported, array('header', 'mid', $supported = array_merge($supported, array('header', 'mid',
'emailId', 'ticketId', 'reply-to', 'reply-to-name', 'emailId', 'ticketId', 'reply-to', 'reply-to-name',
'in-reply-to', 'references')); 'in-reply-to', 'references', 'thread-type'));
$supported['attachments']['*'][] = 'cid'; $supported['attachments']['*'][] = 'cid';
} }
......
...@@ -169,6 +169,40 @@ class Mail_Parse { ...@@ -169,6 +169,40 @@ class Mail_Parse {
return Mail_Parse::parseAddressList($header); return Mail_Parse::parseAddressList($header);
} }
function isBounceNotice() {
if (!($body = $this->getPart($this->struct, 'message/delivery-status')))
return false;
$info = self::splitHeaders($body);
if (!isset($info['Action']))
return false;
return strcasecmp($info['Action'], 'failed') === 0;
}
function getDeliveryStatusMessage() {
$ctype = @strtolower($this->struct->ctype_primary.'/'.$this->struct->ctype_secondary);
if ($ctype == 'multipart/report'
&& isset($this->struct->ctype_parameters['report-type'])
&& $this->struct->ctype_parameters['report-type'] == 'delivery-status'
) {
return sprintf('<pre>%s</pre>',
Format::htmlchars(
$this->getPart($this->struct, 'text/plain', 1)
));
}
return false;
}
function getOriginalMessage() {
foreach ($this->struct->parts as $p) {
$ctype = $p->ctype_primary.'/'.$p->ctype_secondary;
if (strtolower($ctype) === 'message/rfc822')
return $p->parts[0];
}
return null;
}
function getBody(){ function getBody(){
global $cfg; global $cfg;
...@@ -394,16 +428,27 @@ class EmailDataParser { ...@@ -394,16 +428,27 @@ class EmailDataParser {
} }
} }
if ($parser->isBounceNotice()) {
// Fetch the original References and assign to 'references'
if ($msg = $parser->getOriginalMessage())
$data['references'] = $msg->headers['references'];
// Fetch deliver status report
$data['message'] = $parser->getDeliveryStatusMessage();
$data['thread-type'] = 'N';
}
else {
// Typical email
$data['message'] = Format::stripEmptyLines($parser->getBody());
$data['in-reply-to'] = $parser->struct->headers['in-reply-to'];
$data['references'] = $parser->struct->headers['references'];
}
$data['subject'] = $parser->getSubject(); $data['subject'] = $parser->getSubject();
$data['message'] = Format::stripEmptyLines($parser->getBody());
$data['header'] = $parser->getHeader(); $data['header'] = $parser->getHeader();
$data['mid'] = $parser->getMessageId(); $data['mid'] = $parser->getMessageId();
$data['priorityId'] = $parser->getPriority(); $data['priorityId'] = $parser->getPriority();
$data['emailId'] = $emailId; $data['emailId'] = $emailId;
$data['in-reply-to'] = $parser->struct->headers['in-reply-to'];
$data['references'] = $parser->struct->headers['references'];
if (($replyto = $parser->getReplyTo()) && !PEAR::isError($replyto)) { if (($replyto = $parser->getReplyTo()) && !PEAR::isError($replyto)) {
$replyto = $replyto[0]; $replyto = $replyto[0];
$data['reply-to'] = $replyto->mailbox.'@'.$replyto->host; $data['reply-to'] = $replyto->mailbox.'@'.$replyto->host;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment