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

Parse collaborators from email header.

parent 77df040b
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,10 @@ class TicketApiController extends ApiController { ...@@ -39,7 +39,10 @@ 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',
'collaborators' => array("*" => array("name", "email"))
));
$supported['attachments']['*'][] = 'cid'; $supported['attachments']['*'][] = 'cid';
} }
......
...@@ -269,9 +269,9 @@ class MailFetcher { ...@@ -269,9 +269,9 @@ class MailFetcher {
$sender=$headerinfo->from[0]; $sender=$headerinfo->from[0];
//Just what we need... //Just what we need...
$header=array('name' =>@$sender->personal, $header=array('name' => $this->mime_decode(@$sender->personal),
'email' => trim(strtolower($sender->mailbox).'@'.$sender->host), 'email' => trim(strtolower($sender->mailbox).'@'.$sender->host),
'subject'=>@$headerinfo->subject, 'subject'=> $this->mime_decode(@$headerinfo->subject),
'mid' => trim(@$headerinfo->message_id), 'mid' => trim(@$headerinfo->message_id),
'header' => $this->getHeader($mid), 'header' => $this->getHeader($mid),
'in-reply-to' => $headerinfo->in_reply_to, 'in-reply-to' => $headerinfo->in_reply_to,
...@@ -283,22 +283,33 @@ class MailFetcher { ...@@ -283,22 +283,33 @@ class MailFetcher {
$header['reply-to-name'] = $replyto[0]->personal; $header['reply-to-name'] = $replyto[0]->personal;
} }
//Try to determine target email - useful when fetched inbox has // Put together a list of recipients
// aliases that are independent emails within osTicket.
$emailId = 0;
$tolist = array(); $tolist = array();
if($headerinfo->to) if($headerinfo->to)
$tolist = array_merge($tolist, $headerinfo->to); $tolist = array_merge($tolist, $headerinfo->to);
if($headerinfo->cc) if($headerinfo->cc)
$tolist = array_merge($tolist, $headerinfo->cc); $tolist = array_merge($tolist, $headerinfo->cc);
if($headerinfo->bcc)
$tolist = array_merge($tolist, $headerinfo->bcc);
foreach($tolist as $addr) $header['collaborators'] = array();
if(($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) foreach($tolist as $addr) {
break; if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) {
$header['collaborators'][] = array(
'name' => $this->mime_decode(@$addr->personal),
'email' => strtolower($addr->mailbox).'@'.$addr->host);
} elseif(!$header['emailId']) {
$header['emailId'] = $emailId;
}
}
$header['emailId'] = $emailId; //BCCed?
if(!$header['emailId']) {
unset($header['collaborators']); //Nuke the recipients - we were bcced
if($headerinfo->bcc)
foreach($headerinfo->bcc as $addr)
if(!$header['emailId']
&& ($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host)))
$header['emailId'] = $emailId;
}
// Ensure we have a message-id. If unable to read it out of the // Ensure we have a message-id. If unable to read it out of the
// email, use the hash of the entire email headers // email, use the hash of the entire email headers
...@@ -485,18 +496,18 @@ class MailFetcher { ...@@ -485,18 +496,18 @@ class MailFetcher {
} }
$vars = $mailinfo; $vars = $mailinfo;
$vars['name']=$this->mime_decode($mailinfo['name']); $vars['name'] = $mailinfo['name'];
$vars['subject']=$mailinfo['subject']?$this->mime_decode($mailinfo['subject']):'[No Subject]'; $vars['subject'] = $mailinfo['subject'] ? $mailinfo['subject'] : '[No Subject]';
$vars['message']=Format::stripEmptyLines($this->getBody($mid)); $vars['message'] = Format::stripEmptyLines($this->getBody($mid));
$vars['emailId']=$mailinfo['emailId']?$mailinfo['emailId']:$this->getEmailId(); $vars['emailId'] = $mailinfo['emailId'] ? $mailinfo['emailId'] : $this->getEmailId();
//Missing FROM name - use email address. //Missing FROM name - use email address.
if(!$vars['name']) if(!$vars['name'])
$vars['name'] = $vars['email']; list($vars['name']) = explode('@', $vars['email']);
//An email with just attachments can have empty body. //An email with just attachments can have empty body.
if(!$vars['message']) if(!$vars['message'])
$vars['message'] = '-'; $vars['message'] = '--';
if($ost->getConfig()->useEmailPriority()) if($ost->getConfig()->useEmailPriority())
$vars['priorityId']=$this->getPriority($mid); $vars['priorityId']=$this->getPriority($mid);
...@@ -565,6 +576,7 @@ class MailFetcher { ...@@ -565,6 +576,7 @@ class MailFetcher {
return null; return null;
} }
return $ticket; return $ticket;
} }
......
...@@ -154,6 +154,13 @@ class Mail_Parse { ...@@ -154,6 +154,13 @@ class Mail_Parse {
return Mail_Parse::parseAddressList($header); return Mail_Parse::parseAddressList($header);
} }
function getBccAddressList(){
if (!($header = $this->struct->headers['bcc']))
return null;
return Mail_Parse::parseAddressList($header);
}
function getMessageId(){ function getMessageId(){
return $this->struct->headers['message-id']; return $this->struct->headers['message-id'];
} }
...@@ -378,19 +385,35 @@ class EmailDataParser { ...@@ -378,19 +385,35 @@ class EmailDataParser {
} }
//TO Address:Try to figure out the email address... associated with the incoming email. //TO Address:Try to figure out the email address... associated with the incoming email.
$emailId = 0; $data['emailId'] = 0;
if(($tolist = $parser->getToAddressList())) { $data['collaborators'] = array();
foreach ($tolist as $toaddr) { $tolist = array();
if(($emailId=Email::getIdByEmail($toaddr->mailbox.'@'.$toaddr->host))) if(($to = $parser->getToAddressList()))
break; $tolist = array_merge($tolist, $to);
if(($cc = $parser->getCcAddressList()))
$tolist = array_merge($tolist, $cc);
foreach ($tolist as $addr) {
if(!($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) {
$data['collaborators'][] = array(
'name' => trim(@$addr->personal, '"'),
'email' => strtolower($addr->mailbox).'@'.$addr->host);
} elseif(!$data['emailId']) {
$data['emailId'] = $emailId;
} }
} }
//maybe we got CC'ed??
if(!$emailId && ($cclist=$parser->getCcAddressList())) { //maybe we got BCC'ed??
foreach ($cclist as $ccaddr) { if(!$data['emailId']) {
if(($emailId=Email::getIdByEmail($ccaddr->mailbox.'@'.$ccaddr->host))) unset($data['collaborators']);
break; $emailId = 0;
if($bcc = $parser->getBccAddressList())
foreach ($bcc as $addr) {
if(($emailId=Email::getIdByEmail($addr->mailbox.'@'.$addr->host)))
break;
} }
$data['emailId'] = $emailId;
} }
$data['subject'] = $parser->getSubject(); $data['subject'] = $parser->getSubject();
...@@ -398,7 +421,6 @@ class EmailDataParser { ...@@ -398,7 +421,6 @@ class EmailDataParser {
$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['in-reply-to'] = $parser->struct->headers['in-reply-to']; $data['in-reply-to'] = $parser->struct->headers['in-reply-to'];
$data['references'] = $parser->struct->headers['references']; $data['references'] = $parser->struct->headers['references'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment