1: <?php
2: /**
3: * The Horde_Mime_Viewer_Tnef class allows MS-TNEF attachments to be
4: * displayed.
5: *
6: * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Jan Schneider <jan@horde.org>
12: * @author Michael Slusarz <slusarz@horde.org>
13: * @category Horde
14: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15: * @package Mime_Viewer
16: */
17: class Horde_Mime_Viewer_Tnef extends Horde_Mime_Viewer_Base
18: {
19: /**
20: * This driver's display capabilities.
21: *
22: * @var array
23: */
24: protected $_capability = array(
25: 'full' => false,
26: 'info' => false,
27: 'inline' => false,
28: 'raw' => false
29: );
30:
31: /**
32: * Metadata for the current viewer/data.
33: *
34: * @var array
35: */
36: protected $_metadata = array(
37: 'compressed' => true,
38: 'embedded' => true,
39: 'forceinline' => true
40: );
41:
42: /**
43: * Constructor.
44: *
45: * @param Horde_Mime_Part $mime_part The object with the data to be
46: * rendered.
47: * @param array $conf Configuration:
48: * <pre>
49: * 'tnef' - (Horde_Compress_Tnef) TNEF object.
50: * </pre>
51: *
52: * @throws InvalidArgumentException
53: */
54: public function __construct(Horde_Mime_Part $part, array $conf = array())
55: {
56: parent::__construct($part, $conf);
57: }
58:
59: /**
60: * If this MIME part can contain embedded MIME part(s), and those part(s)
61: * exist, return a representation of that data.
62: *
63: * @return mixed A Horde_Mime_Part object representing the embedded data.
64: * Returns null if no embedded MIME part(s) exist.
65: */
66: protected function _getEmbeddedMimeParts()
67: {
68: /* Get the data from the attachment. */
69: if (!($tnef = $this->getConfigParam('tnef'))) {
70: $tnef = Horde_Compress::factory('Tnef');
71: $this->setConfigParam('tnef', $tnef);
72: }
73: $tnefData = $tnef->decompress($this->_mimepart->getContents());
74:
75: if (!count($tnefData)) {
76: return null;
77: }
78:
79: $mixed = new Horde_Mime_Part();
80: $mixed->setType('multipart/mixed');
81:
82: reset($tnefData);
83: while (list($key, $data) = each($tnefData)) {
84: $temp_part = new Horde_Mime_Part();
85: $temp_part->setName($data['name']);
86: $temp_part->setDescription($data['name']);
87: $temp_part->setContents($data['stream']);
88:
89: /* Short-circuit MIME-type guessing for winmail.dat parts;
90: * we're showing enough entries for them already. */
91: $type = $data['type'] . '/' . $data['subtype'];
92: if (in_array($type, array('application/octet-stream', 'application/base64'))) {
93: $type = Horde_Mime_Magic::filenameToMIME($data['name']);
94: }
95: $temp_part->setType($type);
96:
97: $mixed->addPart($temp_part);
98: }
99:
100: return $mixed;
101: }
102:
103: }
104: