Esempio n. 1
0
 //Ticket lock if any
 $statusKeys = array('open' => 'Open', 'Reopen' => 'Open', 'Close' => 'Closed');
 switch (strtolower($_POST['a'])) {
     case 'reply':
         if (!$_POST['msgId']) {
             $errors['err'] = 'Missing message ID - Internal error';
         }
         if (!$_POST['response']) {
             $errors['response'] = 'Response required';
         }
         //Use locks to avoid double replies
         if ($lock && $lock->getStaffId() != $thisstaff->getId()) {
             $errors['err'] = 'Action Denied. Ticket is locked by someone else!';
         }
         //Make sure the email is not banned
         if (!$errors['err'] && EmailFilter::isBanned($ticket->getEmail())) {
             $errors['err'] = 'Email is in banlist. Must be removed to reply.';
         }
         $wasOpen = $ticket->isOpen();
         //If no error...do the do.
         if (!$errors && ($respId = $ticket->postReply($_POST, $errors))) {
             $msg = 'Reply posted successfully';
             $ticket->reload();
             if ($ticket->isClosed() && $wasOpen) {
                 $ticket = null;
             }
         } elseif (!$errors['err']) {
             $errors['err'] = 'Unable to post the reply. Correct the errors below and try again!';
         }
         break;
     case 'transfer':
Esempio n. 2
0
 function create($vars, &$errors, $origin, $autorespond = true, $alertstaff = true)
 {
     global $cfg, $thisclient, $_FILES;
     //Make sure the email is not banned
     if ($vars['email'] && EmailFilter::isBanned($vars['email'])) {
         $errors['err'] = 'Ticket denied. Error #403';
         Sys::log(LOG_WARNING, 'Ticket denied', 'Banned email - ' . $vars['email']);
         return 0;
     }
     $id = 0;
     $fields = array();
     $fields['name'] = array('type' => 'string', 'required' => 1, 'error' => 'Name required');
     $fields['email'] = array('type' => 'email', 'required' => 1, 'error' => 'Valid email required');
     $fields['subject'] = array('type' => 'string', 'required' => 1, 'error' => 'Subject required');
     $fields['message'] = array('type' => 'text', 'required' => 1, 'error' => 'Message required');
     switch (strtolower($origin)) {
         case 'web':
             $fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Select help topic');
             break;
         case 'staff':
             $fields['deptId'] = array('type' => 'int', 'required' => 1, 'error' => 'Dept. required');
             $fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Topic required');
             $fields['duedate'] = array('type' => 'date', 'required' => 0, 'error' => 'Invalid date - must be MM/DD/YY');
         case 'api':
             $fields['source'] = array('type' => 'string', 'required' => 1, 'error' => 'Indicate source');
             break;
         case 'email':
             $fields['emailId'] = array('type' => 'int', 'required' => 1, 'error' => 'Email unknown');
             break;
         default:
             # TODO: Return error message
             $errors['origin'] = 'Invalid origin given';
     }
     $fields['pri'] = array('type' => 'int', 'required' => 0, 'error' => 'Invalid Priority');
     $fields['phone'] = array('type' => 'phone', 'required' => 0, 'error' => 'Valid phone # required');
     if (!Validator::process($fields, $vars, $errors) && !$errors['err']) {
         $errors['err'] = 'Missing or invalid data - check the errors and try again';
     }
     //Make sure phone extension is valid
     if ($vars['phone_ext']) {
         if (!is_numeric($vars['phone_ext']) && !$errors['phone']) {
             $errors['phone'] = 'Invalid phone ext.';
         } elseif (!$vars['phone']) {
             //make sure they just didn't enter ext without phone # XXX: reconsider allowing!
             $errors['phone'] = 'Phone number required';
         }
     }
     //Make sure the due date is valid
     if ($vars['duedate']) {
         if (!$vars['time'] || strpos($vars['time'], ':') === false) {
             $errors['time'] = 'Select time';
         } elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) === false) {
             $errors['duedate'] = 'Invalid duedate';
         } elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) <= time()) {
             $errors['duedate'] = 'Due date must be in the future';
         }
     }
     //check attachment..if any is set ...only set on webbased tickets..
     //XXX:?? Create ticket anyway and simply drop the attachments?? We're already doing so with emails.
     if ($_FILES['attachment']['name'] && $cfg->allowOnlineAttachments()) {
         if (!$cfg->canUploadFileType($_FILES['attachment']['name'])) {
             $errors['attachment'] = 'Invalid file type [ ' . Format::htmlchars($_FILES['attachment']['name']) . ' ]';
         } elseif ($_FILES['attachment']['size'] > $cfg->getMaxFileSize()) {
             $errors['attachment'] = 'File is too big. Max ' . $cfg->getMaxFileSize() . ' bytes allowed';
         }
     }
     # Perform email filter actions on the new ticket arguments XXX: Move filter to the top and check for reject...
     if (!$errors && ($ef = new EmailFilter($vars))) {
         $ef->apply($vars);
     }
     # Some things will need to be unpacked back into the scope of this
     # function
     if (isset($vars['autorespond'])) {
         $autorespond = $vars['autorespond'];
     }
     //check ticket limits..if limit set is >0
     //TODO: Base ticket limits on SLA... XXX: move it elsewhere??
     if ($vars['email'] && !$errors && $cfg->getMaxOpenTickets() > 0 && strcasecmp($origin, 'staff')) {
         $openTickets = Ticket::getOpenTicketsByEmail($vars['email']);
         if ($openTickets >= $cfg->getMaxOpenTickets()) {
             $errors['err'] = "You've reached the maximum open tickets allowed.";
             //Send the notice only once (when the limit is reached) incase of autoresponders at client end.
             if ($cfg->getMaxOpenTickets() == $openTickets && $cfg->sendOverlimitNotice()) {
                 if ($vars['deptId']) {
                     $dept = Dept::lookup($vars['deptId']);
                 }
                 if (!$dept || !($tpl = $dept->getTemplate())) {
                     $tpl = $cfg->getDefaultTemplate();
                 }
                 if (!$dept || !($email = $dept->getAutoRespEmail())) {
                     $email = $cfg->getDefaultEmail();
                 }
                 if ($tpl && ($msg = $tpl->getOverlimitMsgTemplate()) && $email) {
                     $body = str_replace('%name', $vars['name'], $msg['body']);
                     $body = str_replace('%email', $vars['email'], $msg['body']);
                     $body = str_replace('%url', $cfg->getBaseUrl(), $body);
                     $body = str_replace('%signature', $dept && $dept->isPublic() ? $dept->getSignature() : '', $body);
                     $email->send($vars['email'], $msg['subj'], $body);
                 }
                 //Log + Alert admin...this might be spammy (no option to disable)...but it is helpful..I think.
                 $msg = 'Support ticket request denied for ' . $vars['email'] . "\n" . 'Open ticket:' . $openTickets . "\n" . 'Max Allowed:' . $cfg->getMaxOpenTickets() . "\n\nNotice only sent once";
                 Sys::log(LOG_CRIT, 'Overlimit Notice', $msg);
             }
         }
     }
     //Any error above is fatal.
     if ($errors) {
         return 0;
     }
     // OK...just do it.
     $deptId = $vars['deptId'];
     //pre-selected Dept if any.
     $priorityId = $vars['pri'];
     $source = ucfirst($vars['source']);
     $topic = NULL;
     // Intenal mapping magic...see if we need to overwrite anything
     if (isset($vars['topicId']) && ($topic = Topic::lookup($vars['topicId']))) {
         //Ticket created via web by user/or staff
         $deptId = $deptId ? $deptId : $topic->getDeptId();
         $priorityId = $priorityId ? $priorityId : $topic->getPriorityId();
         if ($autorespond) {
             $autorespond = $topic->autoRespond();
         }
         $source = $vars['source'] ? $vars['source'] : 'Web';
     } elseif ($vars['emailId'] && !$vars['deptId'] && ($email = Email::lookup($vars['emailId']))) {
         //Emailed Tickets
         $deptId = $email->getDeptId();
         $priorityId = $priorityId ? $priorityId : $email->getPriorityId();
         if ($autorespond) {
             $autorespond = $email->autoRespond();
         }
         $email = null;
         $source = 'Email';
     } elseif ($vars['deptId']) {
         //Opened by staff.
         $deptId = $vars['deptId'];
         $source = ucfirst($vars['source']);
     }
     //Last minute checks
     $priorityId = $priorityId ? $priorityId : $cfg->getDefaultPriorityId();
     $deptId = $deptId ? $deptId : $cfg->getDefaultDeptId();
     $topicId = $vars['topicId'] ? $vars['topicId'] : 0;
     $ipaddress = $vars['ip'] ? $vars['ip'] : $_SERVER['REMOTE_ADDR'];
     //We are ready son...hold on to the rails.
     $extId = Ticket::genExtRandID();
     $sql = 'INSERT INTO ' . TICKET_TABLE . ' SET created=NOW() ' . ' ,lastmessage= NOW()' . ' ,ticketID=' . db_input($extId) . ' ,dept_id=' . db_input($deptId) . ' ,topic_id=' . db_input($topicId) . ' ,priority_id=' . db_input($priorityId) . ' ,email=' . db_input($vars['email']) . ' ,name=' . db_input(Format::striptags($vars['name'])) . ' ,subject=' . db_input(Format::striptags($vars['subject'])) . ' ,phone="' . db_input($vars['phone'], false) . '"' . ' ,phone_ext=' . db_input($vars['phone_ext'] ? $vars['phone_ext'] : '') . ' ,ip_address=' . db_input($ipaddress) . ' ,source=' . db_input($source);
     //Make sure the origin is staff - avoid firebug hack!
     if ($vars['duedate'] && !strcasecmp($origin, 'staff')) {
         $sql .= ' ,duedate=' . db_input(date('Y-m-d G:i', Misc::dbtime($vars['duedate'] . ' ' . $vars['time'])));
     }
     if (!db_query($sql) || !($id = db_insert_id()) || !($ticket = Ticket::lookup($id))) {
         return null;
     }
     /* -------------------- POST CREATE ------------------------ */
     $dept = $ticket->getDept();
     if (!$cfg->useRandomIds()) {
         //Sequential ticketIDs support really..really suck arse.
         $extId = $id;
         //To make things really easy we are going to use autoincrement ticket_id.
         db_query('UPDATE ' . TICKET_TABLE . ' SET ticketID=' . db_input($extId) . ' WHERE ticket_id=' . $id . ' LIMIT 1');
         //TODO: RETHING what happens if this fails?? [At the moment on failure random ID is used...making stuff usable]
     }
     //post the message.
     $msgid = $ticket->postMessage($vars['message'], $source, $vars['mid'], $vars['header'], true);
     //TODO: recover from postMessage error??
     //Upload attachments...web based. - XXX: Assumes user uploaded attachments!! XXX: move it to client interface.
     if ($_FILES['attachment']['name'] && $cfg->allowOnlineAttachments() && $msgid) {
         if (!$cfg->allowAttachmentsOnlogin() || $cfg->allowAttachmentsOnlogin() && ($thisuser && $thisuser->isValid())) {
             $ticket->uploadAttachment($_FILES['attachment'], $msgid, 'M');
         }
     }
     // Configure service-level-agreement for this ticket
     $ticket->selectSLAId($vars['slaId']);
     //Auto assign staff or team - auto assignment based on filter rules.
     if ($vars['staffId'] && !$vars['assignId']) {
         $ticket->assignToStaff($vars['staffId'], 'auto-assignment');
     }
     if ($vars['teamId'] && !$vars['assignId']) {
         $ticket->assignToTeam($vars['teamId'], 'auto-assignment');
     }
     /**********   double check auto-response  ************/
     //Overwrite auto responder if the FROM email is one of the internal emails...loop control.
     if ($autorespond && Email::getIdByEmail($ticket->getEmail())) {
         $autorespond = false;
     }
     if ($autorespond && $dept && !$dept->autoRespONNewTicket()) {
         $autorespond = false;
     }
     # Messages that are clearly auto-responses from email systems should
     # not have a return 'ping' message
     if ($autorespond && $vars['header'] && EmailFilter::isAutoResponse(Mail_Parse::splitHeaders($vars['header']))) {
         $autorespond = false;
     }
     //Don't auto respond to mailer daemons.
     if ($autorespond && (strpos(strtolower($vars['email']), 'mailer-daemon@') !== false || strpos(strtolower($vars['email']), 'postmaster@') !== false)) {
         $autorespond = false;
     }
     /***** See if we need to send some alerts ****/
     $ticket->onNewTicket($vars['message'], $autorespond, $alertstaff);
     return $ticket;
 }
Esempio n. 3
0
 function create($vars, &$errors, $origin, $autorespond = true, $alertstaff = true)
 {
     global $cfg, $thisclient, $_FILES;
     //Check for 403
     if ($vars['email'] && Validator::is_email($vars['email'])) {
         //Make sure the email address is not banned
         if (EmailFilter::isBanned($vars['email'])) {
             $errors['err'] = 'Ticket denied. Error #403';
             Sys::log(LOG_WARNING, 'Ticket denied', 'Banned email - ' . $vars['email']);
             return 0;
         }
         //Make sure the open ticket limit hasn't been reached. (LOOP CONTROL)
         if ($cfg->getMaxOpenTickets() > 0 && strcasecmp($origin, 'staff') && ($client = Client::lookupByEmail($vars['email'])) && ($openTickets = $client->getNumOpenTickets()) && $opentickets >= $cfg->getMaxOpenTickets()) {
             $errors['err'] = "You've reached the maximum open tickets allowed.";
             Sys::log(LOG_WARNING, 'Ticket denied -' . $vars['email'], sprintf('Max open tickets (%d) reached for %s ', $cfg->getMaxOpenTickets(), $vars['email']));
             return 0;
         }
     }
     // Make sure email contents should not be rejected
     if (($email_filter = new EmailFilter($vars)) && ($filter = $email_filter->shouldReject())) {
         $errors['err'] = 'Ticket denied. Error #403';
         Sys::log(LOG_WARNING, 'Ticket denied', sprintf('Banned email - %s by filter "%s"', $vars['email'], $filter->getName()));
         return 0;
     }
     $id = 0;
     $fields = array();
     $fields['name'] = array('type' => 'string', 'required' => 1, 'error' => 'Name required');
     $fields['email'] = array('type' => 'email', 'required' => 1, 'error' => 'Valid email required');
     $fields['subject'] = array('type' => 'string', 'required' => 1, 'error' => 'Subject required');
     $fields['message'] = array('type' => 'text', 'required' => 1, 'error' => 'Message required');
     switch (strtolower($origin)) {
         case 'web':
             $fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Select help topic');
             break;
         case 'staff':
             $fields['deptId'] = array('type' => 'int', 'required' => 1, 'error' => 'Dept. required');
             $fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Topic required');
             $fields['duedate'] = array('type' => 'date', 'required' => 0, 'error' => 'Invalid date - must be MM/DD/YY');
         case 'api':
             $fields['source'] = array('type' => 'string', 'required' => 1, 'error' => 'Indicate source');
             break;
         case 'email':
             $fields['emailId'] = array('type' => 'int', 'required' => 1, 'error' => 'Email unknown');
             break;
         default:
             # TODO: Return error message
             $errors['err'] = $errors['origin'] = 'Invalid origin given';
     }
     $fields['priorityId'] = array('type' => 'int', 'required' => 0, 'error' => 'Invalid Priority');
     $fields['phone'] = array('type' => 'phone', 'required' => 0, 'error' => 'Valid phone # required');
     if (!Validator::process($fields, $vars, $errors) && !$errors['err']) {
         $errors['err'] = 'Missing or invalid data - check the errors and try again';
     }
     //Make sure phone extension is valid
     if ($vars['phone_ext']) {
         if (!is_numeric($vars['phone_ext']) && !$errors['phone']) {
             $errors['phone'] = 'Invalid phone ext.';
         } elseif (!$vars['phone']) {
             //make sure they just didn't enter ext without phone # XXX: reconsider allowing!
             $errors['phone'] = 'Phone number required';
         }
     }
     //Make sure the due date is valid
     if ($vars['duedate']) {
         if (!$vars['time'] || strpos($vars['time'], ':') === false) {
             $errors['time'] = 'Select time';
         } elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) === false) {
             $errors['duedate'] = 'Invalid duedate';
         } elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) <= time()) {
             $errors['duedate'] = 'Due date must be in the future';
         }
     }
     # Perform email filter actions on the new ticket arguments XXX: Move filter to the top and check for reject...
     if (!$errors && $email_filter) {
         $email_filter->apply($vars);
     }
     # Some things will need to be unpacked back into the scope of this
     # function
     if (isset($vars['autorespond'])) {
         $autorespond = $vars['autorespond'];
     }
     //Any error above is fatal.
     if ($errors) {
         return 0;
     }
     // OK...just do it.
     $deptId = $vars['deptId'];
     //pre-selected Dept if any.
     $priorityId = $vars['priorityId'];
     $source = ucfirst($vars['source']);
     $topic = NULL;
     // Intenal mapping magic...see if we need to overwrite anything
     if (isset($vars['topicId']) && ($topic = Topic::lookup($vars['topicId']))) {
         //Ticket created via web by user/or staff
         $deptId = $deptId ? $deptId : $topic->getDeptId();
         $priorityId = $priorityId ? $priorityId : $topic->getPriorityId();
         if ($autorespond) {
             $autorespond = $topic->autoRespond();
         }
         $source = $vars['source'] ? $vars['source'] : 'Web';
     } elseif ($vars['emailId'] && !$vars['deptId'] && ($email = Email::lookup($vars['emailId']))) {
         //Emailed Tickets
         $deptId = $email->getDeptId();
         $priorityId = $priorityId ? $priorityId : $email->getPriorityId();
         if ($autorespond) {
             $autorespond = $email->autoRespond();
         }
         $email = null;
         $source = 'Email';
     } elseif ($vars['deptId']) {
         //Opened by staff.
         $deptId = $vars['deptId'];
         $source = ucfirst($vars['source']);
     }
     //Last minute checks
     $priorityId = $priorityId ? $priorityId : $cfg->getDefaultPriorityId();
     $deptId = $deptId ? $deptId : $cfg->getDefaultDeptId();
     $topicId = $vars['topicId'] ? $vars['topicId'] : 0;
     $ipaddress = $vars['ip'] ? $vars['ip'] : $_SERVER['REMOTE_ADDR'];
     //We are ready son...hold on to the rails.
     $extId = Ticket::genExtRandID();
     $sql = 'INSERT INTO ' . TICKET_TABLE . ' SET created=NOW() ' . ' ,lastmessage= NOW()' . ' ,ticketID=' . db_input($extId) . ' ,dept_id=' . db_input($deptId) . ' ,topic_id=' . db_input($topicId) . ' ,priority_id=' . db_input($priorityId) . ' ,email=' . db_input($vars['email']) . ' ,name=' . db_input(Format::striptags($vars['name'])) . ' ,subject=' . db_input(Format::striptags($vars['subject'])) . ' ,phone="' . db_input($vars['phone'], false) . '"' . ' ,phone_ext=' . db_input($vars['phone_ext'] ? $vars['phone_ext'] : '') . ' ,ip_address=' . db_input($ipaddress) . ' ,source=' . db_input($source);
     //Make sure the origin is staff - avoid firebug hack!
     if ($vars['duedate'] && !strcasecmp($origin, 'staff')) {
         $sql .= ' ,duedate=' . db_input(date('Y-m-d G:i', Misc::dbtime($vars['duedate'] . ' ' . $vars['time'])));
     }
     if (!db_query($sql) || !($id = db_insert_id()) || !($ticket = Ticket::lookup($id))) {
         return null;
     }
     /* -------------------- POST CREATE ------------------------ */
     $dept = $ticket->getDept();
     if (!$cfg->useRandomIds()) {
         //Sequential ticketIDs support really..really suck arse.
         $extId = $id;
         //To make things really easy we are going to use autoincrement ticket_id.
         db_query('UPDATE ' . TICKET_TABLE . ' SET ticketID=' . db_input($extId) . ' WHERE ticket_id=' . $id . ' LIMIT 1');
         //TODO: RETHING what happens if this fails?? [At the moment on failure random ID is used...making stuff usable]
     }
     //post the message.
     $msgid = $ticket->postMessage($vars['message'], $source, $vars['mid'], $vars['header'], true);
     // Configure service-level-agreement for this ticket
     $ticket->selectSLAId($vars['slaId']);
     //Auto assign staff or team - auto assignment based on filter rules.
     if ($vars['staffId'] && !$vars['assignId']) {
         $ticket->assignToStaff($vars['staffId'], 'auto-assignment');
     }
     if ($vars['teamId'] && !$vars['assignId']) {
         $ticket->assignToTeam($vars['teamId'], 'auto-assignment');
     }
     /**********   double check auto-response  ************/
     //Overwrite auto responder if the FROM email is one of the internal emails...loop control.
     if ($autorespond && Email::getIdByEmail($ticket->getEmail())) {
         $autorespond = false;
     }
     if ($autorespond && $dept && !$dept->autoRespONNewTicket()) {
         $autorespond = false;
     }
     # Messages that are clearly auto-responses from email systems should
     # not have a return 'ping' message
     if ($autorespond && $vars['header'] && EmailFilter::isAutoResponse(Mail_Parse::splitHeaders($vars['header']))) {
         $autorespond = false;
     }
     //Don't auto respond to mailer daemons.
     if ($autorespond && (strpos(strtolower($vars['email']), 'mailer-daemon@') !== false || strpos(strtolower($vars['email']), 'postmaster@') !== false)) {
         $autorespond = false;
     }
     /***** See if we need to send some alerts ****/
     $ticket->onNewTicket($vars['message'], $autorespond, $alertstaff);
     /************ check if the user JUST reached the max. open tickets limit **********/
     if ($cfg->getMaxOpenTickets() > 0 && ($client = $ticket->getClient()) && $client->getNumOpenTickets() == $cfg->getMaxOpenTickets()) {
         $ticket->onOpenLimit($autorespond && strcasecmp($origin, 'staff'));
     }
     /* Phew! ... time for tea (KETEPA) */
     return $ticket;
 }
 function createTicket($mid)
 {
     global $ost;
     if (!($mailinfo = $this->getHeaderInfo($mid))) {
         return false;
     }
     //Make sure the email is NOT already fetched... (undeleted emails)
     if ($mailinfo['mid'] && ($id = Ticket::getIdByMessageId(trim($mailinfo['mid']), $mailinfo['email']))) {
         return true;
     }
     //Reporting success so the email can be moved or deleted.
     //Is the email address banned?
     if ($mailinfo['email'] && EmailFilter::isBanned($mailinfo['email'])) {
         //We need to let admin know...
         $ost->logWarning('Ticket denied', 'Banned email - ' . $mailinfo['email']);
         return true;
         //Report success (moved or delete)
     }
     $emailId = $this->getEmailId();
     $var['name'] = $this->mime_decode($mailinfo['name']);
     $var['email'] = $mailinfo['email'];
     $var['subject'] = $mailinfo['subject'] ? $this->mime_decode($mailinfo['subject']) : '[No Subject]';
     $var['message'] = Format::stripEmptyLines($this->getBody($mid));
     $var['header'] = $this->getHeader($mid);
     $var['emailId'] = $emailId ? $emailId : $ost->getConfig()->getDefaultEmailId();
     //ok to default?
     $var['name'] = $var['name'] ? $var['name'] : $var['email'];
     //No name? use email
     $var['mid'] = $mailinfo['mid'];
     if (!$var['message']) {
         //An email with just attachments can have empty body.
         $var['message'] = '(EMPTY)';
     }
     if ($ost->getConfig()->useEmailPriority()) {
         $var['priorityId'] = $this->getPriority($mid);
     }
     $ticket = null;
     $newticket = true;
     //Check the subject line for possible ID.
     if ($var['subject'] && preg_match("[[#][0-9]{1,10}]", $var['subject'], $regs)) {
         $tid = trim(preg_replace("/[^0-9]/", "", $regs[0]));
         //Allow mismatched emails?? For now NO.
         if (!($ticket = Ticket::lookupByExtId($tid)) || strcasecmp($ticket->getEmail(), $var['email'])) {
             $ticket = null;
         }
     }
     $errors = array();
     if ($ticket) {
         if (!($msgid = $ticket->postMessage($var['message'], 'Email', $var['mid'], $var['header']))) {
             return false;
         }
     } elseif ($ticket = Ticket::create($var, $errors, 'Email')) {
         $msgid = $ticket->getLastMsgId();
     } else {
         //TODO: Log error..
         return null;
     }
     //Save attachments if any.
     if ($msgid && $ost->getConfig()->allowEmailAttachments() && ($struct = imap_fetchstructure($this->mbox, $mid)) && $struct->parts && ($attachments = $this->getAttachments($struct))) {
         //We're just checking the type of file - not size or number of attachments...
         // Restrictions are mainly due to PHP file uploads limitations
         foreach ($attachments as $a) {
             if ($ost->isFileTypeAllowed($a['name'], $a['mime'])) {
                 $file = array('name' => $a['name'], 'type' => $a['mime'], 'data' => $this->decode($a['encoding'], imap_fetchbody($this->mbox, $mid, $a['index'])));
                 $ticket->saveAttachment($file, $msgid, 'M');
             } else {
                 //This should be really a comment on message - NoT an internal note.
                 //TODO: support comments on Messages and Responses.
                 $error = sprintf('Attachment %s [%s] rejected because of file type', $a['name'], $a['mime']);
                 $ticket->postNote('Email Attachment Rejected', $error, false);
                 $ost->logDebug('Email Attachment Rejected (Ticket #' . $ticket->getExtId() . ')', $error);
             }
         }
     }
     return $ticket;
 }
Esempio n. 5
0
 function isbanned($email)
 {
     return EmailFilter::isBanned($email);
 }
Esempio n. 6
0
 function createTicket($mid, $emailid = 0)
 {
     global $cfg;
     $mailinfo = $this->getHeaderInfo($mid);
     //Make sure the email is NOT one of the undeleted emails.
     if ($mailinfo['mid'] && ($id = Ticket::getIdByMessageId(trim($mailinfo['mid']), $mailinfo['from']['email']))) {
         //TODO: Move emails to a fetched folder when delete is false??
         return true;
     }
     //Is the email address banned?
     if ($mailinfo['from']['email'] && EmailFilter::isBanned($mailinfo['from']['email'])) {
         //We need to let admin know...
         Sys::log(LOG_WARNING, 'Ticket denied', 'Banned email - ' . $mailinfo['from']['email']);
         return true;
     }
     $var['name'] = $this->mime_decode($mailinfo['from']['name']);
     $var['email'] = $mailinfo['from']['email'];
     $var['subject'] = $mailinfo['subject'] ? $this->mime_decode($mailinfo['subject']) : '[No Subject]';
     $var['message'] = Format::stripEmptyLines($this->getBody($mid));
     $var['header'] = $this->getHeader($mid);
     $var['emailId'] = $emailid ? $emailid : $cfg->getDefaultEmailId();
     //ok to default?
     $var['name'] = $var['name'] ? $var['name'] : $var['email'];
     //No name? use email
     $var['mid'] = $mailinfo['mid'];
     if ($cfg->useEmailPriority()) {
         $var['pri'] = $this->getPriority($mid);
     }
     $ticket = null;
     $newticket = true;
     //Check the subject line for possible ID.
     if (preg_match("[[#][0-9]{1,10}]", $var['subject'], $regs)) {
         $extid = trim(preg_replace("/[^0-9]/", "", $regs[0]));
         $ticket = new Ticket(Ticket::getIdByExtId($extid));
         //Allow mismatched emails?? For now NO.
         if (!$ticket || strcasecmp($ticket->getEmail(), $var['email'])) {
             $ticket = null;
         }
     }
     $errors = array();
     if (!$ticket) {
         # Apply email filters for the new ticket
         $ef = new EmailFilter($var);
         $ef->apply($var);
         if (!($ticket = Ticket::create($var, $errors, 'Email')) || $errors) {
             return null;
         }
         $msgid = $ticket->getLastMsgId();
     } else {
         $message = $var['message'];
         //Strip quoted reply...TODO: figure out how mail clients do it without special tag..
         if ($cfg->stripQuotedReply() && ($tag = $cfg->getReplySeparator()) && strpos($var['message'], $tag)) {
             list($message) = split($tag, $var['message']);
         }
         $msgid = $ticket->postMessage($message, 'Email', $var['mid'], $var['header']);
     }
     //Save attachments if any.
     if ($msgid && $cfg->allowEmailAttachments()) {
         if (($struct = imap_fetchstructure($this->mbox, $mid)) && $struct->parts) {
             if ($ticket->getLastMsgId() != $msgid) {
                 $ticket->setLastMsgId($msgid);
             }
             $this->saveAttachments($ticket, $mid, $struct);
         }
     }
     return $ticket;
 }