File: tnef.php

package info (click to toggle)
imp4 4.2-4lenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,252 kB
  • ctags: 5,316
  • sloc: php: 21,340; xml: 19,302; makefile: 68; sql: 14
file content (145 lines) | stat: -rw-r--r-- 4,989 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php

require_once 'Horde/MIME/Viewer/tnef.php';

/**
 * The IMP_MIME_Viewer_tnef class allows MS-TNEF attachments to be displayed.
 *
 * $Horde: imp/lib/MIME/Viewer/tnef.php,v 1.25.10.11 2008/01/02 11:32:01 jan Exp $
 *
 * Copyright 2002-2008 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>
 * @package Horde_MIME_Viewer
 */
class IMP_MIME_Viewer_tnef extends MIME_Viewer_tnef {

    /**
     * The contentType of the attachment.
     *
     * @var string
     */
    var $_contentType = 'application/octet-stream';

    /**
     * Render out the currently set contents.
     *
     * @param array $params  An array with a reference to a MIME_Contents
     *                       object.
     *
     * @return string  Either the list of tnef files or the data of an
     *                 individual tnef file.
     */
    function render($params)
    {
        $contents = &$params[0];

        $text = '';

        /* Get the data from the attachment. */
        $tnefData = $this->_getSubparts();

        /* Display the requested file. Its position in the $tnefData
           array can be found in 'tnef_attachment'. */
        if (Util::getFormData('tnef_attachment')) {
            $tnefKey = Util::getFormData('tnef_attachment') - 1;
            /* Verify that the requested file exists. */
            if (isset($tnefData[$tnefKey])) {
                $text = $tnefData[$tnefKey]['stream'];
                if (empty($text)) {
                    $text = $contents->formatStatusMsg(_("Could not extract the requested file from the MS-TNEF attachment."));
                } else {
                    $this->mime_part->setName($tnefData[$tnefKey]['name']);
                    $this->mime_part->setType($tnefData[$tnefKey]['type'] . '/' . $tnefData[$tnefKey]['subtype']);
                }
            } else {
                $text = $contents->formatStatusMsg(_("The requested file does not exist in the MS-TNEF attachment."));
            }
        } else {
            $text = $this->renderAttachmentInfo(array($params[0]));
        }

        return $text;
    }

    /**
     * Render out TNEF attachment information.
     *
     * @param array $params  An array with a reference to a MIME_Contents
     *                       object.
     *
     * @return string  The rendered text in HTML.
     */
    function renderAttachmentInfo($params)
    {
        $contents = &$params[0];

        $text = '';

        /* Make sure the contents are in the MIME_Part object. */
        if (!$this->mime_part->getContents()) {
            $this->mime_part->setContents($contents->getBodyPart($this->mime_part->getMIMEId()));
        }

        /* Get the data from the attachment. */
        $tnefData = $this->_getSubparts();

        if (!count($tnefData)) {
            $text = $contents->formatStatusMsg(_("No attachments found."));
        } else {
            $text = $contents->formatStatusMsg(_("The following files were attached to this part:")) . '<br />';
            foreach ($tnefData as $key => $data) {
                $temp_part = $this->mime_part;
                $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. */
                require_once 'Horde/MIME/Magic.php';
                $type = $data['type'] . '/' . $data['subtype'];
                if (($type == 'application/octet-stream') ||
                    ($type == 'application/base64')) {
                    $type = MIME_Magic::filenameToMIME($data['name']);
                }
                $temp_part->setType($type);

                $link = $contents->linkView($temp_part, 'view_attach', $data['name'], array('jstext' => sprintf(_("View %s"), $data['name']), 'viewparams' => array('tnef_attachment' => ($key + 1))));
                $text .= _("Attached File:") . '&nbsp;&nbsp;' . $link . '&nbsp;&nbsp;(' . $data['type'] . '/' . $data['subtype'] . ")<br />\n";
            }
        }

        return $text;
    }

    /**
     * List any embedded attachments in the TNEF part.
     *
     * @access private
     *
     * @return array  An array of any embedded attachments.
     */
    function _getSubparts()
    {
        require_once 'Horde/Compress.php';
        $tnef = &Horde_Compress::singleton('tnef');
        return $tnef->decompress($this->mime_part->transferDecode());
    }

    /**
     * Return the content-type.
     *
     * @return string  The content-type of the output.
     */
    function getType()
    {
        if (Util::getFormData('tnef_attachment')) {
            return $this->_contentType;
        } else {
            return 'text/html; charset=' . NLS::getCharset();
        }
    }

}