From efb824aa1fbb03ba7836aecfb09f7daf40d83e97 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 14 Nov 2008 16:26:10 -0700 Subject: [PATCH] Update partial Viewer. The first working embedded parts Viewer. Yay! --- imp/lib/Mime/Viewer/partial.php | 79 ++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/imp/lib/Mime/Viewer/partial.php b/imp/lib/Mime/Viewer/partial.php index e744371f6..6c8814c1a 100644 --- a/imp/lib/Mime/Viewer/partial.php +++ b/imp/lib/Mime/Viewer/partial.php @@ -1,6 +1,6 @@ true, + 'full' => false, + 'info' => false, + 'inline' => false, + ); + + /** + * If this MIME part can contain embedded MIME parts, and those embedded + * MIME parts exist, return an altered version of the Horde_Mime_Part that + * contains the embedded MIME part information. * - * @return string The rendered text in HTML. + * @return mixed A Horde_Mime_Part with the embedded MIME part information + * or null if no embedded MIME parts exist. */ - public function render($params) + protected function _getEmbeddedMimeParts() { - $contents = &$params[0]; + $id = $this->_mimepart->getContentTypeParameter('id'); + $number = $this->_mimepart->getContentTypeParameter('number'); + $total = $this->_mimepart->getContentTypeParameter('total'); - $base_ob = &$contents->getBaseObjectPtr(); - $curr_index = $base_ob->getMessageIndex(); - $id = $this->mime_part->getContentTypeParameter('id'); - $parts = array(); + if (is_null($id) || is_null($number) || is_null($total)) { + return null; + } + + $mbox = $this->_params['contents']->getMailbox(); /* Perform the search to find the other parts of the message. */ $query = new Horde_Imap_Client_Search_Query(); - $query->header('Content-Type', $id); - - $indices = $GLOBALS['imp_search']->runSearchQuery($query, $GLOBALS['imp_mbox']['thismailbox']); + $query->headerText('Content-Type', $id); + $indices = $GLOBALS['imp_search']->runSearchQuery($query, $mbox); /* If not able to find the other parts of the message, print error. */ - if (count($indices) != $this->mime_part->getContentTypeParameter('total')) { - return $this->formatStatusMsg(sprintf(_("Cannot display - found only %s of %s parts of this message in the current mailbox."), count($indices), $this->mime_part->getContentTypeParameter('total'))); + if (count($indices) != $total) { + $mime_part = new Horde_Mime_Part(); + $mime_part->setType('text/plain'); + $mime_part->setCharset(NLS::getCharset()); + $mime_part->setContents(sprintf(_("[Cannot display message - found only %s of %s parts of this message in the current mailbox.]"), count($indices), $total)); + return $mime_part; } /* Get the contents of each of the parts. */ + $parts = array(); foreach ($indices as $val) { /* No need to fetch the current part again. */ - if ($val == $curr_index) { - $parts[$this->mime_part->getContentTypeParameter('number')] = $this->mime_part->getContents(); + if ($val == $number) { + $parts[$number] = $this->_mimepart->getContents(); } else { - $imp_contents = &IMP_Contents::singleton($val . IMP::IDX_SEP . $GLOBALS['imp_mbox']['thismailbox']); - $part = &$imp_contents->getMIMEPart(0); - $parts[$part->getContentTypeParameter('number')] = $imp_contents->getBody(); + $ic = &IMP_Contents::singleton($val . IMP::IDX_SEP . $mbox); + $parts[$ic->getMIMEMessage()->getContentTypeParameter('number')] = $ic->getBody(); } } /* Sort the parts in numerical order. */ ksort($parts, SORT_NUMERIC); - /* Combine the parts and render the underlying data. */ - $mime_message = &MIME_Message::parseMessage(implode('', $parts)); - $mc = new MIME_Contents($mime_message, array('download' => 'download_attach', 'view' => 'view_attach'), array(&$contents)); - $mc->buildMessage(); - - return '' . $mc->getMessage(true) . '
'; - } - - /** - * Return the content-type of the rendered output. - * - * @return string The content-type of the output. - */ - public function getType() - { - return 'text/html; charset=' . NLS::getCharset(); + /* Combine the parts. */ + $mime_message = Horde_Mime_Message::parseMessage(implode('', $parts)); + return ($mime_message === false) ? null : $mime_message; } } -- 2.11.0