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
 /**
  * this function generates the response for the client
  * 
  * @return void
  */
 public function getResponse()
 {
     $rfc822 = Felamimail_Controller_Message::getInstance()->getMessagePart($this->_itemId);
     $rfc822->type = Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822;
     $rfc822->filename = 'forwarded email.eml';
     $rfc822->encoding = Zend_Mime::ENCODING_7BIT;
     $mail = Tinebase_Mail::createFromZMM($this->_incomingMessage);
     $mail->addAttachment($rfc822);
     Felamimail_Controller_Message_Send::getInstance()->sendZendMail($this->_account, $mail, $this->_saveInSent);
 }
 /**
  * add attachments to mail
  *
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Message $_message
  * @throws Felamimail_Exception_IMAP
  */
 protected function _addAttachments(Tinebase_Mail $_mail, Felamimail_Model_Message $_message)
 {
     if (!isset($_message->attachments) || empty($_message->attachments)) {
         return;
     }
     $maxAttachmentSize = $this->_getMaxAttachmentSize();
     $size = 0;
     $tempFileBackend = Tinebase_TempFile::getInstance();
     foreach ($_message->attachments as $attachment) {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding attachment: ' . (is_object($attachment) ? print_r($attachment->toArray(), TRUE) : print_r($attachment, TRUE)));
         }
         if (isset($attachment['type']) && $attachment['type'] == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 && $_message->original_id instanceof Felamimail_Model_Message) {
             $part = $this->getMessagePart($_message->original_id, $_message->original_part_id ? $_message->original_part_id : NULL);
             $part->decodeContent();
             $name = $attachment['name'] . '.eml';
             $type = $attachment['type'];
             if (!empty($attachment['size'])) {
                 $size += $attachment['size'];
             }
         } else {
             $tempFile = $attachment instanceof Tinebase_Model_TempFile ? $attachment : (isset($attachment['tempFile']) || array_key_exists('tempFile', $attachment) ? $tempFileBackend->get($attachment['tempFile']['id']) : NULL);
             if ($tempFile === NULL) {
                 continue;
             }
             if (!$tempFile->path) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Could not find attachment.');
                 continue;
             }
             // get contents from uploaded file
             $stream = fopen($tempFile->path, 'r');
             $part = new Zend_Mime_Part($stream);
             // RFC822 attachments are not encoded, set all others to ENCODING_BASE64
             $part->encoding = $tempFile->type == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 ? null : Zend_Mime::ENCODING_BASE64;
             $name = $tempFile->name;
             $type = $tempFile->type;
             if (!empty($tempFile->size)) {
                 $size += $tempFile->size;
             }
         }
         $part->setTypeAndDispositionForAttachment($type, $name);
         if ($size > $maxAttachmentSize) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Current attachment size: ' . Tinebase_Helper::convertToMegabytes($size) . ' MB / allowed size: ' . Tinebase_Helper::convertToMegabytes($maxAttachmentSize) . ' MB');
             }
             throw new Felamimail_Exception_IMAP('Maximum attachment size exceeded. Please remove one or more attachments.');
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding attachment ' . $part->type);
         }
         $_mail->addAttachment($part);
     }
 }
 /**
  * appends old body to mime part
  * 
  * @param Zend_Mime_Part $mp
  * @param string $replyBody plain/text reply body
  * @return Zend_Mime_Part
  */
 protected static function _appendReplyBody(Zend_Mime_Part $mp, $replyBody)
 {
     $decodedContent = Tinebase_Mail::getDecodedContent($mp, NULL, FALSE);
     $type = $mp->type;
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " mp content: " . $decodedContent);
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " reply body: " . $replyBody);
     }
     if ($type === Zend_Mime::TYPE_HTML && $replyBody === strip_tags($replyBody)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Converting plain/text reply body to HTML");
         }
         $replyBody = self::convertFromTextToHTML($replyBody);
     }
     if ($type === Zend_Mime::TYPE_HTML && preg_match('/(<\\/body>[\\s\\r\\n]*<\\/html>)/i', $decodedContent, $matches)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Appending reply body to html body.');
         }
         $decodedContent = str_replace($matches[1], $replyBody . $matches[1], $decodedContent);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Appending reply body to mime text part.");
         }
         $decodedContent .= $replyBody;
     }
     $mp = new Zend_Mime_Part($decodedContent);
     $mp->charset = 'utf-8';
     $mp->type = $type;
     return $mp;
 }
Ejemplo n.º 5
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;
 }
 /**
  * get vacation message defined by template / do substitutions for dates and representative 
  * 
  * @param array $vacationData
  * @return array
  */
 public function getVacationMessage($vacationData)
 {
     $record = new Felamimail_Model_Sieve_Vacation(array(), TRUE);
     $record->setFromJsonInUsersTimezone($vacationData);
     $message = Felamimail_Controller_Sieve::getInstance()->getVacationMessage($record);
     $htmlMessage = Tinebase_Mail::convertFromTextToHTML($message, 'felamimail-body-blockquote');
     return array('message' => $htmlMessage);
 }
 /**
  * create Felamimail message from Zend_Mail_Message
  * 
  * @param Zend_Mail_Message $_zendMailMessage
  * @return Felamimail_Model_Message
  */
 public static function createMessageFromZendMailMessage(Zend_Mail_Message $_zendMailMessage)
 {
     $message = new Felamimail_Model_Message();
     foreach ($_zendMailMessage->getHeaders() as $headerName => $headerValue) {
         switch ($headerName) {
             case 'subject':
                 $message->{$headerName} = $headerValue;
                 break;
             case 'from':
                 // do nothing
                 break;
             case 'to':
             case 'bcc':
             case 'cc':
                 $receipients = array();
                 $addresses = Tinebase_Mail::parseAdresslist($headerValue);
                 foreach ($addresses as $address) {
                     $receipients[] = $address['address'];
                 }
                 $message->{$headerName} = $receipients;
                 break;
         }
     }
     $contentType = $_zendMailMessage->getHeaderField('content-type', 0);
     $message->content_type = $contentType;
     // @todo convert to utf-8 if needed
     $charset = $_zendMailMessage->getHeaderField('content-type', 'charset');
     $encoding = $_zendMailMessage->getHeaderField('content-transfer-encoding');
     switch ($encoding) {
         case Zend_Mime::ENCODING_QUOTEDPRINTABLE:
             $message->body = quoted_printable_decode($_zendMailMessage->getContent());
             break;
         case Zend_Mime::ENCODING_BASE64:
             $message->body = base64_decode($_zendMailMessage->getContent());
             break;
         default:
             $message->body = $_zendMailMessage->getContent();
             break;
     }
     return $message;
 }
 /**
  * send email
  *
  * @param resource $inputStream
  * @param boolean $saveInSent
  * @throws Syncroton_Exception
  */
 public function sendEmail($inputStream, $saveInSent)
 {
     $defaultAccountId = Tinebase_Core::getPreference('Expressomail')->{Expressomail_Preference::DEFAULTACCOUNT};
     try {
         $account = Expressomail_Controller_Account::getInstance()->get($defaultAccountId);
     } catch (Tinebase_Exception_NotFound $ten) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " no email account configured");
         }
         throw new Syncroton_Exception('no email account configured');
     }
     if (empty(Tinebase_Core::getUser()->accountEmailAddress)) {
         throw new Syncroton_Exception('no email address set for current user');
     }
     if (!is_resource($inputStream)) {
         $stream = fopen("php://temp", 'r+');
         fwrite($stream, $inputStream);
         $inputStream = $stream;
         rewind($inputStream);
     }
     if ($this->_debugEmail == true) {
         $debugStream = fopen("php://temp", 'r+');
         stream_copy_to_stream($inputStream, $debugStream);
         rewind($debugStream);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " email to send:" . stream_get_contents($debugStream));
         }
         //replace original stream wirh debug stream, as php://input can't be rewinded
         $inputStream = $debugStream;
         rewind($inputStream);
     }
     $incomingMessage = new Zend_Mail_Message(array('file' => $inputStream));
     $subject = $incomingMessage->headerExists('subject') ? $incomingMessage->getHeader('subject') : null;
     if (Tinebase_Mail::isiMIPMail($incomingMessage)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Do not send iMIP message with subject "' . $subject . '". The server should handle those.');
         }
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Send Message with subject " . $subject . " (saveInSent: " . $saveInSent . ")");
         }
         $mail = Tinebase_Mail::createFromZMM($incomingMessage);
         Expressomail_Controller_Message_Send::getInstance()->sendZendMail($account, $mail, (bool) $saveInSent);
     }
 }
Ejemplo n.º 9
0
 /**
  * add attachments to mail
  *
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Message $_message
  */
 protected function _addAttachments(Tinebase_Mail $_mail, Felamimail_Model_Message $_message)
 {
     if (isset($_message->attachments)) {
         $size = 0;
         $tempFileBackend = Tinebase_TempFile::getInstance();
         foreach ($_message->attachments as $attachment) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding attachment: ' . print_r($attachment, TRUE));
             }
             if ($attachment['type'] == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 && $_message->original_id instanceof Felamimail_Model_Message) {
                 $part = $this->getMessagePart($_message->original_id, $_message->original_part_id ? $_message->original_part_id : NULL);
                 $part->decodeContent();
                 $name = $attachment['name'] . '.eml';
                 $type = $attachment['type'];
             } else {
                 $tempFile = $attachment instanceof Tinebase_Model_TempFile ? $attachment : (array_key_exists('tempFile', $attachment) ? $tempFileBackend->get($attachment['tempFile']['id']) : NULL);
                 if ($tempFile === NULL) {
                     continue;
                 }
                 if (!$tempFile->path) {
                     Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Could not find attachment.');
                     continue;
                 }
                 // get contents from uploaded file
                 $stream = fopen($tempFile->path, 'r');
                 $part = new Zend_Mime_Part($stream);
                 // RFC822 attachments are not encoded, set all others to ENCODING_BASE64
                 $part->encoding = $tempFile->type == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 ? null : Zend_Mime::ENCODING_BASE64;
                 $name = $tempFile->name;
                 $type = $tempFile->type;
             }
             $part->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
             $part->filename = $name;
             $part->type = $type . '; name="' . $name . '"';
             $_mail->addAttachment($part);
         }
     }
 }
 /**
  * get and decode message body
  * 
  * @param Felamimail_Model_Message $_message
  * @param string $_partId
  * @param string $_contentType
  * @param Felamimail_Model_Account $_account
  * @return string
  * 
  * @todo multipart_related messages should deliver inline images
  */
 protected function _getAndDecodeMessageBody(Felamimail_Model_Message $_message, $_partId, $_contentType, $_account = NULL)
 {
     $structure = $_message->getPartStructure($_partId);
     if (empty($structure)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Empty structure, could not find body parts of message ' . $_message->subject);
         }
         return '';
     }
     $bodyParts = $_message->getBodyParts($structure, $_contentType);
     if (empty($bodyParts)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Could not find body parts of message ' . $_message->subject);
         }
         return '';
     }
     $messageBody = '';
     foreach ($bodyParts as $partId => $partStructure) {
         $bodyPart = $this->getMessagePart($_message, $partId, TRUE, $partStructure);
         $body = Tinebase_Mail::getDecodedContent($bodyPart, $partStructure);
         if ($partStructure['contentType'] != Zend_Mime::TYPE_TEXT) {
             $bodyCharCountBefore = strlen($body);
             $body = $this->_purifyBodyContent($body, $_message->getId());
             $bodyCharCountAfter = strlen($body);
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Purifying removed ' . ($bodyCharCountBefore - $bodyCharCountAfter) . ' / ' . $bodyCharCountBefore . ' characters.');
             }
             if ($_message->text_partid && $bodyCharCountAfter < $bodyCharCountBefore / 10) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Purify may have removed (more than 9/10) too many chars, using alternative text message part.');
                 }
                 $result = $this->_getAndDecodeMessageBody($_message, $_message->text_partid, Zend_Mime::TYPE_TEXT, $_account);
                 return Felamimail_Message::convertContentType(Zend_Mime::TYPE_TEXT, Zend_Mime::TYPE_HTML, $result);
             }
         }
         if (!($_account !== NULL && $_account->display_format === Felamimail_Model_Account::DISPLAY_CONTENT_TYPE && $bodyPart->type == Zend_Mime::TYPE_TEXT)) {
             $body = Felamimail_Message::convertContentType($partStructure['contentType'], $_contentType, $body);
             if ($bodyPart->type == Zend_Mime::TYPE_TEXT && $_contentType == Zend_Mime::TYPE_HTML) {
                 $body = Felamimail_Message::replaceUris($body);
                 $body = Felamimail_Message::replaceEmails($body);
             }
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Do not convert ' . $bodyPart->type . ' part to ' . $_contentType);
             }
         }
         $body = Felamimail_Message::replaceTargets($body);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding part ' . $partId . ' to message body.');
         }
         $messageBody .= Tinebase_Core::filterInputForDatabase($body);
     }
     return $messageBody;
 }
Ejemplo n.º 11
0
 /**
  * this function generates the response for the client
  * 
  * @return void
  */
 public function getResponse()
 {
     $replyBody = Felamimail_Controller_Message::getInstance()->getMessageBody($this->_itemId, null, 'text/plain');
     $mail = Tinebase_Mail::createFromZMM($this->_incomingMessage, $replyBody);
     Felamimail_Controller_Message_Send::getInstance()->sendZendMail($this->_account, $mail, $this->_saveInSent);
 }
Ejemplo n.º 12
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');
 }
Ejemplo n.º 13
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;
 }
 /**
  * add attachments to mail
  *
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Message $_message
  * @throws Felamimail_Exception_IMAP
  */
 protected function _addAttachments(Tinebase_Mail $_mail, Felamimail_Model_Message $_message)
 {
     if (!isset($_message->attachments) || empty($_message->attachments)) {
         return;
     }
     $maxAttachmentSize = $this->_getMaxAttachmentSize();
     $totalSize = 0;
     foreach ($_message->attachments as $attachment) {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding attachment: ' . (is_object($attachment) ? print_r($attachment->toArray(), TRUE) : print_r($attachment, TRUE)));
         }
         if (isset($attachment['type']) && $attachment['type'] == Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 && $_message->original_id instanceof Felamimail_Model_Message) {
             $part = $this->_getRfc822Attachment($attachment, $_message);
         } else {
             if ($attachment instanceof Tinebase_Model_TempFile || isset($attachment['tempFile'])) {
                 $part = $this->_getTempFileAttachment($attachment);
             } else {
                 $part = $this->_getMessagePartAttachment($attachment);
             }
         }
         if (!$part || empty($attachment['type'])) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Skipping attachment ' . print_r($attachment, true));
             }
             continue;
         }
         $part->setTypeAndDispositionForAttachment($attachment['type'], $attachment['name']);
         if (!empty($attachment['size'])) {
             $totalSize += $attachment['size'];
         }
         if ($totalSize > $maxAttachmentSize) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Current attachment size: ' . Tinebase_Helper::convertToMegabytes($totalSize) . ' MB / allowed size: ' . Tinebase_Helper::convertToMegabytes($maxAttachmentSize) . ' MB');
             }
             throw new Felamimail_Exception_IMAP('Maximum attachment size exceeded. Please remove one or more attachments.');
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding attachment ' . $part->type);
         }
         $_mail->addAttachment($part);
     }
 }
Ejemplo n.º 15
0
 /**
  * this function generates the response for the client
  * 
  * @return void
  */
 public function getResponse()
 {
     $mail = Tinebase_Mail::createFromZMM($this->_incomingMessage);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " saveInSent: " . (int) $this->_saveInSent);
     }
     Felamimail_Controller_Message_Send::getInstance()->sendZendMail($this->_account, $mail, $this->_saveInSent);
 }
 /**
  * @see 0011556: sending mails to multiple recipients fails
  */
 public function testParseAdresslist()
 {
     $addressesString = 'abc@example.org, abc2@example.org';
     $addresses = Tinebase_Mail::parseAdresslist($addressesString);
     $this->assertEquals(array(array('name' => null, 'address' => '*****@*****.**'), array('name' => null, 'address' => '*****@*****.**')), $addresses, print_r($addresses, true));
 }
 /**
  * test conversion from plain text to html (quotes ('> > ...') to blockquotes)
  * 
  * @see 0005334: convert plain text quoting ("> ") to html blockquotes
  */
 public function testTextToHtml()
 {
     $plaintextMessage = "blabla\n" . "> lalülüüla\n" . "> \n" . "> > >lala\n" . ">  >\n" . ">  > xyz\n" . "\n\n" . "> jojo\n" . "jojo\n";
     $result = Tinebase_Mail::convertFromTextToHTML($plaintextMessage, 'felamimail-body-blockquote');
     $this->assertEquals('blabla<br /><blockquote class="felamimail-body-blockquote">lalülüüla<br /><br />' . '<blockquote class="felamimail-body-blockquote"><blockquote class="felamimail-body-blockquote">lala<br />' . '</blockquote><br />xyz<br /></blockquote></blockquote><br /><br /><blockquote class="felamimail-body-blockquote">jojo<br /></blockquote>jojo<br />', $result);
 }
 /**
  * Send the reading confirmation in a message who has the correct header and is not seen yet
  *
  * @return void
  */
 public function sendReadingConfirmation()
 {
     if (!is_array($this->headers)) {
         $this->headers = Felamimail_Controller_Message::getInstance()->getMessageHeaders($this->getId(), NULL, TRUE);
     }
     if ((isset($this->headers['disposition-notification-to']) || array_key_exists('disposition-notification-to', $this->headers)) && $this->headers['disposition-notification-to']) {
         $translate = Tinebase_Translation::getTranslation($this->_application);
         $from = Felamimail_Controller_Account::getInstance()->get($this->account_id);
         $message = new Felamimail_Model_Message();
         $message->account_id = $this->account_id;
         $punycodeConverter = Felamimail_Controller_Message::getInstance()->getPunycodeConverter();
         $to = Felamimail_Message::convertAddresses($this->headers['disposition-notification-to'], $punycodeConverter);
         if (empty($to)) {
             throw new Felamimail_Exception('disposition-notification-to header does not contain a valid email address');
         }
         $message->content_type = Felamimail_Model_Message::CONTENT_TYPE_HTML;
         $message->to = $to[0]['email'];
         $message->subject = $translate->_('Reading Confirmation:') . ' ' . $this->subject;
         $message->body = $translate->_('Your message:') . ' ' . $this->subject . "\n" . $translate->_('Received on') . ' ' . $this->received . "\n" . $translate->_('Was read by:') . ' ' . $from->from . ' <' . $from->email . '> ' . $translate->_('on') . ' ' . date('Y-m-d H:i:s');
         $message->body = Tinebase_Mail::convertFromTextToHTML($message->body, 'felamimail-body-blockquote');
         Felamimail_Controller_Message_Send::getInstance()->sendMessage($message);
     }
 }
 /**
  * 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)');
 }