const RENDER_INLINE = 2;
const RENDER_INLINE_DISP_NO = 4;
const RENDER_INFO = 8;
+ const RENDER_INLINE_AUTO = 16;
/**
* The IMAP index of the message.
* Render a MIME Part.
*
* @param string $mime_id The MIME ID to render.
- * @param string $mode Either 'full', 'inline', 'info', or
- * 'inlineauto' ('inline' and, if not available,
- * then 'info').
+ * @param integer $mode One of the RENDER_ constants.
* @param array $options Additional options:
* <pre>
* 'params' - (array) Additional params to set.
$viewer->setParams($options['params']);
}
- $ret = $viewer->render(($mode == 'inlineauto') ? 'inline' : $mode);
+ switch ($mode) {
+ case self::RENDER_FULL:
+ $textmode = 'full';
+ break;
+
+ case self::RENDER_INLINE:
+ case self::RENDER_INLINE_AUTO:
+ case self::RENDER_INLINE_DISP_NO:
+ $textmode = 'inline';
+ break;
+
+ case self::RENDER_INFO:
+ $textmode = 'info';
+ break;
+ }
+
+ $ret = $viewer->render($textmode);
if (empty($ret)) {
- return ($mode == 'inlineauto')
- ? $this->renderMIMEPart($mime_id, 'info', $options)
+ return ($mode == self::RENDER_INLINE_AUTO)
+ ? $this->renderMIMEPart($mime_id, self::RENDER_INLINE_INFO, $options)
: array();
}
* Can this MIME part be displayed in the given mode?
*
* @param mixed $id The MIME part or a MIME ID string.
- * @param integer $mask The masks to search for.
+ * @param integer $mask One of the RENDER_ constants.
* @param string $type The type to use (overrides the MIME Id if $id is
* a MIME part).
*
}
$viewer = Horde_Mime_Viewer::factory($part, $type);
+ if ($mask & self::RENDER_INLINE_AUTO) {
+ $mask |= self::RENDER_INLINE | self::RENDER_INFO;
+ }
+
if (($mask & self::RENDER_FULL) && $viewer->canRender('full')) {
return self::RENDER_FULL;
}
$render_part = $this->_mimepart->getPart($disp_id);
foreach (array_keys($render_part->contentTypeMap()) as $val) {
if (isset($display_ids[$val])) {
- $render = $this->_params['contents']->renderMIMEPart($val, 'inline', array('params' => $this->_params));
+ $render = $this->_params['contents']->renderMIMEPart($val, IMP_Contents::RENDER_INLINE, array('params' => $this->_params));
foreach (array_keys($render) as $id) {
$ret[$id] = $render[$id];
unset($display_ids[$id]);
/* If this is a straight message/disposition-notification part, just
* output the text. */
if ($this->_mimepart->getType() == 'message/disposition-notification') {
- return $this->_params['contents']->renderMIMEPart($this->_mimepart->getMIMEId(), 'full', array('type' => 'text/plain', 'params' => $this->_params));
+ return $this->_params['contents']->renderMIMEPart($this->_mimepart->getMIMEId(), IMP_Contents::RENDER_FULL, array('type' => 'text/plain', 'params' => $this->_params));
}
return $this->_renderInfo();
/* Print the human readable message. */
$curr_id = $first_id = key($parts);
- $first_part = $this->_params['contents']->renderMIMEPart($curr_id, 'inlineauto', array('params' => $this->_params));
+ $first_part = $this->_params['contents']->renderMIMEPart($curr_id, IMP_Contents::RENDER_INLINE_AUTO, array('params' => $this->_params));
/* Display a link to more detailed message. */
$curr_id = Horde_Mime::mimeIdArithmetic($curr_id, 'next');
$part = $this->_params['contents']->getMIMEPart($curr_id);
if ($part) {
- $status[0]['text'][] = sprintf(_("Additional information can be viewed %s."), $this->_params['contents']->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("Additional information details"), 'params' => array('mode' => 'inline'))));
+ $status[0]['text'][] = sprintf(_("Additional information can be viewed %s."), $this->_params['contents']->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("Additional information details"), 'params' => array('mode' => IMP_Contents::RENDER_INLINE))));
}
/* Display a link to the sent message. Try to download the text of
}
}
- $render = $this->_params['contents']->renderMIMEPart($id, $inline ? 'inline' : 'full', array('params' => array_merge($this->_params, array('related_id' => $id, 'related_cids' => $cids))));
+ $render = $this->_params['contents']->renderMIMEPart($id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL, array('params' => array_merge($this->_params, array('related_id' => $id, 'related_cids' => $cids))));
foreach (array_keys($render) as $val) {
$ret[$val] = $render[$val];
continue;
}
- $render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO);
- if ($render_mode & IMP_Contents::RENDER_INLINE) {
- $type = 'inline';
- } elseif ($render_mode & IMP_Contents::RENDER_INFO) {
- $type = 'info';
- } else {
+ if (!($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) {
if (!$show_all_parts && $imp_contents->isAttachment($mime_type)) {
$atc_parts[] = $mime_id;
}
continue;
}
- $render_part = $imp_contents->renderMIMEPart($mime_id, $type);
- if (($type == 'inline') && empty($render_part)) {
+ $render_part = $imp_contents->renderMIMEPart($mime_id, $render_mode);
+ if (($render_mode & IMP_Contents::RENDER_INLINE) && empty($render_part)) {
/* This meant that nothing was rendered - allow this part to appear
* in the attachment list instead. */
if (!$show_all_parts) {
$contents = &IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
$mime_id = $contents->findBody();
if ($contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE)) {
- $curr_msg['body'] = $contents->renderMIMEPart($mime_id);
+ $curr_msg['body'] = $contents->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE);
} else {
$curr_msg['body'] = '<em>' . _("There is no text that can be displayed inline.") . '</em>';
}
break;
case 'download_render':
- $render = $contents->renderMIMEPart($id, Util::getFormData('mode', 'full'), array('type' => $ctype));
+ $render = $contents->renderMIMEPart($id, Util::getFormData('mode', IMP_Contents::RENDER_FULL), array('type' => $ctype));
$body = $render[$id]['data'];
$type = $render[$id]['type'];
$name = $render[$id]['name'];
exit;
case 'view_attach':
- $render = $contents->renderMIMEPart($id, Util::getFormData('mode', 'full'), array('type' => $ctype));
+ $render = $contents->renderMIMEPart($id, Util::getFormData('mode', IMP_Contents::RENDER_FULL), array('type' => $ctype));
$browser->downloadHeaders($render[$id]['name'], $render[$id]['type'], true, strlen($render[$id]['data']));
echo $render[$id]['data'];
exit;