Esempio n. 1
0
 protected function actionNotification($params)
 {
     $account = Account::model()->findByPk($params['account_id']);
     $alias = $this->_findAliasFromRecipients($account, new \GO\Base\Mail\EmailRecipients($params['message_to']));
     if (!$alias) {
         $alias = $account->getDefaultAlias();
     }
     $body = sprintf(GO::t('notification_body', 'email'), $params['subject'], \GO\Base\Util\Date::get_timestamp(time()));
     $message = new \GO\Base\Mail\Message(sprintf(GO::t('notification_subject', 'email'), $params['subject']), $body);
     $message->setFrom($alias->email, $alias->name);
     $toList = new \GO\Base\Mail\EmailRecipients($params['notification_to']);
     $address = $toList->getAddress();
     $message->setTo($address['email'], $address['personal']);
     $mailer = \GO\Base\Mail\Mailer::newGoInstance(\GO\Email\Transport::newGoInstance($account));
     $response['success'] = $mailer->send($message);
     return $response;
 }
Esempio n. 2
0
 /**
  * Load the message by mime data
  * 
  * @param String $mimeData
  * @param array/string $replaceCallback A function that will be called with the body so you can replace tags in the body.
  */
 public function loadMimeMessage($mimeData, $loadDate = false, $replaceCallback = false, $replaceCallbackArgs = array())
 {
     $decoder = new MimeDecode($mimeData);
     $structure = $decoder->decode(array('include_bodies' => true, 'decode_headers' => true, 'decode_bodies' => true));
     if (!$structure) {
         throw new \Exception("Could not decode mime data:\n\n {$mimeData}");
     }
     if (!empty($structure->headers['subject'])) {
         $this->setSubject($structure->headers['subject']);
     }
     if (isset($structure->headers['disposition-notification-to'])) {
         //$mail->ConfirmReadingTo = $structure->headers['disposition-notification-to'];
     }
     //fix for [20150125 05:43:24] PHP Warning: strpos() expects parameter 1 to be string, array given in /usr/share/groupoffice/go/base/mail/Message.php on line 105
     if (isset($structure->headers['to']) && is_array($structure->headers['to'])) {
         $structure->headers['to'] = implode(',', $structure->headers['to']);
     }
     if (isset($structure->headers['cc']) && is_array($structure->headers['cc'])) {
         $structure->headers['cc'] = implode(',', $structure->headers['cc']);
     }
     if (isset($structure->headers['bcc']) && is_array($structure->headers['bcc'])) {
         $structure->headers['bcc'] = implode(',', $structure->headers['bcc']);
     }
     $to = isset($structure->headers['to']) && strpos($structure->headers['to'], 'undisclosed') === false ? $structure->headers['to'] : '';
     $cc = isset($structure->headers['cc']) && strpos($structure->headers['cc'], 'undisclosed') === false ? $structure->headers['cc'] : '';
     $bcc = isset($structure->headers['bcc']) && strpos($structure->headers['bcc'], 'undisclosed') === false ? $structure->headers['bcc'] : '';
     //workaround activesync problem where 'mailto:' is included in the mail address.
     $to = str_replace('mailto:', '', $to);
     $cc = str_replace('mailto:', '', $cc);
     $bcc = str_replace('mailto:', '', $bcc);
     $toList = new EmailRecipients($to);
     $to = $toList->getAddresses();
     foreach ($to as $email => $personal) {
         try {
             $this->addTo($email, $personal);
         } catch (Exception $e) {
             trigger_error('Failed to add receipient address: ' . $e);
         }
     }
     $ccList = new EmailRecipients($cc);
     $cc = $ccList->getAddresses();
     foreach ($cc as $email => $personal) {
         try {
             $this->addCc($email, $personal);
         } catch (Exception $e) {
             trigger_error('Failed to add CC address: ' . $e);
         }
     }
     $bccList = new EmailRecipients($bcc);
     $bcc = $bccList->getAddresses();
     foreach ($bcc as $email => $personal) {
         try {
             $this->addBcc($email, $personal);
         } catch (Exception $e) {
             trigger_error('Failed to add BCC address: ' . $e);
         }
     }
     if (isset($structure->headers['from'])) {
         $fromList = new EmailRecipients(str_replace('mailto:', '', $structure->headers['from']));
         $from = $fromList->getAddress();
         if ($from) {
             $this->setFrom($from['email'], $from['personal']);
         }
     }
     $this->_getParts($structure);
     if ($replaceCallback) {
         $bodyStart = strpos($this->_loadedBody, '<body');
         if ($bodyStart) {
             $body = substr($this->_loadedBody, $bodyStart);
             array_unshift($replaceCallbackArgs, $body);
             $body = call_user_func_array($replaceCallback, $replaceCallbackArgs);
             $this->_loadedBody = substr($this->_loadedBody, 0, $bodyStart) . $body;
         } else {
             array_unshift($replaceCallbackArgs, $this->_loadedBody);
             $this->_loadedBody = call_user_func_array($replaceCallback, $replaceCallbackArgs);
         }
     }
     if ($loadDate) {
         $date = isset($structure->headers['date']) ? $structure->headers['date'] : date('c');
         $udate = strtotime($date);
         $this->setDate($udate);
     }
     $this->setHtmlAlternateBody($this->_loadedBody);
     return $this;
 }