Clean up MS-TNEF handling.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 10 Aug 2010 19:19:11 +0000 (13:19 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 10 Aug 2010 20:38:19 +0000 (14:38 -0600)
Don't show winmail.dat entry - instead, make any embedded attachments
look like attachments to the main e-mail message.  The one negative - it
is not possible to strip the attachments from the message since
winmail.dat no longer appears in attachment lists.  But IMHO this is a
fair tradeoff to reduce complexity/confustion when showing the message
parts (and ms-tnef is not really a valid/viable standard anyway).

framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php
imp/config/mime_drivers.php.dist
imp/lib/Contents.php
imp/lib/Mime/Viewer/Tnef.php [deleted file]

index 91a237e..b7358ef 100644 (file)
@@ -22,8 +22,8 @@ class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Base
      * @var array
      */
     protected $_capability = array(
-        'full' => true,
-        'info' => true,
+        'full' => false,
+        'info' => false,
         'inline' => false,
         'raw' => false
     );
@@ -35,8 +35,8 @@ class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Base
      */
     protected $_metadata = array(
         'compressed' => true,
-        'embedded' => false,
-        'forceinline' => false
+        'embedded' => true,
+        'forceinline' => true
     );
 
     /**
@@ -57,44 +57,47 @@ class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Base
     }
 
     /**
-     * Return the full rendered version of the Horde_Mime_Part object.
+     * If this MIME part can contain embedded MIME part(s), and those part(s)
+     * exist, return a representation of that data.
      *
-     * @return array  See parent::render().
-     * @throws Horde_Exception
+     * @return mixed  A Horde_Mime_Part object representing the embedded data.
+     *                Returns null if no embedded MIME part(s) exist.
      */
-    protected function _render()
+    protected function _getEmbeddedMimeParts()
     {
-        return $this->_renderFullReturn($this->_renderInfo());
-    }
+        /* Get the data from the attachment. */
+        if (!($tnef = $this->getConfigParam('tnef'))) {
+            $tnef = Horde_Compress::factory('Tnef');
+            $this->setConfigParam('tnef', $tnef);
+        }
+        $tnefData = $tnef->decompress($this->_mimepart->getContents());
 
-    /**
-     * Return the rendered information about the Horde_Mime_Part object.
-     *
-     * @return array  See parent::render().
-     * @throws Horde_Exception
-     */
-    protected function _renderInfo()
-    {
-        if (!$this->getConfigParam('tnef')) {
-            $this->setConfigParam('tnef', Horde_Compress::factory('Tnef'));
+        if (!count($tnefData)) {
+            return null;
         }
-        $info = $this->getConfigParam('tnef')->decompress($this->_mimepart->getContents());
 
-        $data = '<table border="1">';
-        if (empty($info)) {
-            $data .= '<tr><td>' . _("MS-TNEF Attachment contained no data.") . '</td></tr>';
-        } else {
-            $data .= '<tr><td>' . _("Name") . '</td><td>' . _("Mime Type") . '</td></tr>';
-            foreach ($info as $part) {
-                $data .= '<tr><td>' . $part['name'] . '</td><td>' . $part['type'] . '/' . $part['subtype'] . '</td></tr>';
+        $mixed = new Horde_Mime_Part();
+        $mixed->setType('multipart/mixed');
+
+        reset($tnefData);
+        while (list($key, $data) = each($tnefData)) {
+            $temp_part = new Horde_Mime_Part();
+            $temp_part->setName($data['name']);
+            $temp_part->setDescription($data['name']);
+            $temp_part->setContents($data['stream']);
+
+            /* Short-circuit MIME-type guessing for winmail.dat parts;
+             * we're showing enough entries for them already. */
+            $type = $data['type'] . '/' . $data['subtype'];
+            if (in_array($type, array('application/octet-stream', 'application/base64'))) {
+                $type = Horde_Mime_Magic::filenameToMIME($data['name']);
             }
+            $temp_part->setType($type);
+
+            $mixed->addPart($temp_part);
         }
-        $data .= '</table>';
 
-        return $this->_renderReturn(
-            $data,
-            'text/html; charset=' . $this->getConfigParam('charset')
-        );
+        return $mixed;
     }
 
 }
index 7a357e2..b00f899 100644 (file)
@@ -239,17 +239,5 @@ $mime_drivers = array(
             'message/rfc822',
             'x-extension/eml'
         )
-    ),
-
-    /* MS-TNEF Attachment display.
-     * YOU SHOULD NOT NORMALLY ALTER THIS SETTING. */
-    'tnef' => array(
-        'inline' => false,
-        'handles' => array(
-            'application/ms-tnef'
-        ),
-        'icons' => array(
-            'default' => 'binary.png'
-        )
     )
 );
index ad3ce2a..1ad5df2 100644 (file)
@@ -826,6 +826,11 @@ class IMP_Contents
      */
     public function isAttachment($mime_type)
     {
+        switch ($mime_type) {
+        case 'application/ms-tnef':
+            return false;
+        }
+
         list($ptype,) = explode('/', $mime_type, 2);
 
         switch ($ptype) {
diff --git a/imp/lib/Mime/Viewer/Tnef.php b/imp/lib/Mime/Viewer/Tnef.php
deleted file mode 100644 (file)
index f078861..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-<?php
-/**
- * The IMP_Mime_Viewer_Tnef class allows MS-TNEF attachments to be
- * displayed.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author   Michael Slusarz <slusarz@horde.org>
- * @category Horde
- * @license  http://www.fsf.org/copyleft/gpl.html GPL
- * @package  IMP
- */
-class IMP_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Tnef
-{
-    /**
-     * This driver's display capabilities.
-     *
-     * @var array
-     */
-    protected $_capability = array(
-        'full' => true,
-        'info' => true,
-        'inline' => false,
-        'raw' => false
-    );
-
-    /**
-     * Metadata for the current viewer/data.
-     *
-     * @var array
-     */
-    protected $_metadata = array(
-        'compressed' => true,
-        'embedded' => false,
-        'forceinline' => false
-    );
-
-    /**
-     * Return the full rendered version of the Horde_Mime_Part object.
-     *
-     * URL parameters used by this function:
-     * <pre>
-     * 'tnef_attachment' - (integer) The TNEF attachment to download.
-     * </pre>
-     *
-     * @return array  See parent::render().
-     * @throws Horde_Exception
-     */
-    protected function _render()
-    {
-        if (!($tnef_atc = Horde_Util::getFormData('tnef_attachment'))) {
-            $ret = $this->_renderInfo();
-            reset($ret);
-            $ret[key($ret)]['data'] = '<html><body>' . $ret[key($ret)]['data'] . '</body></html>';
-            return $ret;
-        }
-
-        /* Get the data from the attachment. */
-        if (!($tnef = $this->getConfigParam('tnef'))) {
-            $tnef = Horde_Compress::factory('Tnef');
-            $this->setConfigParam('tnef', $tnef);
-        }
-        $tnefData = $tnef->decompress($this->_mimepart->getContents());
-
-        /* Display the requested file. Its position in the $tnefData
-         * array can be found in 'tnef_attachment'. */
-        $tnefKey = $tnef_atc - 1;
-
-        /* Verify that the requested file exists. */
-        if (isset($tnefData[$tnefKey])) {
-            $text = $tnefData[$tnefKey]['stream'];
-            if (!empty($text)) {
-                return array(
-                    $this->_mimepart->getMimeId() => array(
-                        'data' => $text,
-                        'name' => $tnefData[$tnefKey]['name'],
-                        'status' => array(),
-                        'type' => $tnefData[$tnefKey]['type'] . '/' . $tnefData[$tnefKey]['subtype']
-                    )
-                );
-            }
-        }
-
-        // TODO: Error reporting
-        return array();
-    }
-
-    /**
-     * Return the rendered information about the Horde_Mime_Part object.
-     *
-     * @return array  See parent::render().
-     * @throws Horde_Exception
-     */
-    protected function _renderInfo()
-    {
-        /* Get the data from the attachment. */
-        if (!($tnef = $this->getConfigParam('tnef'))) {
-            $tnef = Horde_Compress::factory('Tnef');
-            $this->setConfigParam('tnef', $tnef);
-        }
-        $tnefData = $tnef->decompress($this->_mimepart->getContents());
-
-        if (!count($tnefData)) {
-            /* Ignore attachment if it doesn't contain any files. */
-            return array(
-                $this->_mimepart->getMimeId() => null
-            );
-        }
-
-        $text = '';
-
-        reset($tnefData);
-        while (list($key, $data) = each($tnefData)) {
-            $temp_part = $this->_mimepart;
-            $temp_part->setName($data['name']);
-            $temp_part->setDescription($data['name']);
-
-            /* Short-circuit MIME-type guessing for winmail.dat parts;
-             * we're showing enough entries for them already. */
-            $type = $data['type'] . '/' . $data['subtype'];
-            if (in_array($type, array('application/octet-stream', 'application/base64'))) {
-                $type = Horde_Mime_Magic::filenameToMIME($data['name']);
-            }
-            $temp_part->setType($type);
-
-            $link = $this->getConfigParam('imp_contents')->linkView($temp_part, 'view_attach', htmlspecialchars($data['name']), array('jstext' => sprintf(_("View %s"), $data['name']), 'params' => array('tnef_attachment' => $key + 1)));
-            $text .= _("Attached File:") . '&nbsp;&nbsp;' . $link . '&nbsp;&nbsp;(' . $data['type'] . '/' . $data['subtype'] . ")<br />\n";
-        }
-
-        return array(
-            $this->_mimepart->getMimeId() => array(
-                'data' => $text,
-                'status' => array(
-                    array(
-                        'text' => array(_("The following files were attached to this part:"))
-                    )
-                ),
-                'type' => 'text/html; charset=' . $this->getConfigParam('charset')
-            )
-        );
-    }
-
-}