/** * get and decode message body * * @param Expressomail_Model_Message $_message * @param string $_partId * @param string $_contentType * @param Expressomail_Model_Account $_account * @return string * * @todo multipart_related messages should deliver inline images */ protected function _getAndDecodeMessageBody(Expressomail_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) { if ($partStructure['disposition']['type'] == 'ATTACHMENT') { continue; } $bodyPart = $this->getMessagePart($_message, $partId, TRUE, $partStructure); $body = $this->_getDecodedBodyContent($bodyPart, $partStructure); if ($partStructure['contentType'] != Zend_Mime::TYPE_TEXT && $partStructure['contentType'] != Expressomail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822) { $bodyCharCountBefore = strlen($body); $body = $this->_getDecodedBodyImages($_message->getId(), $body); $body = $this->_purifyBodyContent($body); $body = Expressomail_Message::linkify($body); $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.'); } return $this->_getAndDecodeMessageBody($_message, $_message->text_partid, Zend_Mime::TYPE_TEXT, $_account); } } else { if ($partStructure['contentType'] === Expressomail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822) { $partContent = $this->_getPartContent($_message, $partId, $partStructure); $translate = Tinebase_Translation::getTranslation('Expressomail'); $body .= "\n\n----- " . $translate->_('Returned Message Content') . " -----\n" . $partContent; } $body = '<pre class="message-viewer">' . $body . '</pre>'; } if (!($_account !== NULL && $_account->display_format === Expressomail_Model_Account::DISPLAY_CONTENT_TYPE && $bodyPart->type == Zend_Mime::TYPE_TEXT)) { //$body = Expressomail_Message::convertContentType($partStructure['contentType'], $_contentType, $body); if ($bodyPart->type == Zend_Mime::TYPE_TEXT && $_contentType == Zend_Mime::TYPE_HTML) { $body = Expressomail_Message::replaceUris($body); //$body = Expressomail_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); } } // Use only Expressomail to send e-mails $body = Expressomail_Message::replaceEmails($body); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding part ' . $partId . ' to message body.'); } $messageBody .= $body; } return $messageBody; }
/** * Get multipart report notification message body * * @param Expressomail_Model_Message $_message * @return string Expressomail_Model_MessageDispositionNotificationPart->getHTMLFormatted $_mdnMessage */ private function _getMultipartReportNotificationMessageBody(Expressomail_Model_Message $_message, $_partId, $_contentType, $_account = NULL) { $_structure = $_message->getPartStructure($_partId); $_bodyParts = $_message->getBodyParts($_structure, $_contentType); // test if we have all the parts if (empty($_bodyParts) || count($_bodyParts) < 2 || count($_bodyParts) > 3 || !isset($_bodyParts[2]['contentType']) && $_bodyParts[2]['contentType'] !== Expressomail_Model_Message::CONTENT_TYPE_MESSAGE_DISPOSITION_NOTIFICATION) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Malformed MDN Message.'); return ''; } // MDN message assembly needs 2 original message parts to handle //First is part 2 to get original message send data $_bodyPart = $this->getMessagePart($_message, 2, FALSE, $_structure); //Second is part 1 to get SIEVE automatic message data $_bodyPart2 = $this->getMessagePart($_message, 1, FALSE, $_structure); $_mdnMessage = new Expressomail_Model_MessageDispositionNotificationPart($this->_getDecodedBodyContent($_bodyPart, $_structure)); $_mdnSieve = new Expressomail_Model_MessageDispositionNotificationPart($this->_getDecodedBodyContent($_bodyPart2, $_structure)); $_userMessage = $_mdnSieve->getCustomMessage(); //Put them together to assebly user friendly message return $_mdnMessage->getHTMLFormatted($_userMessage); }