public function renderMIMEPart($mime_id, $mode, array $options = array())
{
$this->_buildMessage();
$mime_part = empty($options['mime_part']) ? $this->getMimePart($mime_id) : $options['mime_part'];
if (!$mime_part) {
return array($mime_id => null);
}
if (!empty($options['autodetect']) && ($tempfile = Horde::getTempFile()) && ($fp = fopen($tempfile, 'w')) && !is_null($contents = $mime_part->getContents(array('stream' => true)))) {
rewind($contents);
while (!feof($contents)) {
fwrite($fp, fread($contents, 65536));
}
fclose($fp);
$options['type'] = Horde_Mime_Magic::analyzeFile($tempfile, empty($GLOBALS['conf']['mime']['magic_db']) ? null : $GLOBALS['conf']['mime']['magic_db']);
}
$type = empty($options['type']) ? null : $options['type'];
$viewer = $GLOBALS['injector']->getInstance('IMP_Factory_MimeViewer')->create($mime_part, array('contents' => $this, 'type' => $type));
switch ($mode) {
case self::RENDER_INLINE:
case self::RENDER_INLINE_AUTO:
case self::RENDER_INLINE_DISP_NO:
$textmode = 'inline';
$limit = $viewer->getConfigParam('limit_inline_size');
if ($limit && $mime_part->getBytes() > $limit) {
$data = '';
$status = new IMP_Mime_Status($mime_part, array(_("This message part cannot be viewed because it is too large."), $this->linkView($mime_part, 'download_attach', _("Click to download the data."))));
$status->icon('alerts/warning.png', _("Warning"));
if (method_exists($viewer, 'overLimitText')) {
$data = $viewer->overLimitText();
$status->addText(_("The initial portion of this text part is displayed below."));
}
return array($mime_id => array('data' => $data, 'name' => '', 'status' => $status, 'type' => 'text/html; charset=' . 'UTF-8'));
}
break;
case self::RENDER_INFO:
$textmode = 'info';
break;
case self::RENDER_RAW:
$textmode = 'raw';
break;
case self::RENDER_RAW_FALLBACK:
$textmode = $viewer->canRender('raw') ? 'raw' : 'full';
break;
case self::RENDER_FULL:
default:
$textmode = 'full';
break;
}
$ret = $viewer->render($textmode);
if (empty($ret)) {
return $mode == self::RENDER_INLINE_AUTO ? $this->renderMIMEPart($mime_id, self::RENDER_INFO, $options) : array();
}
if (!empty($ret[$mime_id]) && !isset($ret[$mime_id]['name'])) {
$ret[$mime_id]['name'] = $mime_part->getName(true);
}
/* Don't show empty parts. */
if ($textmode == 'inline' && !is_null($ret[$mime_id]['data']) && !strlen($ret[$mime_id]['data']) && !isset($ret[$mime_id]['status'])) {
$ret[$mime_id] = null;
}
return $ret;
}