diff --git a/include/api.tickets.php b/include/api.tickets.php index 00d7628b2e06076938a13df268b0a52fe05dbdc3..feca779c56927422490373136e8feb48d0bbd8d1 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -141,9 +141,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 e7b039211f71b9c8ff8f472503ca75eed20e3924..21797c2313d815ccf5185bfca09d1a59aba7e2f0 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -518,6 +518,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 3356cb9bf1a596272d3e46e9a2cb72dfc0c41ca5..34209b67c52badeb4e982f624f34cea0050848a9 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() { @@ -235,7 +246,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'])) @@ -249,8 +263,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; } }