From 63c84d2fb63f28706c77b1a7e8d4901606734c36 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Sun, 11 Aug 2013 23:16:38 +0000 Subject: [PATCH] Support aliased mail fetching --- include/class.mailfetch.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 53fce8bd3..3dc79e8d5 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -234,6 +234,23 @@ class MailFetcher { 'mid' =>$headerinfo->message_id ); + //Try to determine target email - useful when fetched inbox has + // aliases that are independent emails within osTicket. + $emailId = 0; + $tolist = array(); + if($headerinfo->to) + $tolist = array_merge($tolist, $headerinfo->to); + if($headerinfo->cc) + $tolist = array_merge($tolist, $headerinfo->cc); + if($headerinfo->bcc) + $tolist = array_merge($tolist, $headerinfo->bcc); + + foreach($tolist as $addr) + if(($emailId=Email::getIdByEmail(strtolower($addr->mailbox).'@'.$addr->host))) + break; + + $header['emailId'] = $emailId; + return $header; } @@ -374,14 +391,13 @@ class MailFetcher { return true; //Report success (moved or delete) } - $emailId = $this->getEmailId(); $vars = array(); $vars['email']=$mailinfo['email']; $vars['name']=$this->mime_decode($mailinfo['name']); $vars['subject']=$mailinfo['subject']?$this->mime_decode($mailinfo['subject']):'[No Subject]'; $vars['message']=Format::stripEmptyLines($this->getBody($mid)); $vars['header']=$this->getHeader($mid); - $vars['emailId']=$emailId?$emailId:$ost->getConfig()->getDefaultEmailId(); //ok to default? + $vars['emailId']=$mailinfo['emailId']?$mailinfo['emailId']:$this->getEmailId(); $vars['mid']=$mailinfo['mid']; //Missing FROM name - use email address. -- GitLab