Exemplo n.º 1
0
 public function runMailQueue($targetRunTime)
 {
     $s = microtime(true);
     $transport = XenForo_Mail::getTransport();
     $db = $this->_getDb();
     do {
         $queue = $this->getMailQueue($targetRunTime ? 20 : 0);
         foreach ($queue as $id => $record) {
             if (!$db->delete('xf_mail_queue', 'mail_queue_id = ' . $db->quote($id))) {
                 // already been deleted - run elsewhere
                 continue;
             }
             $mailObj = @unserialize($record['mail_data']);
             if (!$mailObj instanceof Zend_Mail) {
                 continue;
             }
             $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
             try {
                 $mailObj->send($thisTransport);
             } catch (Exception $e) {
                 $toEmails = implode(', ', $mailObj->getRecipients());
                 XenForo_Error::logException($e, false, "Email to {$toEmails} failed: ");
                 // pipe may be messed up now, so let's be sure to get another one
                 unset($transport);
                 $transport = XenForo_Mail::getTransport();
             }
             if ($targetRunTime && microtime(true) - $s > $targetRunTime) {
                 $queue = false;
                 break;
             }
         }
     } while ($queue);
     return $this->hasMailQueue();
 }
Exemplo n.º 2
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('start' => 0, 'count' => 0, 'criteria' => null, 'userIds' => null, 'email' => array()), $data);
     if (!XenForo_Application::get('config')->enableMail) {
         return false;
     }
     $s = microtime(true);
     /* @var $userModel XenForo_Model_User */
     $userModel = XenForo_Model::create('XenForo_Model_User');
     if (is_array($data['criteria'])) {
         $userIds = $userModel->getUserIds($data['criteria'], $data['start'], 1000);
     } else {
         if (is_array($data['userIds'])) {
             $userIds = $data['userIds'];
         } else {
             $userIds = array();
         }
     }
     if (!$userIds) {
         return false;
     }
     $email = $data['email'];
     $transport = XenForo_Mail::getTransport();
     $limitTime = $targetRunTime > 0;
     foreach ($userIds as $key => $userId) {
         $data['count']++;
         $data['start'] = $userId;
         unset($userIds[$key]);
         $user = $userModel->getUserById($userId);
         if ($user) {
             $this->_sendEmail($email, $user, $transport);
         }
         if ($limitTime && microtime(true) - $s > $targetRunTime) {
             break;
         }
     }
     if (is_array($data['userIds'])) {
         $data['userIds'] = $userIds;
     }
     $actionPhrase = new XenForo_Phrase('emailing');
     $typePhrase = new XenForo_Phrase('users');
     $status = sprintf('%s... %s (%d)', $actionPhrase, $typePhrase, $data['count']);
     return $data;
 }
Exemplo n.º 3
0
 /**
  * Sends the specified email.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionEmailSend()
 {
     $this->_assertPostOnly();
     $criteria = $this->_input->filterSingle('criteria', XenForo_Input::JSON_ARRAY);
     $criteria = $this->_filterUserSearchCriteria($criteria);
     $criteriaPrepared = $this->_prepareUserSearchCriteria($criteria);
     $email = $this->_input->filter(array('from_name' => XenForo_Input::STRING, 'from_email' => XenForo_Input::STRING, 'email_title' => XenForo_Input::STRING, 'email_format' => XenForo_Input::STRING, 'email_body' => XenForo_Input::STRING));
     $total = $this->_input->filterSingle('total', XenForo_Input::UINT);
     $failed = $this->_input->filterSingle('failed', XenForo_Input::UINT);
     $transport = XenForo_Mail::getTransport();
     if ($this->_input->filterSingle('test', XenForo_Input::STRING)) {
         $this->_sendEmail(XenForo_Visitor::getInstance()->toArray(), $email, $transport);
         return $this->responseReroute(__CLASS__, 'email');
     }
     $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
     $perPage = 30;
     $users = $this->_getUserModel()->getUsers($criteriaPrepared, array('page' => $page, 'perPage' => $perPage));
     if (!$users) {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('users/email', false, array('sent' => $total, 'failed' => $failed)));
     } else {
         foreach ($users as $user) {
             if (!$this->_sendEmail($user, $email, $transport)) {
                 $failed++;
             }
         }
         $viewParams = array('total' => $total, 'failed' => $failed, 'completed' => ($page - 1) * $perPage + count($users), 'nextPage' => $page + 1, 'criteria' => $criteria, 'email' => $email);
         return $this->responseView('XenForo_ViewAdmin_User_Email_Send', 'user_email_send', $viewParams);
     }
 }
Exemplo n.º 4
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('start' => 0, 'count' => 0, 'criteria' => null, 'userIds' => null, 'email' => array()), $data);
     if (!XenForo_Application::get('config')->enableMail) {
         return false;
     }
     $s = microtime(true);
     /* @var $userModel XenForo_Model_User */
     $userModel = XenForo_Model::create('XenForo_Model_User');
     if (is_array($data['criteria'])) {
         $userIds = $userModel->getUserIds($data['criteria'], $data['start'], 1000);
     } else {
         if (is_array($data['userIds'])) {
             $userIds = $data['userIds'];
         } else {
             $userIds = array();
         }
     }
     if (!$userIds) {
         return false;
     }
     $options = XenForo_Application::getOptions();
     $email = $data['email'];
     $transport = XenForo_Mail::getTransport();
     $limitTime = $targetRunTime > 0;
     foreach ($userIds as $key => $userId) {
         $data['count']++;
         $data['start'] = $userId;
         unset($userIds[$key]);
         $user = $userModel->getUserById($userId);
         if (!$user['email']) {
             continue;
         }
         $phraseTitles = XenForo_Helper_String::findPhraseNamesFromStringSimple($email['email_title'] . $email['email_body']);
         /** @var XenForo_Model_Phrase $phraseModel */
         $phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
         $phrases = $phraseModel->getPhraseTextFromPhraseTitles($phraseTitles, $user['language_id']);
         foreach ($phraseTitles as $search => $phraseTitle) {
             if (isset($phrases[$phraseTitle])) {
                 $email['email_title'] = str_replace($search, $phrases[$phraseTitle], $email['email_title']);
                 $email['email_body'] = str_replace($search, $phrases[$phraseTitle], $email['email_body']);
             }
         }
         $mailObj = new Zend_Mail('utf-8');
         $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
         $bounceEmailAddress = $options->bounceEmailAddress;
         if (!$bounceEmailAddress) {
             $bounceEmailAddress = $options->defaultEmailAddress;
         }
         $toEmail = $user['email'];
         $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
         $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
         if ($options->enableVerp) {
             $verpValue = str_replace('@', '=', $toEmail);
             $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
         }
         $mailObj->setReturnPath($bounceEmailAddress);
         if ($email['email_format'] == 'html') {
             $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
             $email['email_body'] = strtr($email['email_body'], $replacements);
             $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
             $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
         } else {
             $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
             $email['email_body'] = strtr($email['email_body'], $replacements);
             $mailObj->setBodyText($email['email_body']);
         }
         if (!$mailObj->getMessageId()) {
             $mailObj->setMessageId();
         }
         $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
         try {
             $mailObj->send($thisTransport);
         } catch (Exception $e) {
             XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
             continue;
         }
         if ($limitTime && microtime(true) - $s > $targetRunTime) {
             break;
         }
     }
     if (is_array($data['userIds'])) {
         $data['userIds'] = $userIds;
     }
     $actionPhrase = new XenForo_Phrase('emailing');
     $typePhrase = new XenForo_Phrase('users');
     $status = sprintf('%s... %s (%d)', $actionPhrase, $typePhrase, $data['count']);
     return $data;
 }