Skip to content

Commit

Permalink
More BODYPART fixes.
Browse files Browse the repository at this point in the history
Possibly related to Bug: 13729
  • Loading branch information
mrubinsk committed Dec 16, 2014
1 parent 92508f1 commit 4e2f399
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
13 changes: 12 additions & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Imap/Adapter.php
Expand Up @@ -1267,7 +1267,11 @@ protected function _buildHtmlPart(array $body_data, array $options, &$message)
} else {
$message->type = Horde_ActiveSync::BODYPREF_TYPE_HTML;
}
if (!empty($body_data['html']['estimated_size'])) {

if ($message instanceof Horde_ActiveSync_Message_AirSyncBaseBodypart) {
$message->data = $body_data['bodyparthtml']['body']->stream;
$message->truncated = $body_data['bodyparthtml']['truncated'];
} elseif (!empty($body_data['html']['estimated_size'])) {
$message->estimateddatasize = $body_data['html']['estimated_size'];
$message->truncated = $body_data['html']['truncated'];
$message->data = $body_data['html']['body']->stream;
Expand Down Expand Up @@ -1596,6 +1600,13 @@ protected function _validateMessageBodyData($data)
stream_filter_remove($filter_h);
$data['html']['body'] = $stream;
}
if (!empty($data['bodyparthtml'])) {
$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['bodyparthtml']['body'], $data['bodyparthtml']['charset']), true);
stream_filter_remove($filter_h);
$data['bodyparthtml']['body'] = $stream;
}

return $data;
}
Expand Down
23 changes: 22 additions & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Imap/Message.php
Expand Up @@ -222,7 +222,8 @@ public function getMessageBodyData(array $options = array())
// Deduce which part(s) we need to request.
$want_html_text = $version >= Horde_ActiveSync::VERSION_TWELVE &&
(!empty($options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]) ||
!empty($options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]));
!empty($options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]) ||
!empty($options['bodypartprefs']));

$want_plain_text = $version == Horde_ActiveSync::VERSION_TWOFIVE ||
empty($options['bodyprefs']) ||
Expand Down Expand Up @@ -325,6 +326,7 @@ public function getMessageBodyData(array $options = array())
$html_body_part->setContents($html);
$html = $html_body_part->getContents();
}
$html_original = $html;

// Size of the original HTML part.
$html_size = !is_null($data->getBodyPartSize($html_id))
Expand Down Expand Up @@ -353,6 +355,25 @@ public function getMessageBodyData(array $options = array())
}
}

// Bodypart?
if (!empty($options['bodypartprefs'])) {
if (!empty($options['bodypartprefs']['truncationsize'])) {
$html_bp = Horde_String::substr(
$html_original,
0,
$options['bodypartprefs']['truncationsize'],
$html_charset);
} else {
$html_bp = $html_original;
}
$return['bodyparthtml'] = array(
'charset' => $html_charset,
'body' => $html_bp,
'truncated' => $html_size > Horde_String::length($html_bp),
'size' => $html_size
);
}

// Was the part truncated?
$truncated = $html_size > Horde_String::length($html);

Expand Down

0 comments on commit 4e2f399

Please sign in to comment.