Ejemplo n.º 1
0
 /**
  * send a notification as email
  *
  * @param Tinebase_Model_FullUser   $_updater
  * @param Addressbook_Model_Contact $_recipient
  * @param string                    $_subject the subject
  * @param string                    $_messagePlain the message as plain text
  * @param string                    $_messageHtml the message as html
  * @param string|array              $_attachments
  */
 public function send($_updater, Addressbook_Model_Contact $_recipient, $_subject, $_messagePlain, $_messageHtml = NULL, $_attachments = NULL)
 {
     // create mail object
     $mail = new Tinebase_Mail('UTF-8');
     // this seems to break some subjects, removing it for the moment
     // -> see 0004070: sometimes we can't decode message subjects (calendar notifications?)
     //$mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
     $mail->setSubject($_subject);
     $mail->setBodyText($_messagePlain);
     if ($_messageHtml !== NULL) {
         $mail->setBodyHtml($_messageHtml);
     }
     // set mail generator
     $mail->addHeader('X-MailGenerator', 'Tine 2.0');
     // add header to identify mails sent by notification service
     $mail->addHeader('X-Tine20-Type', 'Notification');
     // don't reply to this mail, dear autoresponder ... :)
     $mail->addHeader('Precedence', 'bulk');
     if (empty($this->_fromAddress)) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No notification service address set. Could not send notification.');
         return;
     }
     if ($_updater !== NULL && !empty($_updater->accountEmailAddress)) {
         $mail->setFrom($_updater->accountEmailAddress, $_updater->accountFullName);
         $mail->setSender($this->_fromAddress, $this->_fromName);
     } else {
         $mail->setFrom($this->_fromAddress, $this->_fromName);
     }
     // attachments
     if (is_array($_attachments)) {
         $attachments =& $_attachments;
     } elseif (is_string($_attachments)) {
         $attachments = array(&$_attachments);
     } else {
         $attachments = array();
     }
     foreach ($attachments as $attachment) {
         if ($attachment instanceof Zend_Mime_Part) {
             $mail->addAttachment($attachment);
         } else {
             if (isset($attachment['filename'])) {
                 $mail->createAttachment($attachment['rawdata'], Zend_Mime::TYPE_OCTETSTREAM, Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $attachment['filename']);
             } else {
                 $mail->createAttachment($attachment);
             }
         }
     }
     // send
     if (!empty($_recipient->email)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Send notification email to ' . $_recipient->email);
         }
         $mail->addTo($_recipient->email, $_recipient->n_fn);
         Tinebase_Smtp::getInstance()->sendMessage($mail);
     } else {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Not sending notification email to ' . $_recipient->n_fn . '. No email address available.');
     }
 }
Ejemplo n.º 2
0
 /**
  * test line end encoding of Zend_Mime_Part / Smtp Protocol
  */
 public function testSendWithWrongLineEnd()
 {
     $config = TestServer::getInstance()->getConfig();
     $mailDomain = $config->maildomain ? $config->maildomain : 'tine20.org';
     // build message with wrong line end rfc822 part
     $mail = new Tinebase_Mail('utf-8');
     $mail->setBodyText('testmail' . "\r\n" . "\r\n");
     $mail->setFrom('unittest@' . $mailDomain, 'unittest');
     $mail->setSubject('line end test');
     $mail->addTo('unittest@' . $mailDomain);
     $mail->addHeader('X-Tine20TestMessage', 'lineend');
     // replace EOLs
     $content = file_get_contents(dirname(dirname(__FILE__)) . '/files/text_plain.eml');
     $content = preg_replace("/\\x0a/", "\r\n", $content);
     $stream = fopen("php://temp", 'r+');
     fputs($stream, $content);
     rewind($stream);
     $attachment = new Zend_Mime_Part($stream);
     $attachment->type = Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822;
     $attachment->encoding = null;
     $attachment->charset = 'ISO-8859-1';
     $attachment->filename = 'attach.eml';
     $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
     $mail->addAttachment($attachment);
     $smtpConfig = $this->_account->getSmtpConfig();
     $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig);
     $mail->send($transport);
     $smtpLog = $transport->getConnection()->getLog();
     $badLineEndCount = preg_match_all("/\\x0d\\x0d\\x0a/", $smtpLog, $matches);
     $this->assertEquals(0, $badLineEndCount);
     $badLineEndCount = preg_match_all("/\\x0d/", $smtpLog, $matches);
     $this->assertTrue(preg_match_all("/\\x0d/", $smtpLog, $matches) > 70, 'unix line ends are missing');
 }
 /**
  * create new mail for sending via SMTP
  * 
  * @param Felamimail_Model_Message $_message
  * @param Felamimail_Model_Account $_account
  * @param array $_nonPrivateRecipients
  * @return Tinebase_Mail
  */
 public function createMailForSending(Felamimail_Model_Message $_message, Felamimail_Model_Account $_account, &$_nonPrivateRecipients = array())
 {
     // create new mail to send
     $mail = new Tinebase_Mail('UTF-8');
     $mail->setSubject($_message->subject);
     $this->_setMailBody($mail, $_message);
     $this->_setMailFrom($mail, $_account, $_message);
     $_nonPrivateRecipients = $this->_setMailRecipients($mail, $_message);
     $this->_setMailHeaders($mail, $_account, $_message);
     $this->_addAttachments($mail, $_message);
     return $mail;
 }
Ejemplo n.º 4
0
 /**
  * send lost password mail
  *
  * @param   string $_username
  * @return  bool
  * 
  * @todo    add more texts to mail views & translate mails
  */
 public function sendLostPasswordMail($_username)
 {
     // get full user
     $fullAccount = Tinebase_User::getInstance()->getFullUserByLoginName($_username);
     // generate new password
     $newPassword = $this->generatePassword();
     // save new password in user
     Tinebase_Auth::getInstance()->setPassword($_username, $newPassword, $newPassword);
     // send lost password mail
     $mail = new Tinebase_Mail('UTF-8');
     $mail->setSubject("New password for Tine 2.0");
     // get name from user
     //$recipientName = $fullAccount->accountFirstName." ".$fullAccount->accountLastName;
     $recipientName = $fullAccount->accountFullName;
     // get email from user
     $recipientEmail = $fullAccount->accountEmailAddress;
     // get plain and html message from views
     //-- translate text and insert correct link
     $view = new Zend_View();
     $view->setScriptPath(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'views');
     $view->mailTextWelcome = "We generated a new password for you ...";
     $view->newPassword = $newPassword;
     $messagePlain = $view->render('lostpwMailPlain.php');
     $mail->setBodyText($messagePlain);
     $messageHtml = $view->render('lostpwMailHtml.php');
     if ($messageHtml !== NULL) {
         $mail->setBodyHtml($messageHtml);
     }
     $mail->addHeader('X-MailGenerator', 'Tine 2.0');
     $mail->setFrom('*****@*****.**', 'Tine 2.0 Webmaster');
     if (!empty($recipientEmail)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' send lost password email to ' . $recipientEmail);
         }
         $mail->addTo($recipientEmail, $recipientName);
         $mail->send();
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * create Tinebase_Mail from Zend_Mail_Message
  * 
  * @param  Zend_Mail_Message  $_zmm
  * @param  string             $_replyBody
  * @return Tinebase_Mail
  */
 public static function createFromZMM(Zend_Mail_Message $_zmm, $_replyBody = null)
 {
     $contentStream = fopen("php://temp", 'r+');
     fputs($contentStream, $_zmm->getContent());
     rewind($contentStream);
     $mp = new Zend_Mime_Part($contentStream);
     if ($_zmm->headerExists('content-transfer-encoding')) {
         $mp->encoding = $_zmm->getHeader('content-transfer-encoding');
         $mp->decodeContent();
     } else {
         $mp->encoding = Zend_Mime::ENCODING_7BIT;
     }
     // append old body when no multipart/mixed
     if ($_replyBody !== null && $_zmm->headerExists('content-transfer-encoding')) {
         $contentStream = fopen("php://temp", 'r+');
         stream_copy_to_stream($mp->getRawStream(), $contentStream);
         fputs($contentStream, $_replyBody);
         rewind($contentStream);
         // create decoded stream
         $mp = new Zend_Mime_Part($contentStream);
         $mp->encoding = $_zmm->getHeader('content-transfer-encoding');
     }
     if ($_zmm->headerExists('content-type')) {
         $contentTypeHeader = Zend_Mime_Decode::splitHeaderField($_zmm->getHeader('content-type'));
         $mp->type = $contentTypeHeader[0];
         if (isset($contentTypeHeader['boundary'])) {
             $mp->boundary = $contentTypeHeader['boundary'];
         }
         if (isset($contentTypeHeader['charset'])) {
             $mp->charset = $contentTypeHeader['charset'];
         }
     } else {
         $mp->type = Zend_Mime::TYPE_TEXT;
     }
     $result = new Tinebase_Mail('utf-8');
     $result->setBodyText($mp);
     foreach ($_zmm->getHeaders() as $header => $values) {
         foreach ((array) $values as $value) {
             switch ($header) {
                 case 'content-transfer-encoding':
                     // these are implicitly set by Zend_Mail_Transport_Abstract::_getHeaders()
                 // these are implicitly set by Zend_Mail_Transport_Abstract::_getHeaders()
                 case 'content-type':
                 case 'mime-version':
                     // do nothing
                     break;
                 case 'bcc':
                     $addresses = Felamimail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->addBcc($address['address'], $address['name']);
                     }
                     break;
                 case 'cc':
                     $addresses = Felamimail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->addCc($address['address'], $address['name']);
                     }
                     break;
                 case 'date':
                     try {
                         $result->setDate($value);
                     } catch (Zend_Mail_Exception $zme) {
                         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " Could not set date: " . $value);
                         }
                         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . " " . $zme);
                         }
                         $result->setDate();
                     }
                     break;
                 case 'from':
                     $addresses = Felamimail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->setFrom($address['address'], $address['name']);
                     }
                     break;
                 case 'message-id':
                     $result->setMessageId($value);
                     break;
                 case 'return-path':
                     $result->setReturnPath($value);
                     break;
                 case 'subject':
                     $result->setSubject($value);
                     break;
                 case 'to':
                     $addresses = Felamimail_Message::parseAdresslist($value);
                     foreach ($addresses as $address) {
                         $result->addTo($address['address'], $address['name']);
                     }
                     break;
                 default:
                     $result->addHeader($header, $value);
                     break;
             }
         }
     }
     return $result;
 }
 /**
  * test line end encoding of Zend_Mime_Part / Smtp Protocol
  */
 public function testSendWithWrongLineEnd()
 {
     $this->markTestSkipped('FIXME: 0011688: fix line end encoding in attachments');
     // build message with wrong line end rfc822 part
     $mail = new Tinebase_Mail('utf-8');
     $mail->setBodyText('testmail' . "\r\n" . "\r\n");
     $mail->setFrom($this->_getEmailAddress(), 'unittest');
     $mail->setSubject('line end test');
     $mail->addTo($this->_getEmailAddress());
     $mail->addHeader('X-Tine20TestMessage', 'lineend');
     // replace EOLs
     $content = file_get_contents(dirname(dirname(__FILE__)) . '/files/text_plain.eml');
     $content = preg_replace("/\\x0a/", "\r\n", $content);
     $stream = fopen("php://temp", 'r+');
     fputs($stream, $content);
     rewind($stream);
     $attachment = new Zend_Mime_Part($stream);
     $attachment->type = Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822;
     $attachment->encoding = null;
     $attachment->charset = 'ISO-8859-1';
     $attachment->filename = 'attach.eml';
     $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
     $mail->addAttachment($attachment);
     $smtpConfig = $this->_account->getSmtpConfig();
     $transport = new Felamimail_Transport($smtpConfig['hostname'], $smtpConfig);
     Zend_Mail_Protocol_Abstract::$loggingEnabled = true;
     $mail->send($transport);
     Zend_Mail_Protocol_Abstract::$loggingEnabled = false;
     $smtpLog = $transport->getConnection()->getLog();
     $badLineEndCount = preg_match_all("/\\x0d\\x0d\\x0a/", $smtpLog, $matches);
     $this->assertEquals(0, $badLineEndCount);
     $unixLineEndCount = preg_match_all("/\\x0d/", $smtpLog, $matches);
     $this->assertTrue($unixLineEndCount > 70, 'unix line ends are missing (got ' . $unixLineEndCount . ' unix line ends)');
 }