diff --git a/include/api.tickets.php b/include/api.tickets.php index 9fbbd853658fdd7270d97726864f983f9c611dc5..fcb55d81b5b27cc62ee8b3cfb71d4128f0344fab 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -40,7 +40,7 @@ class TicketApiController extends ApiController { $supported = array_merge($supported, array('header', 'mid', 'emailId', 'to-email-id', 'ticketId', 'reply-to', 'reply-to-name', 'in-reply-to', 'references', 'thread-type', - 'flags' => array('bounce', 'auto-reply'), + 'flags' => array('bounce', 'auto-reply', 'spam', 'viral'), 'recipients' => array('*' => array('name', 'email', 'source')) )); diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 3ab0d891a84e15a14a7a7c2ccd0634d557776a6b..7bddd9ef00d6eaf90f10bc0e55b2bd70fa30e3c5 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -269,13 +269,22 @@ class MailFetcher { if(!($headerinfo=imap_headerinfo($this->mbox, $mid)) || !$headerinfo->from) return null; + $raw_header = $this->getHeader($mid); + $info = array( + 'raw_header' => &$raw_header, + 'headers' => $headerinfo, + 'decoder' => $this, + 'type' => $this->getMimeType($headerinfo), + ); + Signal::send('mail.decoded', $this, $info); + $sender=$headerinfo->from[0]; //Just what we need... $header=array('name' => $this->mime_decode(@$sender->personal), 'email' => trim(strtolower($sender->mailbox).'@'.$sender->host), 'subject'=> $this->mime_decode(@$headerinfo->subject), 'mid' => trim(@$headerinfo->message_id), - 'header' => $this->getHeader($mid), + 'header' => $raw_header, 'in-reply-to' => $headerinfo->in_reply_to, 'references' => $headerinfo->references, ); @@ -624,6 +633,7 @@ class MailFetcher { $vars['subject'] = $mailinfo['subject'] ?: '[No Subject]'; $vars['emailId'] = $mailinfo['emailId'] ?: $this->getEmailId(); $vars['to-email-id'] = $mailinfo['emailId'] ?: 0; + $vars['flags'] = new ArrayObject(); if ($this->isBounceNotice($mid)) { // Fetch the original References and assign to 'references' @@ -694,6 +704,9 @@ class MailFetcher { } } + // Allow signal handlers to interact with the message decoding + Signal::send('mail.processed', $this, $vars); + $seen = false; if (($thread = ThreadEntry::lookupByEmailHeaders($vars, $seen)) && ($message = $thread->postEmail($vars))) { diff --git a/include/class.mailparse.php b/include/class.mailparse.php index d498a77f7fd99bfe737fc1a9bddef58b505baa53..91d0f57003efc898e2c1bbf6299400fcc75414e0 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -58,6 +58,9 @@ class Mail_Parse { 'decode_headers'=> $this->decode_headers, 'decode_bodies' => $this->decode_bodies); + $info = array('raw' => &$this->mime_message); + Signal::send('mail.received', $this, $info); + $this->splitBodyHeader(); $decoder = new Mail_mimeDecode($this->mime_message); @@ -66,6 +69,18 @@ class Mail_Parse { if (PEAR::isError($this->struct)) return false; + $info = array( + 'raw_header' => &$this->header, + 'headers' => &$this->struct->headers, + 'body' => &$this->struct->parts, + 'type' => $this->struct->ctype_primary.'/'.$this->struct->ctype_secondary, + 'mail' => $this->struct, + 'decoder' => $decoder, + ); + + // Allow signal handlers to interact with the processing + Signal::send('mail.decoded', $decoder, $info); + // Handle wrapped emails when forwarded if ($this->struct && $this->struct->parts) { $outer = $this->struct; @@ -533,6 +548,7 @@ class EmailDataParser { $data['header'] = $parser->getHeader(); $data['mid'] = $parser->getMessageId(); $data['priorityId'] = $parser->getPriority(); + $data['flags'] = new ArrayObject(); //FROM address: who sent the email. if(($fromlist = $parser->getFromAddressList())) {