From: Michael M Slusarz Date: Thu, 12 Nov 2009 22:33:08 +0000 (-0700) Subject: Add way for Mime Viewers to display 'preview' information if the inline size is exceeded X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f536372c8a76dd627fc70fe2435bb8da4cd77928;p=horde.git Add way for Mime Viewers to display 'preview' information if the inline size is exceeded --- diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index fef549982..f5d35eae9 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -424,17 +424,27 @@ class IMP_Contents case self::RENDER_INLINE_DISP_NO: $textmode = 'inline'; $limit = $viewer->getConfigParam('limit_inline_size'); + if ($limit && ($mime_part->getBytes() > $limit)) { + $data = ''; + $status = array( + _("This message part cannot be viewed because it is too large."), + sprintf(_("Click %s to download the data."), $this->linkView($mime_part, 'download_attach', _("HERE"))) + ); + + if (method_exists($viewer, 'overLimitText')) { + $data = $viewer->overLimitText(); + $status[] = _("The initial portion of this text part is displayed below."); + } + return array( $mime_id => array( - 'data' => '', + 'data' => $data, 'name' => '', 'status' => array( array( - 'text' => array( - _("This message part cannot be viewed because it is too large."), - sprintf(_("Click %s to download the data."), $this->linkView($mime_part, 'download_attach', _("HERE"))) - ) + 'icon' => Horde::img('alerts/warning.png', _("Warning"), null, $GLOBALS['registry']->getImageDir('horde')), + 'text' => $status ) ), 'type' => 'text/html; charset=' . Horde_Nls::getCharset() diff --git a/imp/lib/Mime/Viewer/Plain.php b/imp/lib/Mime/Viewer/Plain.php index 381c53c80..7424e74d1 100644 --- a/imp/lib/Mime/Viewer/Plain.php +++ b/imp/lib/Mime/Viewer/Plain.php @@ -303,4 +303,29 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain return $new_part; } + /** + * Output to use if text size is over the limit. + * See IMP_Contents::renderMIMEPart(). + * + * @return string The text to display inline. + */ + public function overLimitText() + { + $stream = $this->_mimepart->getContents(array('stream' => true)); + rewind($stream); + + // Escape text + $filters = array( + 'text2html' => array( + 'parselevel' => Horde_Text_Filter_Text2html::MICRO, + 'charset' => Horde_Nls::getCharset() + ), + 'tabs2spaces' => array(), + ); + + return '
' . + Horde_Text_Filter::filter(Horde_String::convertCharset(fread($stream, 1024), $this->_mimepart->getCharset()), array_keys($filters), array_values($filters)) . + ' [...]
'; + } + }