Use new Horde_Mime_Viewer API.
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 10 Nov 2008 23:42:05 +0000 (16:42 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 10 Nov 2008 23:42:05 +0000 (16:42 -0700)
imp/lib/Contents.php
imp/lib/Mime/Viewer/html.php
imp/lib/Mime/Viewer/plain.php
imp/message.php
imp/view.php

index d4bff53..e4aa057 100644 (file)
@@ -275,29 +275,16 @@ class IMP_Contents
      *
      * @return
      */
-    public function renderMIMEPart($mime_id, $options = array())
+    public function renderMIMEPart($mime_id, $format, $options = array())
     {
         $mime_part = $this->getMIMEPart($mime_id);
         $viewer = Horde_Mime_Viewer::factory(empty($options['type']) ? $mime_part->getType() : $options['type']);
         $viewer->setMIMEPart($mime_part);
         $viewer->setParams(array('contents' => &$this));
 
-        switch($options['format']) {
-        case 'inline':
-            $data = $viewer->renderInline();
-            break;
-
-        case 'info':
-            $data = $viewer->renderInfo();
-            break;
-
-        case 'full':
-            $data = $viewer->render();
-            return array('data' => $data['data'], 'name' => $mime_part->getName(true), 'type' => $data['type']);
-            break;
-        }
-
-        return array('data' => $data, 'name' => $mime_part->getName(true), 'type' => null);
+        $ret = $viewer->render($format);
+        $ret['name'] => $mime_part->getName(true);
+        return $ret;
     }
 
     /**
@@ -438,17 +425,14 @@ class IMP_Contents
                 $last_id = null;
                 $viewer = Horde_Mime_Viewer::factory($mime_type);
 
-                if ($viewer->canDisplayInline() &&
+                if ($viewer->canRender('inline') &&
                     ($mime_part->getDisposition() == 'inline')) {
                     $part['render_inline'] = true;
                     $info['render'][$mime_id] = 'inline';
                     $last_id = $mime_id;
-                } elseif (is_null($last_id) && $viewer->canDisplayInfo()) {
-                    // TODO - Need way to show info while allowing display of
-                    // subparts.
+                } elseif (is_null($last_id) && $viewer->canRender('info')) {
                     $part['render_info'] = true;
                     $info['render'][$mime_id] = 'info';
-                    $last_id = $mime_id;
                 }
             }
 
index b98565c..72beb8d 100644 (file)
@@ -63,7 +63,9 @@ class IMP_Horde_Mime_Viewer_html extends Horde_Mime_Viewer_html
         /isx';
 
     /**
-     * TODO
+     * Return the full rendered version of the Horde_Mime_Part object.
+     *
+     * @return array  See Horde_Mime_Viewer_Driver::render().
      */
     protected function _render()
     {
@@ -77,7 +79,9 @@ class IMP_Horde_Mime_Viewer_html extends Horde_Mime_Viewer_html
     }
 
     /**
-     * TODO
+     * Return the rendered inline version of the Horde_Mime_Part object.
+     *
+     * @return array  See Horde_Mime_Viewer_Driver::render().
      */
     protected function _renderInline()
     {
index f5887b8..283715b 100644 (file)
@@ -15,7 +15,9 @@
 class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain
 {
     /**
-     * TODO
+     * Return the rendered inline version of the Horde_Mime_Part object.
+     *
+     * @return array  See Horde_Mime_Viewer_Driver::render().
      */
     protected function _renderInline()
     {
@@ -24,10 +26,7 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain
         // Trim extra whitespace in the text.
         $text = rtrim($this->_mimepart->getContents());
         if ($text == '') {
-            return array(
-                'data' => '',
-                'status' => array()
-            );
+            return array();
         }
 
         // If requested, scan the message for PGP data.
@@ -37,10 +36,7 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain
             require_once IMP_BASE . '/lib/Crypt/PGP.php';
             $imp_pgp = new IMP_PGP();
             if (($out = $imp_pgp->parseMessageOutput($this->_mimepart, $this->_params['contents']))) {
-                return array(
-                    'data' => $out,
-                    'status' => array()
-                );
+                return array('data' => $out);
             }
         }
 
@@ -107,9 +103,6 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain
             $text = '&nbsp;' . substr($text, 1);
         }
 
-        return array(
-            'data' => '<div class="fixed leftAlign">' . "\n" . $text . '</div>',
-            'status' => array()
-        );
+        return array('data' => '<div class="fixed leftAlign">' . "\n" . $text . '</div>');
     }
 }
index 9592231..c63c00d 100644 (file)
@@ -633,9 +633,9 @@ if (!$printer_friendly) {
 
 $atc_display = $prefs->getValue('attachment_display');
 $show_parts = (($atc_display == 'list') || ($atc_display == 'both'));
-$downloadall_link = empty($summary['message']['download_all'])
+$downloadall_link = empty($summary['info']['download_all'])
     ? false
-    : $imp_contents->urlView($imp_contents->getMIMEMessage(), 'download_all', array('params' => array('download_ids' => serialize($summary['message']['download_all']))));
+    : $imp_contents->urlView($imp_contents->getMIMEMessage(), 'download_all', array('params' => array('download_ids' => serialize($summary['info']['download_all']))));
 $hdrs = array();
 $i = 1;
 
@@ -660,8 +660,8 @@ if (!empty($summary['parts']) &&
     $val = '';
     if ($show_parts) {
         $part_info = array('icon', 'id', 'description', 'type', 'size');
-        foreach (array('download_link', 'zip', 'img_save', 'strip') as $val) {
-            if ($summary['message']['has_' . $val]) {
+        foreach (array('download', 'download_zip', 'img_save', 'strip') as $val) {
+            if (isset($summary['info']['has'][$val])) {
                 $part_info[] = $val;
             }
         }
@@ -692,7 +692,7 @@ if ($printer_friendly && !empty($conf['print']['add_printedby'])) {
 
 $m_template->set('headers', $hdrs);
 // TODO
-$m_template->set('msgtext', reset($inline_parts));
+//$m_template->set('msgtext', reset($inline_parts));
 echo $m_template->fetch(IMP_TEMPLATES . '/message/message.html');
 
 if (!$printer_friendly) {
index f17a877..3358cd7 100644 (file)
@@ -108,7 +108,7 @@ case 'download_render':
         break;
 
     case 'download_render':
-        $render = $contents->renderMIMEPart($id, array('format' => 'full', 'type' => $ctype));
+        $render = $contents->renderMIMEPart($id, 'full', array('type' => $ctype));
         $body = $render['body'];
         $type = $render['type'];
         $name = $render['name'];
@@ -131,7 +131,7 @@ case 'download_render':
     exit;
 
 case 'view_attach':
-    $render = $contents->renderMIMEPart($id, array('format' => 'full', 'type' => $ctype));
+    $render = $contents->renderMIMEPart($id, 'full', array('type' => $ctype));
     $browser->downloadHeaders($render['name'], $render['type'], true, strlen($render['data']));
     echo $render['data'];
     exit;