function doRegisterAction() { @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $settings = CerberusSettings::getInstance(); $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, null); $from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, "Support Dept."); $url = DevblocksPlatform::getUrlService(); $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $code = CerberusApplication::generatePassword(8); if (!empty($email) && null != ($addy = DAO_Address::lookupAddress($email, true))) { // Already registered? if ($addy->is_registered) { $tpl->assign('register_error', sprintf("'%s' is already registered.", $email)); DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register'))); return; } $fields = array(DAO_Address::IS_REGISTERED => 0, DAO_Address::PASS => $code); DAO_Address::update($addy->id, $fields); } else { $tpl->assign('register_error', sprintf("'%s' is an invalid e-mail address.", $email)); DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register'))); return; } $message = $mail_service->createMessage(); $message->setTo($email); $message->setFrom(array($from => $from_personal)); $message->setSubject("Confirming your support e-mail address"); $message->setBody(sprintf("This is a message to confirm your recent registration request at:\r\n" . "%s\r\n" . "\r\n" . "Your confirmation code is: %s\r\n" . "\r\n" . "If you've closed the browser window, you can continue by visiting:\r\n" . "%s\r\n" . "\r\n" . "Thanks!\r\n" . "%s\r\n", $url->write('', true), $code, $url->write('c=register&a=confirm', true), $from_personal)); $headers = $message->getHeaders(); $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $result = $mailer->send($message); DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'register', 'confirm'))); }
/** * Enter description here... * * @param CerberusParserMessage $message * @return integer */ public static function parseMessage(CerberusParserMessage $message, $options = array()) { /* * options: * 'no_autoreply' */ $logger = DevblocksPlatform::getConsoleLog(); $settings = DevblocksPlatform::getPluginSettingsService(); $helpdesk_senders = CerberusApplication::getHelpdeskSenders(); // Pre-parse mail filters $pre_filters = Model_PreParseRule::getMatches($message); if (is_array($pre_filters) && !empty($pre_filters)) { // Load filter action manifests for reuse $ext_action_mfts = DevblocksPlatform::getExtensions('cerberusweb.mail_filter.action', false); // Loop through all matching filters foreach ($pre_filters as $pre_filter) { // Do something with matching filter's actions foreach ($pre_filter->actions as $action_key => $action) { switch ($action_key) { case 'blackhole': return NULL; break; case 'redirect': @($to = $action['to']); CerberusMail::reflect($message, $to); return NULL; break; case 'bounce': @($msg = $action['message']); @($subject = 'Delivery failed: ' . self::fixQuotePrintableString($message->headers['subject'])); // [TODO] Follow the RFC spec on a true bounce if (null != ($fromAddressInst = CerberusParser::getAddressFromHeaders($message->headers))) { CerberusMail::quickSend($fromAddressInst->email, $subject, $msg); } return NULL; break; default: // Plugin pre-parser filter actions if (isset($ext_action_mfts[$action_key])) { if (null != @($ext_action = $ext_action_mfts[$action_key]->createInstance())) { try { /* @var $ext_action Extension_MailFilterAction */ $ext_action->run($pre_filter, $message); } catch (Exception $e) { } } } break; } } } } $headers =& $message->headers; // From if (null == ($fromAddressInst = CerberusParser::getAddressFromHeaders($headers))) { $logger->err("[Parser] 'From' address could not be created."); return NULL; } // To/Cc/Bcc $to = array(); $sTo = @$headers['to']; $bIsNew = true; if (!empty($sTo)) { // [TODO] Do we still need this RFC address parser? $to = CerberusParser::parseRfcAddress($sTo); } // Subject // Fix quote printable subject (quoted blocks can appear anywhere in subject) $sSubject = ""; if (isset($headers['subject']) && !empty($headers['subject'])) { $sSubject = $headers['subject']; if (is_array($sSubject)) { $sSubject = array_shift($sSubject); } } // The subject can still end up empty after QP decode if (empty($sSubject)) { $sSubject = "(no subject)"; } // Date $iDate = @strtotime($headers['date']); // If blank, or in the future, set to the current date if (empty($iDate) || $iDate > time()) { $iDate = time(); } // Is banned? if (1 == $fromAddressInst->is_banned) { $logger->info("[Parser] Ignoring ticket from banned address: " . $fromAddressInst->email); return NULL; } // Overloadable $enumSpamTraining = ''; // Message Id / References / In-Reply-To @($sMessageId = $headers['message-id']); $body_append_text = array(); $body_append_html = array(); // [mdf]Check attached files before creating the ticket because we may need to overwrite the message-id // also store any contents of rfc822 files so we can include them after the body foreach ($message->files as $filename => $file) { /* @var $file ParserFile */ switch ($file->mime_type) { case 'message/rfc822': $full_filename = $file->tmpname; $mail = mailparse_msg_parse_file($full_filename); $struct = mailparse_msg_get_structure($mail); $msginfo = mailparse_msg_get_part_data($mail); $inline_headers = $msginfo['headers']; if (isset($headers['from']) && (strtolower(substr($headers['from'], 0, 11)) == 'postmaster@' || strtolower(substr($headers['from'], 0, 14)) == 'mailer-daemon@')) { $headers['in-reply-to'] = $inline_headers['message-id']; } break; } } // [JAS] [TODO] References header may contain multiple message-ids to find if (null != ($ids = self::findParentMessage($headers))) { $bIsNew = false; $id = $ids['ticket_id']; $msgid = $ids['message_id']; // Is it a worker reply from an external client? If so, proxy if (null != ($worker_address = DAO_AddressToWorker::getByAddress($fromAddressInst->email))) { $logger->info("[Parser] Handling an external worker response from " . $fromAddressInst->email); if (!DAO_Ticket::isTicketRequester($worker_address->address, $id)) { // Watcher Commands [TODO] Document on wiki/etc if (0 != ($matches = preg_match_all("/\\[(.*?)\\]/i", $message->headers['subject'], $commands))) { @($command = strtolower(array_pop($commands[1]))); $logger->info("[Parser] Worker command: " . $command); switch ($command) { case 'close': DAO_Ticket::updateTicket($id, array(DAO_Ticket::IS_CLOSED => CerberusTicketStatus::CLOSED)); break; case 'take': DAO_Ticket::updateTicket($id, array(DAO_Ticket::NEXT_WORKER_ID => $worker_address->worker_id)); break; case 'comment': $comment_id = DAO_TicketComment::create(array(DAO_TicketComment::ADDRESS_ID => $fromAddressInst->id, DAO_TicketComment::CREATED => time(), DAO_TicketComment::TICKET_ID => $id, DAO_TicketComment::COMMENT => $message->body)); return $id; break; default: // Typo? break; } } $attachment_files = array(); $attachment_files['name'] = array(); $attachment_files['type'] = array(); $attachment_files['tmp_name'] = array(); $attachment_files['size'] = array(); $i = 0; foreach ($message->files as $filename => $file) { $attachment_files['name'][$i] = $filename; $attachment_files['type'][$i] = $file->mime_type; $attachment_files['tmp_name'][$i] = $file->tmpname; $attachment_files['size'][$i] = $file->file_size; $i++; } CerberusMail::sendTicketMessage(array('message_id' => $msgid, 'content' => $message->body, 'files' => $attachment_files, 'agent_id' => $worker_address->worker_id)); return $id; } else { // ... worker is a requester, treat as normal $logger->info("[Parser] The external worker was a ticket requester, so we're not treating them as a watcher."); } } else { // Reply: Not sent by a worker /* * [TODO] check that this sender is a requester on the matched ticket * Otherwise blank out the $id */ } } $group_id = 0; if (empty($id)) { // New Ticket $sMask = CerberusApplication::generateTicketMask(); $groups = DAO_Group::getAll(); // Routing new tickets if (null != ($routing_rules = Model_MailToGroupRule::getMatches($fromAddressInst, $message))) { if (is_array($routing_rules)) { foreach ($routing_rules as $rule) { // Only end up with the last 'move' action (ignore the previous) if (isset($rule->actions['move'])) { $group_id = intval($rule->actions['move']['group_id']); // We don't need to move again when running rule actions unset($rule->actions['move']); } } } } // Make sure the group exists if (!isset($groups[$group_id])) { $group_id = null; } // Last ditch effort to check for a default group to deliver to if (empty($group_id)) { if (null != ($default_team = DAO_Group::getDefaultGroup())) { $group_id = $default_team->id; } else { // Bounce return null; } } // [JAS] It's important to not set the group_id on the ticket until the messages exist // or inbox filters will just abort. $fields = array(DAO_Ticket::MASK => $sMask, DAO_Ticket::SUBJECT => $sSubject, DAO_Ticket::IS_CLOSED => 0, DAO_Ticket::FIRST_WROTE_ID => intval($fromAddressInst->id), DAO_Ticket::LAST_WROTE_ID => intval($fromAddressInst->id), DAO_Ticket::CREATED_DATE => $iDate, DAO_Ticket::UPDATED_DATE => $iDate, DAO_Ticket::LAST_ACTION_CODE => CerberusTicketActionCode::TICKET_OPENED); $id = DAO_Ticket::createTicket($fields); // Apply routing actions to our new ticket ID if (isset($routing_rules) && is_array($routing_rules)) { foreach ($routing_rules as $rule) { $rule->run($id); } } } // [JAS]: Add requesters to the ticket if (!empty($fromAddressInst->id) && !empty($id)) { // Don't add a requester if the sender is a helpdesk address if (isset($helpdesk_senders[$fromAddressInst->email])) { $logger->info("[Parser] Not adding ourselves as a requester: " . $fromAddressInst->email); } else { DAO_Ticket::createRequester($fromAddressInst->id, $id); } } // Add the other TO/CC addresses to the ticket // [TODO] This should be cleaned up and optimized if ($settings->get('cerberusweb.core', CerberusSettings::PARSER_AUTO_REQ, 0)) { @($autoreq_exclude_list = $settings->get('cerberusweb.core', CerberusSettings::PARSER_AUTO_REQ_EXCLUDE, '')); $destinations = self::getDestinations($headers); if (is_array($destinations) && !empty($destinations)) { // Filter out any excluded requesters if (!empty($autoreq_exclude_list)) { @($autoreq_exclude = DevblocksPlatform::parseCrlfString($autoreq_exclude_list)); if (is_array($autoreq_exclude) && !empty($autoreq_exclude)) { foreach ($autoreq_exclude as $excl_pattern) { $excl_regexp = DevblocksPlatform::parseStringAsRegExp($excl_pattern); // Check all destinations for this pattern foreach ($destinations as $idx => $dest) { if (@preg_match($excl_regexp, $dest)) { unset($destinations[$idx]); } } } } } foreach ($destinations as $dest) { if (null != ($destInst = CerberusApplication::hashLookupAddress($dest, true))) { // Skip if the destination is one of our senders or the matching TO if (isset($helpdesk_senders[$destInst->email])) { continue; } DAO_Ticket::createRequester($destInst->id, $id); } } } } $attachment_path = APP_STORAGE_PATH . '/attachments/'; // [TODO] This should allow external attachments (S3) $fields = array(DAO_Message::TICKET_ID => $id, DAO_Message::CREATED_DATE => $iDate, DAO_Message::ADDRESS_ID => $fromAddressInst->id); $email_id = DAO_Message::create($fields); // Content DAO_MessageContent::create($email_id, $message->body); // Headers foreach ($headers as $hk => $hv) { DAO_MessageHeader::create($email_id, $hk, $hv); } // [mdf] Loop through files to insert attachment records in the db, and move temporary files if (!empty($email_id)) { foreach ($message->files as $filename => $file) { /* @var $file ParserFile */ //[mdf] skip rfc822 messages since we extracted their content above if ($file->mime_type == 'message/rfc822') { continue; } $fields = array(DAO_Attachment::MESSAGE_ID => $email_id, DAO_Attachment::DISPLAY_NAME => $filename, DAO_Attachment::MIME_TYPE => $file->mime_type, DAO_Attachment::FILE_SIZE => intval($file->file_size)); $file_id = DAO_Attachment::create($fields); if (empty($file_id)) { @unlink($file->tmpname); // remove our temp file continue; } // Make file attachments use buckets so we have a max per directory $attachment_bucket = sprintf("%03d/", mt_rand(1, 100)); $attachment_file = $file_id; if (!file_exists($attachment_path . $attachment_bucket)) { @mkdir($attachment_path . $attachment_bucket, 0770, true); // [TODO] Needs error checking } rename($file->getTempFile(), $attachment_path . $attachment_bucket . $attachment_file); // [TODO] Split off attachments into its own DAO DAO_Attachment::update($file_id, array(DAO_Attachment::FILEPATH => $attachment_bucket . $attachment_file)); } } // Pre-load custom fields if (isset($message->custom_fields) && !empty($message->custom_fields)) { foreach ($message->custom_fields as $cf_id => $cf_val) { if (is_array($cf_val) && !empty($cf_val) || !is_array($cf_val) && 0 != strlen($cf_val)) { DAO_CustomFieldValue::setFieldValue('cerberusweb.fields.source.ticket', $id, $cf_id, $cf_val); } } } // Finalize our new ticket details (post-message creation) if ($bIsNew && !empty($id) && !empty($email_id)) { // First thread (needed for anti-spam) DAO_Ticket::updateTicket($id, array(DAO_Ticket::FIRST_MESSAGE_ID => $email_id)); // Prime the change fields (which a few things like anti-spam might change before we commit) $change_fields = array(DAO_Ticket::TEAM_ID => $group_id); $out = CerberusBayes::calculateTicketSpamProbability($id); if (!empty($group_id)) { @($spam_threshold = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_THRESHOLD, 80)); @($spam_action = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_ACTION, '')); @($spam_action_param = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_ACTION_PARAM, '')); if ($out['probability'] * 100 >= $spam_threshold) { $enumSpamTraining = CerberusTicketSpamTraining::SPAM; switch ($spam_action) { default: case 0: // do nothing break; case 1: // delete $change_fields[DAO_Ticket::IS_CLOSED] = 1; $change_fields[DAO_Ticket::IS_DELETED] = 1; break; case 2: // move $buckets = DAO_Bucket::getAll(); // Verify bucket exists if (!empty($spam_action_param) && isset($buckets[$spam_action_param])) { $change_fields[DAO_Ticket::TEAM_ID] = $group_id; $change_fields[DAO_Ticket::CATEGORY_ID] = $spam_action_param; } break; } } } // end spam training // Save properties if (!empty($change_fields)) { DAO_Ticket::updateTicket($id, $change_fields); } } // Reply notifications (new messages are handled by 'move' listener) if (!$bIsNew) { // Inbound Reply Event $eventMgr = DevblocksPlatform::getEventService(); $eventMgr->trigger(new Model_DevblocksEvent('ticket.reply.inbound', array('ticket_id' => $id))); } // New ticket processing if ($bIsNew) { // Auto reply @($autoreply_enabled = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_AUTO_REPLY_ENABLED, 0)); @($autoreply = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_AUTO_REPLY, '')); /* * Send the group's autoreply if one exists, as long as this ticket isn't spam */ if (!isset($options['no_autoreply']) && $autoreply_enabled && !empty($autoreply) && $enumSpamTraining != CerberusTicketSpamTraining::SPAM) { CerberusMail::sendTicketMessage(array('ticket_id' => $id, 'message_id' => $email_id, 'content' => str_replace(array('#ticket_id#', '#mask#', '#subject#', '#timestamp#', '#sender#', '#sender_first#', '#orig_body#'), array($id, $sMask, $sSubject, date('r'), $fromAddressInst->email, $fromAddressInst->first_name, ltrim($message->body)), $autoreply), 'is_autoreply' => true, 'dont_keep_copy' => true)); } } // end bIsNew unset($message); // Re-open and update our date on new replies if (!$bIsNew) { DAO_Ticket::updateTicket($id, array(DAO_Ticket::UPDATED_DATE => time(), DAO_Ticket::IS_WAITING => 0, DAO_Ticket::IS_CLOSED => 0, DAO_Ticket::IS_DELETED => 0, DAO_Ticket::LAST_WROTE_ID => $fromAddressInst->id, DAO_Ticket::LAST_ACTION_CODE => CerberusTicketActionCode::TICKET_CUSTOMER_REPLY)); // [TODO] The TICKET_CUSTOMER_REPLY should be sure of this message address not being a worker } @imap_errors(); // Prevent errors from spilling out into STDOUT return $id; }
function doRecoverStep1Action() { $translate = DevblocksPlatform::getTranslationService(); @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string')); $worker = DAO_Worker::lookupAgentEmail($email); if (empty($email) || empty($worker)) { return; } $_SESSION[self::KEY_FORGOT_EMAIL] = $email; try { $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $mail = $mail_service->createMessage(); $code = CerberusApplication::generatePassword(10); $_SESSION[self::KEY_FORGOT_SENTCODE] = $code; $settings = CerberusSettings::getInstance(); $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM); $personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL); // Headers $mail->setTo(array($email)); $mail->setFrom(array($from => $personal)); $mail->setSubject($translate->_('signin.forgot.mail.subject')); $mail->generateId(); $headers = $mail->getHeaders(); $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $mail->setBody(vsprintf($translate->_('signin.forgot.mail.body'), $code)); if (!$mailer->send($mail)) { throw new Exception('Password Forgot confirmation email failed to send.'); } } catch (Exception $e) { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login', 'forgot', 'step1', 'failed'))); } DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login', 'forgot', 'step2'))); }
function replyAction() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0)); @($message_id = DevblocksPlatform::importGPC($_REQUEST['message_id'], 'integer')); @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'content')); @($to = DevblocksPlatform::importGPC($_REQUEST['to'], 'string')); // used by forward @($page_type = DevblocksPlatform::importGPC($_REQUEST['page_type'], 'string')); $worker = CerberusApplication::getActiveWorker(); if ($page_type == 'comment') { $properties = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => @$worker->id, DAO_MessageNote::CONTENT => $content); $note_id = DAO_MessageNote::create($properties); } else { $properties = array('message_id' => $message_id, 'content' => $content, 'agent_id' => @$worker->id, 'to' => $to); CerberusMail::sendTicketMessage($properties); } DevblocksPlatform::redirect(new DevblocksHttpResponse(array('mobile', 'display', $ticket_id))); }
function sendReplyAction() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer')); $worker = CerberusApplication::getActiveWorker(); $properties = array('message_id' => DevblocksPlatform::importGPC(@$_REQUEST['id']), 'ticket_id' => $ticket_id, 'to' => DevblocksPlatform::importGPC(@$_REQUEST['to']), 'cc' => DevblocksPlatform::importGPC(@$_REQUEST['cc']), 'bcc' => DevblocksPlatform::importGPC(@$_REQUEST['bcc']), 'subject' => DevblocksPlatform::importGPC(@$_REQUEST['subject'], 'string'), 'content' => DevblocksPlatform::importGPC(@$_REQUEST['content']), 'files' => @$_FILES['attachment'], 'next_worker_id' => DevblocksPlatform::importGPC(@$_REQUEST['next_worker_id'], 'integer', 0), 'closed' => DevblocksPlatform::importGPC(@$_REQUEST['closed'], 'integer', 0), 'bucket_id' => DevblocksPlatform::importGPC(@$_REQUEST['bucket_id'], 'string', ''), 'ticket_reopen' => DevblocksPlatform::importGPC(@$_REQUEST['ticket_reopen'], 'string', ''), 'unlock_date' => DevblocksPlatform::importGPC(@$_REQUEST['unlock_date'], 'string', ''), 'agent_id' => @$worker->id, 'forward_files' => DevblocksPlatform::importGPC(@$_REQUEST['forward_files'], 'array', array())); CerberusMail::sendTicketMessage($properties); DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('display', $ticket_id))); }
private function _handleTicketClosed($event) { @($ticket_ids = $event->params['ticket_ids']); @($changed_fields = $event->params['changed_fields']); // for anything other than setting is_closed = 1, we don't need to do anything // also don't send if the ticket is being deleted if (!isset($changed_fields[DAO_Ticket::IS_CLOSED]) || 1 != $changed_fields[DAO_Ticket::IS_CLOSED] || isset($changed_fields[DAO_Ticket::IS_DELETED]) && 1 == $changed_fields[DAO_Ticket::IS_DELETED]) { return; } $group_settings = DAO_GroupSettings::getSettings(); if (!empty($ticket_ids)) { $tickets = DAO_Ticket::getTickets($ticket_ids); foreach ($tickets as $ticket) { /* @var $ticket CerberusTicket */ if (!isset($group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY_ENABLED])) { continue; } if (1 == $ticket->is_deleted) { continue; } if ($group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY_ENABLED] && !empty($group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY])) { if (null != ($msg_first = DAO_Ticket::getMessage($ticket->first_message_id))) { // First sender $ticket_sender = ''; $ticket_sender_first = ''; if (null != ($sender_first = DAO_Address::get($msg_first->address_id))) { $ticket_sender = $sender_first->email; $ticket_sender_first = $sender_first->first_name; } // First body $ticket_body = $msg_first->getContent(); } CerberusMail::sendTicketMessage(array('ticket_id' => $ticket->id, 'message_id' => $ticket->first_message_id, 'content' => str_replace(array('#ticket_id#', '#mask#', '#subject#', '#timestamp#', '#sender#', '#sender_first#', '#orig_body#'), array($ticket->id, $ticket->mask, $ticket->subject, date('r'), $ticket_sender, $ticket_sender_first, ltrim($ticket_body)), $group_settings[$ticket->team_id][DAO_GroupSettings::SETTING_CLOSE_REPLY]), 'is_autoreply' => false, 'dont_keep_copy' => true)); } } } }
private function _sendConfirmation($email, $link) { $settings = CerberusSettings::getInstance(); $from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM); $from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL); $url = DevblocksPlatform::getUrlService(); try { $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $code = CerberusApplication::generatePassword(8); if (!empty($email) && null != ($addy = DAO_Address::lookupAddress($email, false))) { $fields = array(DAO_AddressAuth::CONFIRM => $code); DAO_AddressAuth::update($addy->id, $fields); } else { return; } $message = $mail_service->createMessage(); $message->setTo($email); $send_from = new Swift_Address($from, $from_personal); $message->setFrom($send_from); $message->setSubject("Account Confirmation Code"); $message->setBody(sprintf("Below is your confirmation code. Please copy and paste it into the confirmation form at:\r\n" . "%s\r\n" . "\r\n" . "Your confirmation code is: %s\r\n" . "\r\n" . "Thanks!\r\n", $link, $code)); $message->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $mailer->send($message, $email, $send_from); } catch (Exception $e) { return; } }
private function _sendForwards($event, $is_inbound) { @($ticket_id = $event->params['ticket_id']); @($message_id = $event->params['message_id']); @($send_worker_id = $event->params['worker_id']); $ticket = DAO_Ticket::getTicket($ticket_id); $helpdesk_senders = CerberusApplication::getHelpdeskSenders(); $workers = DAO_Worker::getAllActive(); // [JAS]: Don't send obvious spam to watchers. if ($ticket->spam_score >= 0.9) { return true; } @($notifications = DAO_WorkerMailForward::getWhere(sprintf("%s = %d", DAO_WorkerMailForward::GROUP_ID, $ticket->team_id))); // Bail out early if we have no forwards for this group if (empty($notifications)) { return; } $message = DAO_Ticket::getMessage($message_id); $headers = $message->getHeaders(); // The whole flipping Swift section needs wrapped to catch exceptions try { $settings = CerberusSettings::getInstance(); $reply_to = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, ''); // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, '')); if (!empty($group_from)) { $reply_to = $group_from; } } $sender = DAO_Address::get($message->address_id); $sender_email = strtolower($sender->email); $sender_split = explode('@', $sender_email); if (!is_array($sender_split) || count($sender_split) != 2) { return; } // If return-path is blank if (isset($headers['return-path']) && $headers['return-path'] == '<>') { return; } // Ignore bounces if ($sender_split[1] == "postmaster" || $sender_split[1] == "mailer-daemon") { return; } // Ignore autoresponses autoresponses if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') { return; } // Headers //========== // Build mailing list $send_to = array(); foreach ($notifications as $n) { /* @var $n Model_WorkerMailForward */ if (!isset($n->group_id) || !isset($n->bucket_id)) { continue; } // if worker no longer exists or is disabled if (!isset($workers[$n->worker_id])) { continue; } // Don't allow a worker to usurp a helpdesk address if (isset($helpdesk_senders[$n->email])) { continue; } if ($n->group_id == $ticket->team_id && ($n->bucket_id == -1 || $n->bucket_id == $ticket->category_id)) { // Event checking if ($is_inbound && ($n->event == 'i' || $n->event == 'io') || !$is_inbound && ($n->event == 'o' || $n->event == 'io') || $is_inbound && $n->event == 'r' && $ticket->next_worker_id == $n->worker_id) { $send_to[$n->email] = true; } } } // Attachments $attachments = $message->getAttachments(); $mime_attachments = array(); if (is_array($attachments)) { foreach ($attachments as $attachment) { if (0 == strcasecmp($attachment->display_name, 'original_message.html')) { continue; } $attachment_path = APP_STORAGE_PATH . '/attachments/'; // [TODO] This is highly redundant in the codebase if (!file_exists($attachment_path . $attachment->filepath)) { continue; } $file =& new Swift_File($attachment_path . $attachment->filepath); $mime_attachments[] =& new Swift_Message_Attachment($file, $attachment->display_name, $attachment->mime_type); } } // Send copies if (is_array($send_to) && !empty($send_to)) { $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); foreach ($send_to as $to => $bool) { // Proxy the message $rcpt_to = new Swift_RecipientList(); $a_rcpt_to = array(); $mail_from = new Swift_Address($sender->email); $rcpt_to->addTo($to); $a_rcpt_to = new Swift_Address($to); $mail = $mail_service->createMessage(); /* @var $mail Swift_Message */ $mail->setTo($a_rcpt_to); $mail->setFrom($mail_from); $mail->setReplyTo($reply_to); $mail->setReturnPath($reply_to); $mail->setSubject(sprintf("[%s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject)); if (false !== @($msgid = $headers['message-id'])) { $mail->headers->set('Message-Id', $msgid); } if (false !== @($in_reply_to = $headers['in-reply-to'])) { $mail->headers->set('References', $in_reply_to); $mail->headers->set('In-Reply-To', $in_reply_to); } $mail->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $mail->headers->set('Precedence', 'List'); $mail->headers->set('Auto-Submitted', 'auto-generated'); $mail->attach(new Swift_Message_Part($message->getContent(), 'text/plain', 'base64', LANG_CHARSET_CODE)); // Send message attachments with watcher if (is_array($mime_attachments)) { foreach ($mime_attachments as $mime_attachment) { $mail->attach($mime_attachment); } } $mailer->send($mail, $rcpt_to, $mail_from); } } } catch (Exception $e) { $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR); DAO_MessageNote::create($fields); } }
@($contact_phone = stripslashes($_REQUEST['contact_phone'])); @($contact_refer = stripslashes($_REQUEST['contact_refer'])); @($q1 = stripslashes($_REQUEST['q1'])); @($q2 = stripslashes($_REQUEST['q2'])); @($q3 = stripslashes($_REQUEST['q3'])); @($q4 = stripslashes($_REQUEST['q4'])); @($q5_support = stripslashes($_REQUEST['q5_support'])); @($q5_opensource = stripslashes($_REQUEST['q5_opensource'])); @($q5_price = stripslashes($_REQUEST['q5_price'])); @($q5_updates = stripslashes($_REQUEST['q5_updates'])); @($q5_developers = stripslashes($_REQUEST['q5_developers'])); @($q5_community = stripslashes($_REQUEST['q5_community'])); @($comments = stripslashes($_REQUEST['comments'])); if (isset($_REQUEST['form_submit'])) { $msg = sprintf("Contact Name: %s\r\n" . "Organization: %s\r\n" . "Referred by: %s\r\n" . "Phone: %s\r\n" . "\r\n" . "#1: Briefly, what does your organization do?\r\n%s\r\n\r\n" . "#2: How is your team currently handling e-mail management?\r\n%s\r\n\r\n" . "#3: Are you considering both free and commercial solutions?\r\n%s\r\n\r\n" . "#4: What will be your first important milestone?\r\n%s\r\n\r\n" . "#5: How important are the following benefits in making your decision?\r\n" . "Near-Instant Support: %d\r\nAvailable Source Code: %d\r\nCompetitive Purchase Price: %d\r\n" . "Frequent Product Updates: %d\r\nAccess to Developers: %d\r\nLarge User Community: %d\r\n" . "\r\n" . "Additional Comments: \r\n%s\r\n\r\n", $contact_name, $contact_company, $contact_refer, $contact_phone, $q1, $q2, $q3, $q4, $q5_support, $q5_opensource, $q5_price, $q5_updates, $q5_developers, $q5_community, $comments); CerberusMail::quickSend('*****@*****.**', "About: {$contact_name} of {$contact_company}", $msg, $contact_email, $contact_name); } } $tpl->assign('step', STEP_FINISHED); $tpl->display('steps/redirect.tpl'); exit; } $tpl->assign('template', 'steps/step_register.tpl'); break; case STEP_UPGRADE: $tpl->assign('template', 'steps/step_upgrade.tpl'); break; // [TODO] Delete the /install/ directory (security) // [TODO] Delete the /install/ directory (security) case STEP_FINISHED: // Set up the default cron jobs
function logTicketAction() { $active_worker = CerberusApplication::getActiveWorker(); if (!$active_worker->hasPriv('core.mail.log_ticket')) { return; } @($to = DevblocksPlatform::importGPC($_POST['to'], 'string')); @($reqs = DevblocksPlatform::importGPC($_POST['reqs'], 'string')); @($subject = DevblocksPlatform::importGPC($_POST['subject'], 'string')); @($content = DevblocksPlatform::importGPC($_POST['content'], 'string')); @($send_to_requesters = DevblocksPlatform::importGPC($_POST['send_to_requesters'], 'integer', 0)); @($closed = DevblocksPlatform::importGPC($_POST['closed'], 'integer', 0)); @($move_bucket = DevblocksPlatform::importGPC($_POST['bucket_id'], 'string', '')); @($next_worker_id = DevblocksPlatform::importGPC($_POST['next_worker_id'], 'integer', 0)); @($ticket_reopen = DevblocksPlatform::importGPC($_POST['ticket_reopen'], 'string', '')); @($unlock_date = DevblocksPlatform::importGPC($_POST['unlock_date'], 'string', '')); if (DEMO_MODE) { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create'))); return; } // ******** $message = new CerberusParserMessage(); $message->headers['date'] = date('r'); $message->headers['to'] = $to; $message->headers['subject'] = $subject; $message->headers['message-id'] = CerberusApplication::generateMessageId(); //$message->headers['x-cerberus-portal'] = 1; // Sender $fromList = imap_rfc822_parse_adrlist(rtrim($reqs, ', '), ''); if (empty($fromList) || !is_array($fromList)) { return; // abort with message } $from = array_shift($fromList); $from_address = $from->mailbox . '@' . $from->host; $message->headers['from'] = $from_address; $message->body = sprintf("(... This message was manually created by %s on behalf of the requesters ...)\r\n", $active_worker->getName()); // // Custom Fields // // if(!empty($aFieldIds)) // foreach($aFieldIds as $iIdx => $iFieldId) { // if(!empty($iFieldId)) { // $field =& $fields[$iFieldId]; /* @var $field Model_CustomField */ // $value = ""; // // switch($field->type) { // case Model_CustomField::TYPE_SINGLE_LINE: // case Model_CustomField::TYPE_MULTI_LINE: // case Model_CustomField::TYPE_URL: // @$value = trim($aFollowUpA[$iIdx]); // break; // // case Model_CustomField::TYPE_NUMBER: // @$value = $aFollowUpA[$iIdx]; // if(!is_numeric($value) || 0 == strlen($value)) // $value = null; // break; // // case Model_CustomField::TYPE_DATE: // if(false !== ($time = strtotime($aFollowUpA[$iIdx]))) // @$value = intval($time); // break; // // case Model_CustomField::TYPE_DROPDOWN: // @$value = $aFollowUpA[$iIdx]; // break; // // case Model_CustomField::TYPE_MULTI_PICKLIST: // @$value = DevblocksPlatform::importGPC($_POST['followup_a_'.$iIdx],'array',array()); // break; // // case Model_CustomField::TYPE_CHECKBOX: // @$value = (isset($aFollowUpA[$iIdx]) && !empty($aFollowUpA[$iIdx])) ? 1 : 0; // break; // // case Model_CustomField::TYPE_MULTI_CHECKBOX: // @$value = DevblocksPlatform::importGPC($_POST['followup_a_'.$iIdx],'array',array()); // break; // // case Model_CustomField::TYPE_WORKER: // @$value = DevblocksPlatform::importGPC($_POST['followup_a_'.$iIdx],'integer',0); // break; // } // // if((is_array($value) && !empty($value)) // || (!is_array($value) && 0 != strlen($value))) // $message->custom_fields[$iFieldId] = $value; // } // } // Parse $ticket_id = CerberusParser::parseMessage($message); $ticket = DAO_Ticket::getTicket($ticket_id); // Add additional requesters to ticket if (is_array($fromList) && !empty($fromList)) { foreach ($fromList as $requester) { if (empty($requester)) { continue; } $host = empty($requester->host) ? 'localhost' : $requester->host; $requester_addy = DAO_Address::lookupAddress($requester->mailbox . '@' . $host, true); DAO_Ticket::createRequester($requester_addy->id, $ticket_id); } } // Worker reply $properties = array('message_id' => $ticket->first_message_id, 'ticket_id' => $ticket_id, 'subject' => $subject, 'content' => $content, 'files' => @$_FILES['attachment'], 'next_worker_id' => $next_worker_id, 'closed' => $closed, 'bucket_id' => $move_bucket, 'ticket_reopen' => $ticket_reopen, 'unlock_date' => $unlock_date, 'agent_id' => $active_worker->id, 'dont_send' => false == $send_to_requesters); CerberusMail::sendTicketMessage($properties); // ******** // if(empty($to) || empty($team_id)) { // DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets','create'))); // return; // } $visit = CerberusApplication::getVisit(); /* @var CerberusVisit $visit */ $visit->set('compose.last_ticket', $ticket->mask); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create'))); }
private function _sendConfirmationEmail($to, $worker) { $translate = DevblocksPlatform::getTranslationService(); $settings = DevblocksPlatform::getPluginSettingsService(); $url_writer = DevblocksPlatform::getUrlService(); $tpl = DevblocksPlatform::getTemplateService(); // Tentatively assign the e-mail address to this worker DAO_AddressToWorker::assign($to, $worker->id); // Create a confirmation code and save it $code = CerberusApplication::generatePassword(20); DAO_AddressToWorker::update($to, array(DAO_AddressToWorker::CODE => $code, DAO_AddressToWorker::CODE_EXPIRE => time() + 24 * 60 * 60)); // Email the confirmation code to the address // [TODO] This function can return false, and we need to do something different if it does. CerberusMail::quickSend($to, vsprintf($translate->_('prefs.address.confirm.mail.subject'), $settings->get('cerberusweb.core', CerberusSettings::HELPDESK_TITLE)), vsprintf($translate->_('prefs.address.confirm.mail.body'), array($worker->getName(), $url_writer->write('c=preferences&a=confirm_email&code=' . $code, true)))); $output = array(vsprintf($translate->_('prefs.address.confirm.mail.subject'), $to)); $tpl->assign('pref_success', $output); }
static function reflect(CerberusParserMessage $message, $to) { try { $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $mail = $mail_service->createMessage(); $settings = DevblocksPlatform::getPluginSettingsService(); @($from_addy = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN'])); @($from_personal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, '')); $mail->setTo(array($to)); $headers = $mail->getHeaders(); if (isset($message->headers['subject'])) { if (is_array($message->headers['subject'])) { $subject = array_shift($message->headers['subject']); } else { $subject = $message->headers['subject']; } $mail->setSubject($subject); } if (isset($message->headers['message-id'])) { $headers->addTextHeader('Message-Id', $message->headers['message-id']); } if (isset($message->headers['in-reply-to'])) { $headers->addTextHeader('In-Reply-To', $message->headers['in-reply-to']); } if (isset($message->headers['references'])) { $headers->addTextHeader('References', $message->headers['references']); } if (isset($message->headers['from'])) { $mail->setFrom($message->headers['from']); } if (isset($message->headers['return-path'])) { $mail->setReturnPath($message->headers['return-path']); } if (isset($message->headers['reply-to'])) { $mail->setReplyTo($message->headers['reply-to']); } $headers->addTextHeader('X-CerberusRedirect', '1'); $mail->setBody($message->body); // Files if (is_array($message->files)) { foreach ($message->files as $file_name => $file) { /* @var $file ParserFile */ $mail->attach(Swift_Attachment::fromPath($file->tmpname)->setFilename($file_name)); } } $result = $mailer->send($mail); if (!$result) { return false; } } catch (Exception $e) { return false; } }
function logTicketAction() { $active_worker = CerberusApplication::getActiveWorker(); if (!$active_worker->hasPriv('core.mail.log_ticket')) { return; } @($team_id = DevblocksPlatform::importGPC($_POST['team_id'], 'integer')); @($to = DevblocksPlatform::importGPC($_POST['to'], 'string')); @($subject = DevblocksPlatform::importGPC($_POST['subject'], 'string')); @($content = DevblocksPlatform::importGPC($_POST['content'], 'string')); @($files = $_FILES['attachment']); @($closed = DevblocksPlatform::importGPC($_POST['closed'], 'integer', 0)); @($move_bucket = DevblocksPlatform::importGPC($_POST['bucket_id'], 'string', '')); @($next_worker_id = DevblocksPlatform::importGPC($_POST['next_worker_id'], 'integer', 0)); @($ticket_reopen = DevblocksPlatform::importGPC($_POST['ticket_reopen'], 'string', '')); @($unlock_date = DevblocksPlatform::importGPC($_POST['unlock_date'], 'string', '')); if (DEMO_MODE) { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create'))); return; } if (empty($to) || empty($team_id)) { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create'))); return; } // [TODO] "Opened/sent on behalf of..." $properties = array('team_id' => $team_id, 'to' => $to, 'subject' => $subject, 'content' => $content, 'files' => $files, 'closed' => $closed, 'move_bucket' => $move_bucket, 'next_worker_id' => $next_worker_id, 'ticket_reopen' => $ticket_reopen, 'unlock_date' => $unlock_date, 'no_mail' => true); $ticket_id = CerberusMail::compose($properties); // [TODO] The problem here is the requester isn't the real sender (worker is) // Run group filters //if(false !== ($rules = CerberusApplication::runGroupRouting($team_id, $ticket_id))) { /* @var $rule Model_GroupInboxFilter */ // ... //} $ticket = DAO_Ticket::getTicket($ticket_id); $visit = CerberusApplication::getVisit(); /* @var CerberusVisit $visit */ $visit->set('compose.last_ticket', $ticket->mask); //DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('display',$ticket_id))); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create'))); }
static function reflect(CerberusParserMessage $message, $to) { try { $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $mail = $mail_service->createMessage(); $settings = CerberusSettings::getInstance(); @($from_addy = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN'])); @($from_personal = $settings->get(CerberusSettings::DEFAULT_REPLY_PERSONAL, '')); $sendTo = new Swift_Address($to); $sendFrom = new Swift_Address($from_addy, $from_personal); // if(is_array($message->headers)) // foreach($message->headers as $header => $val) { // if(0==strcasecmp($header,'to')) // continue; // $mail->headers->set($header, $val); // } if (isset($message->headers['subject'])) { $mail->headers->set('Subject', $message->headers['subject']); } if (isset($message->headers['message-id'])) { $mail->headers->set('Message-Id', $message->headers['message-id']); } if (isset($message->headers['in-reply-to'])) { $mail->headers->set('In-Reply-To', $message->headers['in-reply-to']); } if (isset($message->headers['references'])) { $mail->headers->set('References', $message->headers['references']); } if (isset($message->headers['from'])) { $mail->headers->set('From', $message->headers['from']); } if (isset($message->headers['return-path'])) { $mail->headers->set('Return-Path', $message->headers['return-path']); } if (isset($message->headers['reply-to'])) { $mail->headers->set('Reply-To', $message->headers['reply-to']); } $mail->headers->set('X-CerberusRedirect', '1'); $mail->attach(new Swift_Message_Part($message->body, 'text/plain', 'base64', $message->encoding)); // Files if (is_array($message->files)) { foreach ($message->files as $file_name => $file) { /* @var $file ParserFile */ $mail->attach(new Swift_Message_Attachment(new Swift_File($file->tmpname), $file_name, $file->mime_type)); } } if (!$mailer->send($mail, $sendTo, $sendFrom)) { return false; } } catch (Exception $e) { return false; } }
function saveWorkerPeekAction() { $translate = DevblocksPlatform::getTranslationService(); $active_worker = CerberusApplication::getActiveWorker(); if (!$active_worker || !$active_worker->is_superuser || DEMO_MODE) { return; } @($id = DevblocksPlatform::importGPC($_POST['id'], 'integer')); @($view_id = DevblocksPlatform::importGPC($_POST['view_id'], 'string')); @($first_name = DevblocksPlatform::importGPC($_POST['first_name'], 'string')); @($last_name = DevblocksPlatform::importGPC($_POST['last_name'], 'string')); @($title = DevblocksPlatform::importGPC($_POST['title'], 'string')); @($email = DevblocksPlatform::importGPC($_POST['email'], 'string')); @($password = DevblocksPlatform::importGPC($_POST['password'], 'string')); @($is_superuser = DevblocksPlatform::importGPC($_POST['is_superuser'], 'integer', 0)); @($disabled = DevblocksPlatform::importGPC($_POST['is_disabled'], 'integer', 0)); @($group_ids = DevblocksPlatform::importGPC($_POST['group_ids'], 'array')); @($group_roles = DevblocksPlatform::importGPC($_POST['group_roles'], 'array')); @($delete = DevblocksPlatform::importGPC($_POST['do_delete'], 'integer', 0)); // [TODO] The superuser set bit here needs to be protected by ACL if (empty($first_name)) { $first_name = "Anonymous"; } if (!empty($id) && !empty($delete)) { // Can't delete or disable self if ($active_worker->id != $id) { DAO_Worker::deleteAgent($id); } } else { if (empty($id) && null == DAO_Worker::lookupAgentEmail($email)) { $workers = DAO_Worker::getAll(); $license = CerberusLicense::getInstance(); if (!empty($license) && !empty($license['serial']) || count($workers) < 3) { // Creating new worker. If password is empty, email it to them if (empty($password)) { $settings = DevblocksPlatform::getPluginSettingsService(); $replyFrom = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM); $replyPersonal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, ''); $url = DevblocksPlatform::getUrlService(); $password = CerberusApplication::generatePassword(8); try { $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $mail = $mail_service->createMessage(); $mail->setTo(array($email => $first_name . ' ' . $last_name)); $mail->setFrom(array($replyFrom => $replyPersonal)); $mail->setSubject('Your new helpdesk login information!'); $mail->generateId(); $headers = $mail->getHeaders(); $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $body = sprintf("Your new helpdesk login information is below:\r\n" . "\r\n" . "URL: %s\r\n" . "Login: %s\r\n" . "Password: %s\r\n" . "\r\n" . "You should change your password from Preferences after logging in for the first time.\r\n" . "\r\n", $url->write('', true), $email, $password); $mail->setBody($body); if (!$mailer->send($mail)) { throw new Exception('Password notification email failed to send.'); } } catch (Exception $e) { // [TODO] need to report to the admin when the password email doesn't send. The try->catch // will keep it from killing php, but the password will be empty and the user will never get an email. } } $id = DAO_Worker::create($email, $password, '', '', ''); } } // end create worker // Update $fields = array(DAO_Worker::FIRST_NAME => $first_name, DAO_Worker::LAST_NAME => $last_name, DAO_Worker::TITLE => $title, DAO_Worker::EMAIL => $email, DAO_Worker::IS_SUPERUSER => $is_superuser, DAO_Worker::IS_DISABLED => $disabled); // if we're resetting the password if (!empty($password)) { $fields[DAO_Worker::PASSWORD] = md5($password); } // Update worker DAO_Worker::updateAgent($id, $fields); // Update group memberships if (is_array($group_ids) && is_array($group_roles)) { foreach ($group_ids as $idx => $group_id) { if (empty($group_roles[$idx])) { DAO_Group::unsetTeamMember($group_id, $id); } else { DAO_Group::setTeamMember($group_id, $id, 2 == $group_roles[$idx]); } } } // Add the worker e-mail to the addresses table if (!empty($email)) { DAO_Address::lookupAddress($email, true); } // Addresses if (null == DAO_AddressToWorker::getByAddress($email)) { DAO_AddressToWorker::assign($email, $id); DAO_AddressToWorker::update($email, array(DAO_AddressToWorker::IS_CONFIRMED => 1)); } // Custom field saves @($field_ids = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array())); DAO_CustomFieldValue::handleFormPost(ChCustomFieldSource_Worker::ID, $id, $field_ids); } if (!empty($view_id)) { $view = C4_AbstractViewLoader::getView($view_id); $view->render(); } //DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config','workers'))); }
function SendReport($full_filename, $filename) { $logger = DevblocksPlatform::getConsoleLog(); $from = '*****@*****.**'; $personal = 'First Person'; $subject = 'DR Metlife Report Generated on ' . date("n/j/y"); $mail_headers = array(); $mail_headers['X-CerberusCompose'] = '1'; $toList = NULL; $abort = true; @($answernet_email01 = $this->getParam('answernet_email01', NULL)); @($answernet_email02 = $this->getParam('answernet_email02', NULL)); @($answernet_email03 = $this->getParam('answernet_email03', NULL)); @($answernet_email04 = $this->getParam('answernet_email04', NULL)); @($answernet_email05 = $this->getParam('answernet_email05', NULL)); if ($answernet_email01 != '') { $logger->info("[Answernet.com] answernet_email01 = " . $answernet_email01); $toList = $answernet_email01; $abort = false; } if ($answernet_email02 != '') { $logger->info("[Answernet.com] answernet_email02 = " . $answernet_email02); if (!is_null($toList)) { $toList .= ","; } $toList .= $answernet_email02; $abort = false; } if ($answernet_email03 != '') { $logger->info("[Answernet.com] answernet_email03 = " . $answernet_email03); if (!is_null($toList)) { $toList .= ","; } $toList .= $answernet_email03; $abort = false; } if ($answernet_email04 != '') { $logger->info("[Answernet.com] answernet_email04 = " . $answernet_email04); if (!is_null($toList)) { $toList .= ","; } $toList .= $answernet_email04; $abort = false; } if ($answernet_email05 != '') { $logger->info("[Answernet.com] answernet_email05 = " . $answernet_email05); if (!is_null($toList)) { $toList .= ","; } $toList .= $answernet_email05; $abort = false; } if ($abort) { $logger->info("[Answernet.com] Aborting email send."); return; } $logger->info("[Answernet.com] toList = " . $toList); $files['name']['0'] = $filename; $files['type']['0'] = 'application/vnd.ms-excel'; $files['tmp_name']['0'] = $full_filename; $properties = array('team_id' => 1771, 'content' => "Metlife DR report attached", 'subject' => $subject, 'closed' => 0, 'agent_id' => 0, 'to' => $toList, 'files' => $files); $ticket_id = CerberusMail::compose($properties); $logger->info("[Answernet.com] ticket_id = " . $ticket_id); return; }
private function _sendForwards($event, $is_inbound) { @($ticket_id = $event->params['ticket_id']); @($send_worker_id = $event->params['worker_id']); $url_writer = DevblocksPlatform::getUrlService(); $ticket = DAO_Ticket::get($ticket_id); // (Action) Forward Email To: // Sanitize and combine all the destination addresses $context_workers = CerberusContexts::getWorkers(CerberusContexts::CONTEXT_TICKET, $ticket->id); if (!is_array($context_workers)) { return; } foreach ($context_workers as $next_worker) { $notify_emails = $next_worker->email; if (empty($notify_emails)) { continue; } } // [TODO] This could be more efficient $messages = DAO_Message::getMessagesByTicket($ticket_id); $message = end($messages); // last message unset($messages); $headers = $message->getHeaders(); // The whole flipping Swift section needs wrapped to catch exceptions try { $settings = DevblocksPlatform::getPluginSettingsService(); $reply_to = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, CerberusSettingsDefaults::DEFAULT_REPLY_FROM); // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, '')); if (!empty($group_from)) { $reply_to = $group_from; } } $sender = DAO_Address::get($message->address_id); $sender_email = strtolower($sender->email); $sender_split = explode('@', $sender_email); if (!is_array($sender_split) || count($sender_split) != 2) { return; } // If return-path is blank if (isset($headers['return-path']) && $headers['return-path'] == '<>') { return; } // Ignore bounces if ($sender_split[0] == "postmaster" || $sender_split[0] == "mailer-daemon") { return; } // Ignore autoresponses autoresponses if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') { return; } // Attachments $attachments = $message->getAttachments(); $mime_attachments = array(); if (is_array($attachments)) { foreach ($attachments as $attachment) { if (0 == strcasecmp($attachment->display_name, 'original_message.html')) { continue; } $attachment_path = APP_STORAGE_PATH . '/attachments/'; // [TODO] This is highly redundant in the codebase if (!file_exists($attachment_path . $attachment->filepath)) { continue; } $attach = Swift_Attachment::fromPath($attachment_path . $attachment->filepath); if (!empty($attachment->display_name)) { $attach->setFilename($attachment->display_name); } $mime_attachments[] = $attach; } } // Send copies $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $mail = $mail_service->createMessage(); /* @var $mail Swift_Message */ $mail->setTo(array($notify_emails)); $mail->setFrom(array($sender->email)); $mail->setReplyTo($reply_to); $mail->setReturnPath($reply_to); $mail->setSubject(sprintf("[RW: %s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject)); $hdrs = $mail->getHeaders(); if (null !== @($msgid = $headers['message-id'])) { $hdrs->addTextHeader('Message-Id', $msgid); } if (null !== @($in_reply_to = $headers['in-reply-to'])) { $hdrs->addTextHeader('References', $in_reply_to); $hdrs->addTextHeader('In-Reply-To', $in_reply_to); } $hdrs->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $hdrs->addTextHeader('Precedence', 'List'); $hdrs->addTextHeader('Auto-Submitted', 'auto-generated'); $mail->setBody($message->getContent()); // Send message attachments with watcher if (is_array($mime_attachments)) { foreach ($mime_attachments as $mime_attachment) { $mail->attach($mime_attachment); } } $result = $mailer->send($mail); } catch (Exception $e) { if (!empty($message_id)) { $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR); DAO_MessageNote::create($fields); } } }
private function _sendForwards($event, $is_inbound) { @($ticket_id = $event->params['ticket_id']); @($send_worker_id = $event->params['worker_id']); $ticket = DAO_Ticket::getTicket($ticket_id); // Find all our matching filters if (false == ($matches = Model_WatcherMailFilter::getMatches($ticket, $is_inbound ? 'mail_incoming' : 'mail_outgoing'))) { return; } // Sanitize and combine all the destination addresses $notify_emails = $this->_getMailingListFromMatches($matches); if (empty($notify_emails)) { return; } // [TODO] This could be more efficient $messages = DAO_Ticket::getMessagesByTicket($ticket_id); $message = end($messages); // last message unset($messages); $headers = $message->getHeaders(); // The whole flipping Swift section needs wrapped to catch exceptions try { $settings = CerberusSettings::getInstance(); $reply_to = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, ''); // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, '')); if (!empty($group_from)) { $reply_to = $group_from; } } $sender = DAO_Address::get($message->address_id); $sender_email = strtolower($sender->email); $sender_split = explode('@', $sender_email); if (!is_array($sender_split) || count($sender_split) != 2) { return; } // If return-path is blank if (isset($headers['return-path']) && $headers['return-path'] == '<>') { return; } // Ignore bounces if ($sender_split[0] == "postmaster" || $sender_split[0] == "mailer-daemon") { return; } // Ignore autoresponses autoresponses if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') { return; } // Attachments $attachments = $message->getAttachments(); $mime_attachments = array(); if (is_array($attachments)) { foreach ($attachments as $attachment) { if (0 == strcasecmp($attachment->display_name, 'original_message.html')) { continue; } $attachment_path = APP_STORAGE_PATH . '/attachments/'; // [TODO] This is highly redundant in the codebase if (!file_exists($attachment_path . $attachment->filepath)) { continue; } $file =& new Swift_File($attachment_path . $attachment->filepath); $mime_attachments[] =& new Swift_Message_Attachment($file, $attachment->display_name, $attachment->mime_type); } } // Send copies if (is_array($notify_emails) && !empty($notify_emails)) { $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); foreach ($notify_emails as $to) { // Proxy the message $rcpt_to = new Swift_RecipientList(); $a_rcpt_to = array(); $mail_from = new Swift_Address($sender->email); $rcpt_to->addTo($to); $a_rcpt_to = new Swift_Address($to); $mail = $mail_service->createMessage(); /* @var $mail Swift_Message */ $mail->setTo($a_rcpt_to); $mail->setFrom($mail_from); $mail->setReplyTo($reply_to); $mail->setReturnPath($reply_to); $mail->setSubject(sprintf("[%s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject)); if (false !== @($msgid = $headers['message-id'])) { $mail->headers->set('Message-Id', $msgid); } if (false !== @($in_reply_to = $headers['in-reply-to'])) { $mail->headers->set('References', $in_reply_to); $mail->headers->set('In-Reply-To', $in_reply_to); } $mail->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $mail->headers->set('Precedence', 'List'); $mail->headers->set('Auto-Submitted', 'auto-generated'); $mail->attach(new Swift_Message_Part($message->getContent(), 'text/plain', 'base64', LANG_CHARSET_CODE)); // Send message attachments with watcher if (is_array($mime_attachments)) { foreach ($mime_attachments as $mime_attachment) { $mail->attach($mime_attachment); } } $mailer->send($mail, $rcpt_to, $mail_from); } } } catch (Exception $e) { $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR); DAO_MessageNote::create($fields); } }