/**
  * 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;
 }
Example #2
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;
 }