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

Merge pull request #684 from greezybacon/issue/bounce-detection-again


Bounce detection again

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 82c31641 f97be886
Branches
Tags
No related merge requests found
......@@ -584,8 +584,10 @@ class MailFetcher {
// Fetch deliver status report
$vars['message'] = $this->getDeliveryStatusMessage($mid);
$vars['thread-type'] = 'N';
$vars['flags']['bounce'] = true;
}
else {
$vars['flags']['bounce'] = TicketFilter::isBounce($info);
$vars['message']=Format::stripEmptyLines($this->getBody($mid));
}
......
......@@ -532,12 +532,14 @@ class EmailDataParser {
// Fetch deliver status report
$data['message'] = $parser->getDeliveryStatusMessage();
$data['thread-type'] = 'N';
$data['flags']['bounce'] = true;
}
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['flags']['bounce'] = TicketFilter::isBounce($data['header']);
}
$data['subject'] = $parser->getSubject();
......
......@@ -240,7 +240,7 @@ Class ThreadEntry {
if(!$id && !($id=$this->getId()))
return false;
$sql='SELECT thread.*, info.email_mid '
$sql='SELECT thread.*, info.email_mid, info.headers '
.' ,count(DISTINCT attach.attach_id) as attachments '
.' FROM '.TICKET_THREAD_TABLE.' thread '
.' LEFT JOIN '.TICKET_EMAIL_INFO_TABLE.' info
......@@ -333,21 +333,21 @@ Class ThreadEntry {
return $this->ht['email_mid'];
}
function getEmailHeaders() {
function getEmailHeaderArray() {
require_once(INCLUDE_DIR.'class.mailparse.php');
$sql = 'SELECT headers FROM '.TICKET_EMAIL_INFO_TABLE
.' WHERE message_id='.$this->getId();
$headers = db_result(db_query($sql));
return Mail_Parse::splitHeaders($headers);
if (!isset($this->ht['@headers']))
$this->ht['@headers'] = Mail_Parse::splitHeaders($this->ht['headers']);
return $this->ht['@headers'];
}
function getEmailReferences() {
if (!isset($this->_references)) {
$this->_references = $this->getEmailMessageId();
$headers = self::getEmailHeaders();
if (isset($headers['References']))
$this->_references .= " ".$headers['References'];
$headers = self::getEmailHeaderArray();
if (isset($headers['References']) && $headers['References'])
$this->_references = $headers['References']." ";
$this->_references .= $this->getEmailMessageId();
}
return $this->_references;
}
......@@ -379,8 +379,8 @@ Class ThreadEntry {
function isAutoReply() {
if (!isset($this->is_autoreply))
$this->is_autoreply = $this->getEmailHeader()
? TicketFilter::isAutoReply($this->getEmailHeader()) : false;
$this->is_autoreply = $this->getEmailHeaderArray()
? TicketFilter::isAutoReply($this->getEmailHeaderArray()) : false;
return $this->is_autoreply;
}
......@@ -388,8 +388,8 @@ Class ThreadEntry {
function isBounce() {
if (!isset($this->is_bounce))
$this->is_bounce = $this->getEmailHeader()
? TicketFilter::isBounce($this->getEmailHeader()) : false;
$this->is_bounce = $this->getEmailHeaderArray()
? TicketFilter::isBounce($this->getEmailHeaderArray()) : false;
return $this->is_bounce;
}
......
......@@ -1375,9 +1375,10 @@ class Ticket {
if(!$alerts) return $message; //Our work is done...
$autorespond = true;
if ($autorespond && $message->isBounceOrAutoReply())
$autorespond=false;
// Do not auto-respond to bounces and other auto-replies
$autorespond = isset($vars['flags']) ? !$vars['flags']['bounce'] : true;
if ($autorespond && $message->isAutoReply())
$autorespond = false;
$this->onMessage($autorespond, $message); //must be called b4 sending alerts to staff.
......@@ -1605,6 +1606,10 @@ class Ticket {
if(!($note=$this->getThread()->addNote($vars, $errors)))
return null;
if (isset($vars['flags']) && $vars['flags']['bounce'])
// No alerts for bounce emails
$alert = false;
//Set state: Error on state change not critical!
if(isset($vars['state']) && $vars['state']) {
if($this->setState($vars['state']))
......@@ -2174,6 +2179,8 @@ class Ticket {
# Messages that are clearly auto-responses from email systems should
# not have a return 'ping' message
if (isset($vars['flags']) && $vars['flags']['bounce'])
$autorespond = false;
if ($autorespond && $message->isAutoReply())
$autorespond = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment