/**
  * testReplaceUris
  * 
  * @see 0008020: link did not get an anchor in html mail
  */
 public function testReplaceUrisAndMails()
 {
     $message = new Felamimail_Model_Message(array('body' => 'http://www.facebook.com/media/set/?set=a.164136103742229.1073741825.100004375207149&type=1&l=692e495b17' . " Klicken Sie bitte noch auf den folgenden Link, um Ihre Teilnahme zu bestätigen:\n" . 'http://www.kieler-linuxtage.de/vortragsplaner/wsAnmeldung.php?fkt=best&wsID=111&code=xxxx&eMail=abc@efh.com'));
     $result = Felamimail_Message::replaceUris($message->body);
     $result = Felamimail_Message::replaceEmails($result);
     $this->assertContains('a href="http://www.facebook.com/media/set/', $result);
     $this->assertContains('a href="http://www.kieler-linuxtage.de/', $result);
     $this->assertContains('eMail=abc@efh.com', $result);
 }
 /**
  * parse headers and set 'date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender' fields
  * 
  * @param array $_headers
  * @return void
  */
 public function parseHeaders(array $_headers)
 {
     // remove duplicate headers (which can't be set twice in real life)
     foreach (array('date', 'from', 'subject', 'sender') as $field) {
         if (isset($_headers[$field]) && is_array($_headers[$field])) {
             $_headers[$field] = $_headers[$field][0];
         }
     }
     // @see 0008644: error when sending mail with note (wrong charset)
     $this->subject = isset($_headers['subject']) ? Tinebase_Core::filterInputForDatabase(Felamimail_Message::convertText($_headers['subject'])) : null;
     if (isset($_headers['date']) || array_key_exists('date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['date']);
     } elseif (isset($_headers['resent-date']) || array_key_exists('resent-date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['resent-date']);
     }
     $punycodeConverter = Felamimail_Controller_Message::getInstance()->getPunycodeConverter();
     foreach (array('to', 'cc', 'bcc', 'from', 'sender') as $field) {
         if (isset($_headers[$field])) {
             if (is_array($_headers[$field])) {
                 $value = array();
                 foreach ($_headers[$field] as $headerValue) {
                     $value = array_merge($value, Felamimail_Message::convertAddresses($headerValue, $punycodeConverter));
                 }
                 $this->{$field} = $value;
             } else {
                 $value = Felamimail_Message::convertAddresses($_headers[$field], $punycodeConverter);
                 switch ($field) {
                     case 'from':
                         $this->from_email = isset($value[0]) && (isset($value[0]['email']) || array_key_exists('email', $value[0])) ? $value[0]['email'] : '';
                         $this->from_name = isset($value[0]) && (isset($value[0]['name']) || array_key_exists('name', $value[0])) && !empty($value[0]['name']) ? $value[0]['name'] : $this->from_email;
                         break;
                     case 'sender':
                         $this->sender = isset($value[0]) && (isset($value[0]['email']) || array_key_exists('email', $value[0])) ? '<' . $value[0]['email'] . '>' : '';
                         if (isset($value[0]) && (isset($value[0]['name']) || array_key_exists('name', $value[0])) && !empty($value[0]['name'])) {
                             $this->sender = '"' . $value[0]['name'] . '" ' . $this->sender;
                         }
                         break;
                     default:
                         $this->{$field} = $value;
                 }
             }
         }
     }
 }
Beispiel #3
0
 /**
  * create new message for the cache
  * 
  * @param array $_message
  * @param Felamimail_Model_Folder $_folder
  * @return Felamimail_Model_Message
  */
 protected function _createModelMessage(array $_message, Felamimail_Model_Folder $_folder = NULL)
 {
     // Optimization!!!
     if ($_folder == NULL) {
         if (isset($_message['folder_id'])) {
             $_folder = array_key_exists($_message['folder_id'], $this->_folderMap) ? $this->_folderMap[$_message['folder_id']] : ($this->_folderMap[$_message['folder_id']] = Felamimail_Controller_Folder::getInstance()->get($_message['folder_id']));
         } else {
             return NULL;
         }
     }
     $message = new Felamimail_Model_Message(array('id' => self::createMessageId($_folder->account_id, $_folder->getId(), $_message['uid']), 'account_id' => $_folder->account_id, 'messageuid' => $_message['uid'], 'folder_id' => $_folder->getId(), 'timestamp' => Tinebase_DateTime::now(), 'received' => Felamimail_Message::convertDate($_message['received']), 'size' => $_message['size'], 'flags' => $_message['flags']), true);
     $message->parseStructure($_message['structure']);
     $message->parseHeaders($_message['header']);
     $message->fixToListModel();
     $message->parseBodyParts();
     $message->parseSmime($_message['structure']);
     $attachments = Felamimail_Controller_Message::getInstance()->getAttachments($message);
     $message->has_attachment = count($attachments) > 0 ? true : false;
     return $message;
 }
 /**
  * set mail body
  * 
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Message $_message
  */
 protected function _setMailBody(Tinebase_Mail $_mail, Felamimail_Model_Message $_message)
 {
     if ($_message->content_type == Felamimail_Model_Message::CONTENT_TYPE_HTML) {
         $_mail->setBodyHtml(Felamimail_Message::addHtmlMarkup($_message->body));
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyHtml(TRUE));
         }
     }
     $plainBodyText = $_message->getPlainTextBody();
     $_mail->setBodyText($plainBodyText);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyText(TRUE));
     }
 }
 /**
  * create new message for the cache
  * 
  * @param array $_message
  * @param Felamimail_Model_Folder $_folder
  * @return Felamimail_Model_Message
  */
 protected function _createMessageToCache(array $_message, Felamimail_Model_Folder $_folder)
 {
     $message = new Felamimail_Model_Message(array('account_id' => $_folder->account_id, 'messageuid' => $_message['uid'], 'folder_id' => $_folder->getId(), 'timestamp' => Tinebase_DateTime::now(), 'received' => Felamimail_Message::convertDate($_message['received']), 'size' => $_message['size'], 'flags' => $_message['flags']));
     $message->parseStructure($_message['structure']);
     $message->parseHeaders($_message['header']);
     $message->parseBodyParts();
     $attachments = $this->getAttachments($message);
     $message->has_attachment = count($attachments) > 0 ? true : false;
     return $message;
 }
 /**
  * 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;
 }
 /**
  * convert signature to text to remove all html tags and spaces/linebreaks, if the remains are empty -> set empty signature
  * 
  * @param Felamimail_Model_Account $account
  */
 protected function _checkSignature($account)
 {
     if (empty($account->signature)) {
         return;
     }
     $plainTextSignature = Felamimail_Message::convertFromHTMLToText($account->signature, "\n");
     if (!preg_match('/[^\\s^\\n]/', $plainTextSignature, $matches)) {
         $account->signature = '';
     }
 }
Beispiel #8
0
 /**
  * returns message prepared for json transport
  * - overwriten to convert recipients to array
  *
  * @param Tinebase_Record_Interface $_record
  * @return array record data
  */
 protected function _recordToJson($_record)
 {
     if ($_record instanceof Felamimail_Model_Message) {
         foreach (array('to', 'cc', 'bcc') as $type) {
             if (!is_array($_record->{$type})) {
                 if (!empty($_record->{$type})) {
                     $exploded = explode(',', $_record->{$type});
                     $_record->{$type} = $exploded;
                 } else {
                     $_record->{$type} = array();
                 }
             }
         }
         if ($_record->preparedParts instanceof Tinebase_Record_RecordSet) {
             foreach ($_record->preparedParts as $preparedPart) {
                 if ($preparedPart->preparedData instanceof Calendar_Model_iMIP) {
                     try {
                         $iMIPFrontend = new Calendar_Frontend_iMIP();
                         $iMIPFrontend->prepareComponent($preparedPart->preparedData);
                     } catch (Exception $e) {
                         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not prepare calendar iMIP component: ' . $e->getMessage());
                         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
                         }
                     }
                 }
             }
         }
     } else {
         if ($_record instanceof Felamimail_Model_Account) {
             // add usernames (imap + smtp)
             $_record->resolveCredentials();
             $_record->resolveCredentials(TRUE, FALSE, TRUE);
         } else {
             if ($_record instanceof Felamimail_Model_Sieve_Vacation) {
                 if (!$_record->mime) {
                     $_record->reason = Felamimail_Message::convertFromTextToHTML($_record->reason);
                 }
             }
         }
     }
     return parent::_recordToJson($_record);
 }
Beispiel #9
0
 /**
  * parse headers and set 'date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender' fields
  * 
  * @param array $_headers
  * @return void
  */
 public function parseHeaders(array $_headers)
 {
     // remove duplicate headers (which can't be set twice in real life)
     foreach (array('date', 'from', 'to', 'cc', 'bcc', 'subject', 'sender') as $field) {
         if (isset($_headers[$field]) && is_array($_headers[$field])) {
             $_headers[$field] = $_headers[$field][0];
         }
     }
     $this->importance = isset($_headers['importance']) && $_headers['importance'] === 'high' ? true : false;
     $this->subject = isset($_headers['subject']) ? Felamimail_Message::convertText($_headers['subject']) : null;
     if (array_key_exists('date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['date']);
     } elseif (array_key_exists('resent-date', $_headers)) {
         $this->sent = Felamimail_Message::convertDate($_headers['resent-date']);
     }
     $punycodeConverter = Felamimail_Controller_Message::getInstance()->getPunycodeConverter();
     foreach (array('to', 'cc', 'bcc', 'from', 'sender') as $field) {
         if (isset($_headers[$field])) {
             $value = Felamimail_Message::convertAddresses($_headers[$field], $punycodeConverter);
             switch ($field) {
                 case 'from':
                     $this->from_email = isset($value[0]) && array_key_exists('email', $value[0]) ? $value[0]['email'] : '';
                     $this->from_name = isset($value[0]) && array_key_exists('name', $value[0]) && !empty($value[0]['name']) ? $value[0]['name'] : $this->from_email;
                     break;
                 case 'sender':
                     $this->sender = isset($value[0]) && array_key_exists('email', $value[0]) ? '<' . $value[0]['email'] . '>' : '';
                     if (isset($value[0]) && array_key_exists('name', $value[0]) && !empty($value[0]['name'])) {
                         $this->sender = '"' . $value[0]['name'] . '" ' . $this->sender;
                     }
                     break;
                 default:
                     $this->{$field} = $value;
             }
         }
     }
 }
Beispiel #10
0
 /**
  * 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 = Felamimail_Message::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;
 }
Beispiel #11
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;
 }
 /**
  * Compare order of Felamimail_Model_Message acording to Tinebase_Model_Pagination
  * @param Felamimail_Model_Message $msg1
  * @param Felamimail_Model_Message $msg2
  * @return int 
  * 
  * @todo Convert int security value in Expresso_Smime to corresponding string type
  */
 public function compare($msg1, $msg2)
 {
     switch ($this->_pagination->sort) {
         case 'received':
             // Integer
             $value1 = $msg1[$this->_pagination->sort];
             $value2 = $msg2[$this->_pagination->sort];
         case 'sent':
             // Integer
             $value1 = isset($value1) ? $value1 : $msg1['header']['date'];
             $value2 = isset($value2) ? $value2 : $msg2['header']['date'];
             $value1 = intval(Felamimail_Message::convertDate($value1)->format("U"));
             $value2 = intval(Felamimail_Message::convertDate($value2)->format("U"));
         case 'size':
             // Integer
             $value1 = isset($value1) ? $value1 : intval($msg1[$this->_pagination->sort]);
             $value2 = isset($value2) ? $value2 : intval($msg2[$this->_pagination->sort]);
             return $this->compareIntegers($value1, $value2);
         case 'folder_id':
             // Strings
             $folders = array();
             $translate = Tinebase_Translation::getTranslation('Felamimail');
             foreach (array($msg1, $msg2) as $msg) {
                 $folder = Felamimail_Backend_Cache_Imap_Folder::decodeFolderUid($msg[$this->_pagination->sort]);
                 // Optimization! Only create the account object once for every sort operation.
                 $account = array_key_exists($folder['accountId'], $this->_accountMap) ? $this->_accountMap[$folder['accountId']] : ($this->_accountMap[$folder['accountId']] = Felamimail_Controller_Account::getInstance()->get($folder['accountId']));
                 $aux1 = explode('/', $folder['globalName']);
                 $aux2 = '';
                 foreach ($aux1 as $value) {
                     $aux2 .= $translate->_($value) . '/';
                 }
                 $folders[] = $account->name . '/' . substr($aux2, 0, strlen($aux2) - 1);
             }
             list($value1, $value2) = $folders;
             //TODO: Should use a static method implemented on Model_Message or Expresso_Smime
         //TODO: Should use a static method implemented on Model_Message or Expresso_Smime
         case 'smime':
             $value1 = isset($value1) ? $value1 : $this->processSmimeValue($msg1['structure']);
             $value2 = isset($value2) ? $value2 : $this->processSmimeValue($msg2['structure']);
         case 'flags':
             // Strings
             if (!isset($value1)) {
                 sort($msg1['flags']);
                 $value1 = implode(',', $msg1['flags']);
             }
             if (!isset($value2)) {
                 sort($msg2['flags']);
                 $value2 = implode(',', $msg2['flags']);
             }
         case 'subject':
             // Strings
             $value1 = isset($value1) ? $value1 : $msg1['header'][$this->_pagination->sort];
             $value2 = isset($value2) ? $value2 : $msg2['header'][$this->_pagination->sort];
         case 'id':
             // Strings
             $value1 = isset($value1) ? $value1 : $msg1[$this->_pagination->sort];
             $value2 = isset($value2) ? $value2 : $msg2[$this->_pagination->sort];
             return $this->compareStrings($value1, $value2);
         case 'sender':
         case 'to':
         case 'from_name':
         case 'from_email':
             // Strings
             list($header, $field) = explode('_', $this->_pagination->sort);
             $field = empty($field) ? 'email' : $field;
             $address1 = Felamimail_Message::convertAddresses($msg1['header'][$header]);
             $address2 = Felamimail_Message::convertAddresses($msg2['header'][$header]);
             return $this->compareStrings(isset($address1[0]) && array_key_exists($field, $address1[0]) ? $address1[0][$field] : '', isset($address2[0]) && array_key_exists($field, $address2[0]) ? $address2[0][$field] : '');
     }
 }
Beispiel #13
0
 /**
  * convert to plaintext
  * 
  * @param string $_string
  */
 protected function _getPlaintext($_string)
 {
     return Felamimail_Message::convertContentType(Zend_Mime::TYPE_HTML, Zend_Mime::TYPE_TEXT, $_string);
 }
Beispiel #14
0
 /**
  * get and decode message body
  * 
  * @param Felamimail_Model_Message $_message
  * @param string $_partId
  * @param string $_contentType
  * @param Felamimail_Model_Account $_account
  * @return string
  */
 protected function _getAndDecodeMessageBody(Felamimail_Model_Message $_message, $_partId, $_contentType, $_account = NULL)
 {
     $structure = $_message->getPartStructure($_partId);
     $bodyParts = $_message->getBodyParts($structure, $_contentType);
     if (empty($bodyParts)) {
         return '';
     }
     $messageBody = '';
     foreach ($bodyParts as $partId => $partStructure) {
         $bodyPart = $this->getMessagePart($_message, $partId, TRUE);
         $body = $this->_getDecodedBodyContent($bodyPart, $partStructure);
         if ($partStructure['contentType'] != Zend_Mime::TYPE_TEXT) {
             $body = $this->_getDecodedBodyImages($_message->getId(), $body);
             $body = $this->_purifyBodyContent($body);
         }
         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::replaceUriAndSpaces($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);
             }
         }
         $messageBody .= $body;
     }
     return $messageBody;
 }
Beispiel #15
0
 /**
  * set mail body
  * 
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Message $_message
  */
 protected function _setMailBody(Tinebase_Mail $_mail, Felamimail_Model_Message $_message)
 {
     if ($_message->content_type == Felamimail_Model_Message::CONTENT_TYPE_HTML) {
         // checking embedded images
         $embeddedImages = $_mail->processEmbeddedImagesInHtmlBody($_message->body);
         // now checking embedded signature base64 image
         $base64Images = $_mail->processEmbeddedImageSignatureInHtmlBody($_message->body);
         if (count($embeddedImages) > 0) {
             $_message->body = str_ireplace('src="index.php?method=Felamimail.showTempImage&amp;tempImageId=', 'src="cid:', $_message->body);
         }
         if (count($base64Images) > 0) {
             // there should be only one image in the signature
             $signature_cid = $_mail->createCid($base64Images[0][1]);
             $_message->body = preg_replace('/<img id="user-signature-image" alt="[^\\"]+" src="data:image\\/jpeg;base64,[^"]+">/', '<img id="user-signature-image" src="cid:' . $signature_cid . '"/>', $_message->body);
         }
         $_mail->setBodyHtml(Felamimail_Message::addHtmlMarkup($_message->body));
         if (count($embeddedImages) > 0) {
             foreach ($embeddedImages as $embeddedImage) {
                 $file = Tinebase_Core::getTempDir() . '/' . $embeddedImage[1];
                 $image = file_get_contents($file);
                 $_mail->createHtmlRelatedAttachment($image, $embeddedImage[1], 'image/jpg', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $embeddedImage[0]);
             }
         }
         if (count($base64Images) > 0) {
             // again, there should be only one image in the signature
             $image = base64_decode($base64Images[0][1]);
             $_mail->createHtmlRelatedAttachment($image, $signature_cid, 'image/jpg', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $base64Images[0][0]);
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyHtml(TRUE));
         }
     }
     $plainBodyText = $_message->getPlainTextBody();
     $_mail->setBodyText($plainBodyText);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyText(TRUE));
     }
 }