本文整理汇总了PHP中DevblocksPlatform::getMailService方法的典型用法代码示例。如果您正苦于以下问题:PHP DevblocksPlatform::getMailService方法的具体用法?PHP DevblocksPlatform::getMailService怎么用?PHP DevblocksPlatform::getMailService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DevblocksPlatform
的用法示例。
在下文中一共展示了DevblocksPlatform::getMailService方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _sendForwards
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);
}
//.........这里部分代码省略.........
示例2: doRegisterAction
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')));
}
示例3: getMailboxTestAction
function getMailboxTestAction()
{
$translate = DevblocksPlatform::getTranslationService();
@($protocol = DevblocksPlatform::importGPC($_REQUEST['protocol'], 'string', ''));
@($host = DevblocksPlatform::importGPC($_REQUEST['host'], 'string', ''));
@($port = DevblocksPlatform::importGPC($_REQUEST['port'], 'integer', 110));
@($user = DevblocksPlatform::importGPC($_REQUEST['user'], 'string', ''));
@($pass = DevblocksPlatform::importGPC($_REQUEST['pass'], 'string', ''));
// Defaults
if (empty($port)) {
switch ($protocol) {
case 'pop3':
$port = 110;
break;
case 'pop3-ssl':
$port = 995;
break;
case 'imap':
$port = 143;
break;
case 'imap-ssl':
$port = 993;
break;
}
}
$tpl = DevblocksPlatform::getTemplateService();
$tpl->assign('path', $this->_TPL_PATH);
// [JAS]: Test the provided POP settings and give form feedback
if (!empty($host)) {
$mail_service = DevblocksPlatform::getMailService();
if (false !== $mail_service->testImap($host, $port, $protocol, $user, $pass)) {
$tpl->assign('pop_test', true);
} else {
$tpl->assign('pop_test', false);
$tpl->assign('pop_test_output', $translate->_('config.mail.pop3.failed'));
}
} else {
$tpl->assign('pop_test, false');
$tpl->assign('pop_test_output', $translate->_('config.mail.pop3.error_hostname'));
}
$tpl->display('file:' . $this->_TPL_PATH . 'configuration/tabs/mail/test_pop.tpl');
return;
}
示例4: doRecoverStep1Action
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')));
}
示例5: getSmtpTestAction
function getSmtpTestAction()
{
$translate = DevblocksPlatform::getTranslationService();
@($host = DevblocksPlatform::importGPC($_REQUEST['host'], 'string', ''));
@($port = DevblocksPlatform::importGPC($_REQUEST['port'], 'integer', 25));
@($smtp_enc = DevblocksPlatform::importGPC($_REQUEST['enc'], 'string', ''));
@($smtp_auth = DevblocksPlatform::importGPC($_REQUEST['smtp_auth'], 'integer', 0));
@($smtp_user = DevblocksPlatform::importGPC($_REQUEST['smtp_user'], 'string', ''));
@($smtp_pass = DevblocksPlatform::importGPC($_REQUEST['smtp_pass'], 'string', ''));
$tpl = DevblocksPlatform::getTemplateService();
$tpl->assign('path', $this->_TPL_PATH);
// [JAS]: Test the provided SMTP settings and give form feedback
if (!empty($host)) {
try {
$mail_service = DevblocksPlatform::getMailService();
$mailer = $mail_service->getMailer(array('host' => $host, 'port' => $port, 'auth_user' => $smtp_user, 'auth_pass' => $smtp_pass, 'enc' => $smtp_enc));
$transport = $mailer->getTransport();
$transport->start();
$transport->stop();
$tpl->assign('smtp_test', true);
} catch (Exception $e) {
$tpl->assign('smtp_test', false);
$tpl->assign('smtp_test_output', $translate->_('setup.mail.smtp.failed') . ' ' . $e->getMessage());
}
$tpl->display('file:' . $this->_TPL_PATH . 'setup/tabs/mail/test_smtp.tpl');
}
return;
}
示例6: _sendConfirmation
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;
}
}
示例7: saveWorkerAction
function saveWorkerAction()
{
$translate = DevblocksPlatform::getTranslationService();
$active_worker = CerberusApplication::getActiveWorker();
if (!$active_worker || !$active_worker->is_superuser) {
echo $translate->_('common.access_denied');
return;
}
if (DEMO_MODE) {
DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'workers')));
return;
}
@($id = DevblocksPlatform::importGPC($_POST['id'], 'integer'));
@($first_name = DevblocksPlatform::importGPC($_POST['first_name'], 'string'));
@($last_name = DevblocksPlatform::importGPC($_POST['last_name'], 'string'));
@($title = DevblocksPlatform::importGPC($_POST['title'], 'string'));
@($primary_email = DevblocksPlatform::importGPC($_POST['primary_email'], 'string'));
@($email = DevblocksPlatform::importGPC($_POST['email'], 'string'));
@($password = DevblocksPlatform::importGPC($_POST['password'], 'string'));
@($is_superuser = DevblocksPlatform::importGPC($_POST['is_superuser'], 'integer'));
@($group_ids = DevblocksPlatform::importGPC($_POST['group_ids'], 'array'));
@($group_roles = DevblocksPlatform::importGPC($_POST['group_roles'], 'array'));
@($disabled = DevblocksPlatform::importGPC($_POST['do_disable'], 'integer', 0));
@($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) {
return;
}
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 = CerberusSettings::getInstance();
$replyFrom = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
$replyPersonal = $settings->get(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();
$sendTo = new Swift_Address($email, $first_name . $last_name);
$sendFrom = new Swift_Address($replyFrom, $replyPersonal);
$mail->setSubject('Your new helpdesk login information!');
$mail->generateId();
$mail->headers->set('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->attach(new Swift_Message_Part($body, 'text/plain', 'base64', LANG_CHARSET_CODE));
if (!$mailer->send($mail, $sendTo, $sendFrom)) {
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, '', '', '');
} else {
//not licensed and worker limit reached
DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'workers')));
return;
}
}
$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));
}
}
DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'workers')));
//.........这里部分代码省略.........
示例8: sendMailProperties
static function sendMailProperties($properties)
{
$status = true;
@($toStr = $properties['to']);
@($cc = $properties['cc']);
@($bcc = $properties['bcc']);
@($subject = $properties['subject']);
@($content = $properties['content']);
@($files = $properties['files']);
$mail_settings = self::getMailerDefaults();
if (empty($properties['from_addy'])) {
@($from_addy = $settings->get('feg.core', FegSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN']));
}
if (empty($properties['from_personal'])) {
@($from_personal = $settings->get('feg.core', FegSettings::DEFAULT_REPLY_PERSONAL, ''));
}
if (empty($subject)) {
$subject = '(no subject)';
}
// [JAS]: Replace any semi-colons with commas (people like using either)
$toList = DevblocksPlatform::parseCsvString(str_replace(';', ',', $toStr));
$mail_headers = array();
$mail_headers['X-FegCompose'] = '1';
// Headers needed for the ticket message
$log_headers = new Swift_Message_Headers();
$log_headers->setCharset(LANG_CHARSET_CODE);
$log_headers->set('To', $toList);
$log_headers->set('From', !empty($from_personal) ? sprintf("%s <%s>", $from_personal, $from_addy) : sprintf('%s', $from_addy));
$log_headers->set('Subject', $subject);
$log_headers->set('Date', date('r'));
foreach ($log_headers->getList() as $hdr => $v) {
if (null != ($hdr_val = $log_headers->getEncoded($hdr))) {
if (!empty($hdr_val)) {
$mail_headers[$hdr] = $hdr_val;
}
}
}
try {
$mail_service = DevblocksPlatform::getMailService();
$mailer = $mail_service->getMailer(FegMail::getMailerDefaults());
$email = $mail_service->createMessage();
$email->setTo($toList);
// cc
$ccs = array();
if (!empty($cc) && null != ($ccList = DevblocksPlatform::parseCsvString(str_replace(';', ',', $cc)))) {
$email->setCc($ccList);
}
// bcc
if (!empty($bcc) && null != ($bccList = DevblocksPlatform::parseCsvString(str_replace(';', ',', $bcc)))) {
$email->setBcc($bccList);
}
$email->setFrom(array($from => $personal));
$email->setSubject($subject);
$email->generateId();
$headers = $email->getHeaders();
$headers->addTextHeader('X-Mailer', 'Fax Email Gateway (FEG) ' . APP_VERSION . ' (Build ' . APP_BUILD . ')');
$email->setBody($content);
// Mime Attachments
if (is_array($files) && !empty($files)) {
foreach ($files['tmp_name'] as $idx => $file) {
if (empty($file) || empty($files['name'][$idx])) {
continue;
}
$email->attach(Swift_Attachment::fromPath($file)->setFilename($files['name'][$idx]));
}
}
// Headers
foreach ($email->getHeaders()->getAll() as $hdr) {
if (null != ($hdr_val = $hdr->getFieldBody())) {
if (!empty($hdr_val)) {
$mail_headers[$hdr->getFieldName()] = $hdr_val;
}
}
}
// [TODO] Allow separated addresses (parseRfcAddress)
// $mailer->log->enable();
if (!@$mailer->send($email)) {
throw new Exception('Mail failed to send: unknown reason');
}
// $mailer->log->dump();
} catch (Exception $e) {
// Do Something
$status = false;
}
// Give plugins a chance to note a message is imported.
$eventMgr = DevblocksPlatform::getEventService();
$eventMgr->trigger(new Model_DevblocksEvent('email.send', array('properties' => $properties, 'send_status' => $status ? 2 : 1)));
return $status;
}
示例9:
$tpl->assign('app_title', $app_title);
$tpl->assign('template', 'steps/step_contact.tpl');
break;
// Set up and test the outgoing SMTP
// Set up and test the outgoing SMTP
case STEP_OUTGOING_MAIL:
$settings = DevblocksPlatform::getPluginSettingsService();
@($smtp_host = DevblocksPlatform::importGPC($_POST['smtp_host'], 'string', $settings->get('feg.core', FegSettings::SMTP_HOST, 'localhost')));
@($smtp_port = DevblocksPlatform::importGPC($_POST['smtp_port'], 'integer', $settings->get('feg.core', FegSettings::SMTP_PORT, 25)));
@($smtp_enc = DevblocksPlatform::importGPC($_POST['smtp_enc'], 'string', $settings->get('feg.core', FegSettings::SMTP_ENCRYPTION_TYPE, 'None')));
@($smtp_auth_user = DevblocksPlatform::importGPC($_POST['smtp_auth_user'], 'string'));
@($smtp_auth_pass = DevblocksPlatform::importGPC($_POST['smtp_auth_pass'], 'string'));
@($form_submit = DevblocksPlatform::importGPC($_POST['form_submit'], 'integer'));
@($passed = DevblocksPlatform::importGPC($_POST['passed'], 'integer'));
if (!empty($form_submit)) {
$mail_service = DevblocksPlatform::getMailService();
$mailer = null;
try {
$mailer = $mail_service->getMailer(array('host' => $smtp_host, 'port' => $smtp_port, 'auth_user' => $smtp_auth_user, 'auth_pass' => $smtp_auth_pass, 'enc' => $smtp_enc));
$transport = $mailer->getTransport();
$transport->start();
$transport->stop();
if (!empty($smtp_host)) {
$settings->set('feg.core', FegSettings::SMTP_HOST, $smtp_host);
}
if (!empty($smtp_port)) {
$settings->set('feg.core', FegSettings::SMTP_PORT, $smtp_port);
}
if (!empty($smtp_auth_user)) {
$settings->set('feg.core', FegSettings::SMTP_AUTH_ENABLED, 1);
$settings->set('feg.core', FegSettings::SMTP_AUTH_USER, $smtp_auth_user);
示例10: _sendForwards
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);
//.........这里部分代码省略.........
示例11: reflect
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;
}
}
示例12: quickSend
static function quickSend($to, $subject, $body, $from_addy = null, $from_personal = null)
{
try {
$mail_service = DevblocksPlatform::getMailService();
$mailer = $mail_service->getMailer(UsermeetMail::getMailerDefaults());
$mail = $mail_service->createMessage();
$settings = DevblocksPlatform::getPluginSettingsService();
if (empty($from_addy)) {
@($from_addy = $settings->get('usermeet.core', UsermeetSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN']));
}
if (empty($from_personal)) {
@($from_personal = $settings->get('usermeet.core', UsermeetSettings::DEFAULT_REPLY_PERSONAL, ''));
}
$mail->setTo(array($to));
$mail->setFrom(array($from_addy => $from_personal));
$mail->setSubject($subject);
$mail->generateId();
$headers = $mail->getHeaders();
$headers->addTextHeader('X-Mailer', 'Usermeet (Build ' . APP_BUILD . ')');
$mail->setBody($body);
// [TODO] Report when the message wasn't sent.
if (!$mailer->send($mail)) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
示例13: reflect
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;
}
}
示例14: _sendForwards
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);
}
//.........这里部分代码省略.........