* @license PHP License * @package Wombat * @subpackage MailMime */ WBClass::load('WBMail_Mime_Processor'); /** * Wombat Mail Mime Processor: ITS * * Ticket system controlled by e-mail * * @version 0.1.0 * @package Wombat * @subpackage MailMime */ class WBMail_Mime_Processor_ITS extends WBMail_Mime_Processor { /** * Ticket * @var WBITS_Ticket */ private $ticket; /** * @var WBVFS_File */ private $vFile; /** * @var WBFile */ private $file; /** * Command pattern * * @param array $params * @return int 0 on success */ public function execute($params) { if (empty($params)) { $params = array('create'); } $action = strtolower(array_shift($params)); $this->explodeParams($params); $this->ticket = WBClass::create('WBITS_Ticket'); switch ($action) { case 'create': default: $this->createTicket(); break; } return 0; } /** * Create ITS ticket from e-mail * */ private function createTicket() { $this->checkMailData(); $save = array( 'title' => trim($this->mail->getSubject()), 'blurb' => htmlspecialchars(trim($this->mail->getPlainBody())), 'customeremailurlid' => 0, 'customername' => '' ); $save['blurb'] = '
' . $save['blurb'] . '
'; $save['blurb'] = nl2br($save['blurb'], true); // e-mail $from = $this->mail->getFrom(); $save['customername'] = $from->getForename() . ' ' . $from->getSurname(); $dict = WBClass::create('WBDictionary_URL'); $dict->addWord($from->getEmailAddress()); $save['customeremailurlid'] = $dict->getId(); $attCnt = 0; // tell wheather to add attachments if (isset($this->params['attachment']) && 0 < intval($this->params['attachment'])) { $attCnt = $this->mail->countAttachments(); } $media = array(); if (0 < $attCnt) { $this->vFile = WBClass::create('WBVFS_File'); $this->file = WBClass::create('WBFile'); for ($i = 0; $i < $attCnt; ++$i) { $att = $this->mail->getAttachment($i); $this->file->tempnam('its'); file_put_contents($this->file->realpath(), $att->getData()); $this->vFile->setCurrentDir($this->params['attachment'], true); $tmp = $this->vFile->import($this->file->realpath(), $att->getName()); $media[] = $tmp->getId(); if ($this->file->exists()) { $this->file->unlink(); } } } if (0 < count($media)) { $save['ticketmedia'] = $media; } $this->ticket->save($save); $this->subject->inform($this->ticket->getObscureId()); } /** * Verify sufficient e-mail * * @throws WBException_Datasource */ private function checkMailData() { $sub = $this->mail->getSubject(); if (empty($sub)) { $e = array( 'msg' => 'E-mail subject is empty!', 'code' => 1, 'class' => __CLASS__ ); throw WBClass::create('WBException_Datasource', $e); } $plain = $this->mail->getPlainBody(); if (empty($plain)) { $e = array( 'msg' => 'E-mail ('. $sub .') body is empty!', 'code' => 2, 'class' => __CLASS__ ); throw WBClass::create('WBException_Datasource', $e); } } }