Skip to content

Commit

Permalink
Revert "Simplify."
Browse files Browse the repository at this point in the history
This reverts commit d6865ea.

HOTFIX: Fix regression caused by using the Horde_Mime_Part::replaceEOL instead
of the local functionality. Need to investigate why this broke, but in the
meantime, get the functionality working again.
  • Loading branch information
mrubinsk committed Mar 11, 2014
1 parent e26c72d commit d706dd1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
34 changes: 33 additions & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Imap/Adapter.php
Expand Up @@ -905,7 +905,7 @@ protected function _buildMailMessage(
$eas_message->importance = $this->_getEASImportance($priority);

// Get the body data and ensure we have something to send.
$message_body_data =$imap_message->getMessageBodyData($options);
$message_body_data = $this->_validateMessageBodyData($imap_message->getMessageBodyData($options));

if ($version == Horde_ActiveSync::VERSION_TWOFIVE) {
$eas_message->body = $message_body_data['plain']['body']->stream;
Expand Down Expand Up @@ -1447,4 +1447,36 @@ protected function _mailboxExists($mbox)
return false;
}

/**
* Converts and validates the message body data structure.
*
* @param array $data Message body data structure.
*
* @return array The message body data structure, with the [html][body] and
* [plain][body] data converted to UTF-8, EOL normalized and
* placed in a stream.
*/
protected function _validateMessageBodyData($data)
{
//We will need the eol filter to work around PHP bug 65776.
stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol');

if (!empty($data['plain'])) {
$stream = new Horde_Stream_Temp(array('max_memory' => 1048576));
$filter_h = stream_filter_append($stream->stream, 'horde_eol', STREAM_FILTER_WRITE);
$stream->add(Horde_ActiveSync_Utils::ensureUtf8($data['plain']['body'], $data['plain']['charset']), true);
stream_filter_remove($filter_h);
$data['plain']['body'] = $stream;
}
if (!empty($data['html'])) {
$stream = new Horde_Stream_Temp(array('max_memory' => 1048576));
$filter_h = stream_filter_append($stream->stream, 'horde_eol', STREAM_FILTER_WRITE);
$stream->add(Horde_ActiveSync_Utils::ensureUtf8($data['html']['body'], $data['html']['charset']), true);
stream_filter_remove($filter_h);
$data['html']['body'] = $stream;
}

return $data;
}

}
17 changes: 5 additions & 12 deletions framework/ActiveSync/lib/Horde/ActiveSync/Imap/Message.php
Expand Up @@ -295,12 +295,8 @@ public function getMessageBodyData(array $options = array())
if (!empty($text_id) && $want_plain_text) {
$text = $data->getBodyPart($text_id);
if (!$data->getBodyPartDecode($text_id)) {
// PHP Bug 65776
$text_body_part->setContents(
$text_body_part->replaceEOL($text, Horde_Mime_Part::RFC_EOL));
$text = Horde_ActiveSync_Utils::ensureUtf8($text_body_part->getContents(), $charset);
} else {
$text = Horde_ActiveSync_Utils::ensureUtf8($text_body_part->replaceEOL($text, Horde_Mime_Part::RFC_EOL), $html_charset);
$text_body_part->setContents($text);
$text = $text_body_part->getContents();
}

$text_size = !is_null($data->getBodyPartSize($text_id))
Expand All @@ -327,11 +323,8 @@ public function getMessageBodyData(array $options = array())
if (!empty($html_id) && $want_html_text) {
$html = $data->getBodyPart($html_id);
if (!$data->getBodyPartDecode($html_id)) {
$html_body_part->setContents(
$html_body_part->replaceEOL($html, Horde_Mime_Part::RFC_EOL));
$html = Horde_ActiveSync_Utils::ensureUtf8($html_body_part->getContents(), $html_charset);
} else {
$html = Horde_ActiveSync_Utils::ensureUtf8($html_body_part->replaceEOL($html, Horde_Mime_Part::RFC_EOL), $html_charset);
$html_body_part->setContents($html);
$html = $html_body_part->getContents();
}

// Size of the original HTML part.
Expand Down Expand Up @@ -629,7 +622,7 @@ public function getPartName(Horde_Mime_Part $part, $use_descrip = false)
* @param array $options Additional options:
* - decode: (boolean) Attempt to decode the bodypart on the remote
* server. If successful, sets self::$_lastBodyPartDecode to
* the transfer encoding of the decoded data.
* the content-type of the decoded data.
* DEFAULT: No
* - length: (integer) If set, only download this many bytes of the
* bodypart from the server.
Expand Down

0 comments on commit d706dd1

Please sign in to comment.