From: Michael M Slusarz Date: Tue, 10 Aug 2010 19:19:11 +0000 (-0600) Subject: Clean up MS-TNEF handling. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0606689672f7cb682608323243da7542bed9d416;p=horde.git Clean up MS-TNEF handling. 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). --- diff --git a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php index 91a237e00..b7358ef5c 100644 --- a/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php +++ b/framework/Mime_Viewer/lib/Horde/Mime/Viewer/Tnef.php @@ -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 = ''; - if (empty($info)) { - $data .= ''; - } else { - $data .= ''; - foreach ($info as $part) { - $data .= ''; + $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 .= '
' . _("MS-TNEF Attachment contained no data.") . '
' . _("Name") . '' . _("Mime Type") . '
' . $part['name'] . '' . $part['type'] . '/' . $part['subtype'] . '
'; - return $this->_renderReturn( - $data, - 'text/html; charset=' . $this->getConfigParam('charset') - ); + return $mixed; } } diff --git a/imp/config/mime_drivers.php.dist b/imp/config/mime_drivers.php.dist index 7a357e25c..b00f899be 100644 --- a/imp/config/mime_drivers.php.dist +++ b/imp/config/mime_drivers.php.dist @@ -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' - ) ) ); diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index ad3ce2a1d..1ad5df21c 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -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 index f0788619e..000000000 --- a/imp/lib/Mime/Viewer/Tnef.php +++ /dev/null @@ -1,146 +0,0 @@ - - * @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: - *
-     * 'tnef_attachment' - (integer) The TNEF attachment to download.
-     * 
- * - * @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'] = '' . $ret[key($ret)]['data'] . ''; - 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:") . '  ' . $link . '  (' . $data['type'] . '/' . $data['subtype'] . ")
\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') - ) - ); - } - -}