Render a MIME Part.
public renderMIMEPart ( string $mime_id, integer $mode, array $options = [] ) : array | ||
$mime_id | string | The MIME ID to render. |
$mode | integer | One of the RENDER_ constants. |
$options | array | Additional options: - autodetect: (boolean) Attempt to auto-detect MIME type? - mime_part: (Horde_Mime_Part) The MIME part to render. - type: (string) Use this MIME type instead of the MIME type identified in the MIME part. |
return | array | See Horde_Mime_Viewer_Base::render(). The following fields may also be present in addition to the fields defined in Horde_Mime_Viewer_Base: - attach: (boolean) Force display of this part as an attachment. - js: (array) A list of javascript commands to run after the content is displayed on screen. - name: (string) Contains the MIME name information. - wrap: (string) If present, indicates that this part, and all child parts, will be wrapped in a DIV with the given class name. |
/** * Get a MIME Part for use in creating download. * * @param string $id MIME ID. * * @return Horde_Mime_Part MIME part. */ protected function _getRawDownloadPart($id) { $mime = $this->_contents->getMIMEPart($id); if ($this->_contents->canDisplay($id, IMP_Contents::RENDER_RAW)) { $render = $this->_contents->renderMIMEPart($id, IMP_Contents::RENDER_RAW); $part = reset($render); $mime->setContents($part['data'], array('encoding' => 'binary')); } return $mime; }
/** * Get a MIME Part for use in creating download. * * @param string $id MIME ID. * * @return Horde_Mime_Part MIME part, or null on error. */ protected function _getRawDownloadPart($id) { if (!($mime = $this->_contents->getMimePart($id))) { return null; } if ($this->_contents->canDisplay($id, IMP_Contents::RENDER_RAW)) { $render = $this->_contents->renderMIMEPart($id, IMP_Contents::RENDER_RAW); $part = reset($render); $mime->setContents($part['data'], array('encoding' => 'binary', 'usestream' => true)); } return $mime; }
/** * @throws IMP_Exception */ public function composeAttachPreview($id, $autodetect = false, $ctype = null) { if (!($atc = $this->_compose[$id]) || !($mime = $atc->getPart(true))) { $e = new IMP_Exception(_("Could not display attachment data.")); $e->logged = true; throw $e; } $mime->setMimeId($id); $contents = new IMP_Contents($mime); $render = $contents->renderMIMEPart($id, $contents::RENDER_RAW_FALLBACK, array('autodetect' => $autodetect, 'type' => $ctype)); if (!empty($render)) { return reset($render); } elseif ($autodetect) { $e = new IMP_Exception(_("Could not display attachment data.")); $e->logged = true; throw $e; } return array(); }
/** * Generate inline message display. * * @param array $options Options: * - mask: (integer) The mask needed for a getSummary() call. * - mimeid: (string) Restrict output to this MIME ID (and children). * * @return array See getInlineOutput(). */ protected function _getInlineOutput(array $options) { global $prefs, $registry; $atc_parts = $display_ids = $i = $metadata = $msgtext = $wrap_ids = array(); $text_out = ''; $view = $registry->getView(); $contents_mask = isset($options['mask']) ? $options['mask'] : 0; $mimeid_filter = isset($options['mimeid']) ? new Horde_Mime_Id($options['mimeid']) : null; $show_parts = $prefs->getValue('parts_display'); foreach ($this->contents->getMIMEMessage()->partIterator() as $part) { $mime_id = $part->getMimeId(); $i[] = $mime_id; if (isset($display_ids[$mime_id]) || isset($atc_parts[$mime_id])) { continue; } if ($mimeid_filter && (strval($mimeid_filter) != $mime_id && !$mimeid_filter->isChild($mime_id))) { continue; } if (!($render_mode = $this->contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE_AUTO))) { if (IMP_Mime_Attachment::isAttachment($part)) { if ($show_parts == 'atc') { $atc_parts[$mime_id] = 1; } if ($contents_mask) { $msgtext[$mime_id] = array('text' => $this->_formatSummary($this->contents->getSummary($mime_id, $contents_mask), true)); } } continue; } $render_part = $this->contents->renderMIMEPart($mime_id, $render_mode); if ($show_parts == 'atc' && IMP_Mime_Attachment::isAttachment($part) && (empty($render_part) || !($render_mode & IMP_Contents::RENDER_INLINE))) { $atc_parts[$mime_id] = 1; } if (empty($render_part)) { if ($contents_mask && IMP_Mime_Attachment::isAttachment($part)) { $msgtext[$mime_id] = array('text' => $this->_formatSummary($this->contents->getSummary($mime_id, $contents_mask), true)); } continue; } reset($render_part); while (list($id, $info) = each($render_part)) { $display_ids[$id] = 1; if (empty($info)) { continue; } $part_text = $contents_mask && empty($info['nosummary']) ? $this->_formatSummary($this->contents->getSummary($id, $contents_mask), !empty($info['attach'])) : ''; if (empty($info['attach'])) { if (isset($info['status'])) { if (!is_array($info['status'])) { $info['status'] = array($info['status']); } $render_issues = array(); foreach ($info['status'] as $val) { if (in_array($view, $val->views)) { if ($val instanceof IMP_Mime_Status_RenderIssue) { $render_issues[] = $val; } else { $part_text .= strval($val); } } } if (!empty($render_issues)) { $render_issues_ob = new IMP_Mime_Status_RenderIssue_Display(); $render_issues_ob->addIssues($render_issues); $part_text .= strval($render_issues_ob); } } $part_text .= '<div class="mimePartData">' . $info['data'] . '</div>'; } elseif ($show_parts == 'atc') { $atc_parts[$id] = 1; } $msgtext[$id] = array('text' => $part_text, 'wrap' => empty($info['wrap']) ? null : $info['wrap']); if (isset($info['metadata'])) { /* Format: array(identifier, ...[data]...) */ $metadata = array_merge($metadata, $info['metadata']); } } } if (!empty($msgtext)) { uksort($msgtext, 'strnatcmp'); } reset($msgtext); while (list($id, $part) = each($msgtext)) { while (!empty($wrap_ids)) { $id_ob = new Horde_Mime_Id(end($wrap_ids)); if ($id_ob->isChild($id)) { break; } array_pop($wrap_ids); $text_out .= '</div>'; } if (!empty($part['wrap'])) { $text_out .= '<div class="' . $part['wrap'] . '" impcontentsmimeid="' . $id . '">'; $wrap_ids[] = $id; } $text_out .= '<div class="mimePartBase"' . (empty($part['wrap']) ? ' impcontentsmimeid="' . $id . '"' : '') . '>' . $part['text'] . '</div>'; } $text_out .= str_repeat('</div>', count($wrap_ids)); if (!strlen($text_out)) { $text_out = strval(new IMP_Mime_Status(null, _("There are no parts that can be shown inline."))); } $atc_parts = $show_parts == 'all' ? $i : array_keys($atc_parts); return array('atc_parts' => $atc_parts, 'display_ids' => array_keys($display_ids), 'metadata' => $metadata, 'msgtext' => $text_out, 'one_part' => count($i) === 1); }