diff --git a/include/api.tickets.php b/include/api.tickets.php index 4aebd5341ede14d291460400c4352598b24aa4df..55dc5cf1ea6ceccd93a54fb51e7a5467ff7c6991 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -144,9 +144,10 @@ class TicketApiController extends ApiController { return $ticket; } - function processEmail() { + function processEmail($data=false) { - $data = $this->getEmailRequest(); + if (!$data) + $data = $this->getEmailRequest(); if (($thread = ThreadEntry::lookupByEmailHeaders($data)) && $thread->postEmail($data)) { diff --git a/include/class.api.php b/include/class.api.php index 0612fce72ce2f2ef74208e4362a70c88fa943c40..b3e4ea7b349805b8d0489c23dabf0b22b1af7f77 100644 --- a/include/class.api.php +++ b/include/class.api.php @@ -433,7 +433,7 @@ class ApiEmailDataParser extends EmailDataParser { $data['source'] = 'Email'; if(!$data['message']) - $data['message'] = $data['subject']?$data['subject']:'-'; + $data['message'] = '--'; if(!$data['subject']) $data['subject'] = '[No Subject]'; diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index fb4d3dd40d4892fe310e5e53bf1d2c0494d2c297..882cd91a9d1f7cdbdaa0d0795739ed7a3b825e57 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -532,6 +532,23 @@ class MailFetcher { if(!($mailinfo = $this->getHeaderInfo($mid))) return false; + // TODO: If the content-type of the message is 'message/rfc822', + // then this is a message with the forwarded message as the + // attachment. Download the body and pass it along to the mail + // parsing engine. + $info = Mail_Parse::splitHeaders($mailinfo['header']); + if (strtolower($info['Content-Type']) == 'message/rfc822') { + if ($wrapped = $this->getPart($mid, 'message/rfc822')) { + require_once INCLUDE_DIR.'api.tickets.php'; + // Simulate piping the contents into the system + $api = new TicketApiController(); + $parser = new EmailDataParser(); + if ($data = $parser->parse($wrapped)) + return $api->processEmail($data); + } + // If any of this fails, create the ticket as usual + } + //Is the email address banned? if($mailinfo['email'] && TicketFilter::isBanned($mailinfo['email'])) { //We need to let admin know... diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 493603052e75fcf9e916f982428b065b3a43f095..cd66f4e69262442eff83ccf9391051a89acf2d81 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -56,7 +56,18 @@ class Mail_Parse { $this->splitBodyHeader(); $this->struct=Mail_mimeDecode::decode($params); - return (PEAR::isError($this->struct) || !(count($this->struct->headers)>1))?FALSE:TRUE; + if (PEAR::isError($this->struct)) + return false; + + // Handle wrapped emails when forwarded + if ($this->struct && $this->struct->parts) { + $outer = $this->struct; + $ctype = $outer->ctype_primary.'/'.$outer->ctype_secondary; + if (strcasecmp($ctype, 'message/rfc822') === 0) + $this->struct = $outer->parts[0]; + } + + return (count($this->struct->headers) > 1); } function splitBodyHeader() { @@ -246,7 +257,10 @@ class Mail_Parse { if($struct && !$struct->parts) { $ctype = @strtolower($struct->ctype_primary.'/'.$struct->ctype_secondary); - if($ctype && strcasecmp($ctype,$ctypepart)==0) { + if ($struct->disposition + && (strcasecmp($struct->disposition, 'inline') !== 0)) + return ''; + if ($ctype && strcasecmp($ctype,$ctypepart)==0) { $content = $struct->body; //Encode to desired encoding - ONLY if charset is known?? if (isset($struct->ctype_parameters['charset'])) @@ -260,8 +274,7 @@ class Mail_Parse { $data=''; if($struct && $struct->parts && $recurse) { foreach($struct->parts as $i=>$part) { - if($part && !$part->disposition - && ($text=$this->getPart($part,$ctypepart,$recurse - 1))) + if($part && ($text=$this->getPart($part,$ctypepart,$recurse - 1))) $data.=$text; } } diff --git a/include/class.usersession.php b/include/class.usersession.php index 1eae3af81e058246f68d49c11c2660f489ce5d97..4e2440dd57831fe5e8a9f53aac0b190f0d5643ca 100644 --- a/include/class.usersession.php +++ b/include/class.usersession.php @@ -117,6 +117,7 @@ class ClientSession extends EndUser { function __construct($user) { parent::__construct($user); + // XXX: Change the key to user-id $this->session= new UserSession($user->getUserName()); }