Add way for Mime Viewers to display 'preview' information if the inline size is exceeded
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 12 Nov 2009 22:33:08 +0000 (15:33 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 12 Nov 2009 22:33:20 +0000 (15:33 -0700)
imp/lib/Contents.php
imp/lib/Mime/Viewer/Plain.php

index fef5499..f5d35ea 100644 (file)
@@ -424,17 +424,27 @@ class IMP_Contents
         case self::RENDER_INLINE_DISP_NO:
             $textmode = 'inline';
             $limit = $viewer->getConfigParam('limit_inline_size');
+
             if ($limit && ($mime_part->getBytes() > $limit)) {
+                $data = '';
+                $status = array(
+                    _("This message part cannot be viewed because it is too large."),
+                    sprintf(_("Click %s to download the data."), $this->linkView($mime_part, 'download_attach', _("HERE")))
+                );
+
+                if (method_exists($viewer, 'overLimitText')) {
+                    $data = $viewer->overLimitText();
+                    $status[] = _("The initial portion of this text part is displayed below.");
+                }
+
                 return array(
                     $mime_id => array(
-                        'data' => '',
+                        'data' => $data,
                         'name' => '',
                         'status' => array(
                             array(
-                                'text' => array(
-                                    _("This message part cannot be viewed because it is too large."),
-                                    sprintf(_("Click %s to download the data."), $this->linkView($mime_part, 'download_attach', _("HERE")))
-                                )
+                                'icon' => Horde::img('alerts/warning.png', _("Warning"), null, $GLOBALS['registry']->getImageDir('horde')),
+                                'text' => $status
                             )
                         ),
                         'type' => 'text/html; charset=' . Horde_Nls::getCharset()
index 381c53c..7424e74 100644 (file)
@@ -303,4 +303,29 @@ class IMP_Horde_Mime_Viewer_Plain extends Horde_Mime_Viewer_Plain
         return $new_part;
     }
 
+    /**
+     * Output to use if text size is over the limit.
+     * See IMP_Contents::renderMIMEPart().
+     *
+     * @return string  The text to display inline.
+     */
+    public function overLimitText()
+    {
+        $stream = $this->_mimepart->getContents(array('stream' => true));
+        rewind($stream);
+
+        // Escape text
+        $filters = array(
+            'text2html' => array(
+                'parselevel' => Horde_Text_Filter_Text2html::MICRO,
+                'charset' => Horde_Nls::getCharset()
+            ),
+            'tabs2spaces' => array(),
+        );
+
+        return '<div class="fixed">' .
+            Horde_Text_Filter::filter(Horde_String::convertCharset(fread($stream, 1024), $this->_mimepart->getCharset()), array_keys($filters), array_values($filters)) .
+            ' [...]</div>';
+    }
+
 }