~ubuntu-branches/ubuntu/saucy/horde3/saucy

« back to all changes in this revision

Viewing changes to lib/Horde/MIME/Viewer/security.php

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-05-04 23:08:08 UTC
  • Revision ID: james.westby@ubuntu.com-20050504230808-p4hf3hk28o3v7wir
Tags: upstream-3.0.4
ImportĀ upstreamĀ versionĀ 3.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * The MIME_Viewer_security class is a wrapper used to load the appropriate
 
4
 * MIME_Viewer for secure multipart messages (defined by RFC 1847). This
 
5
 * class handles multipart/signed and multipart/encrypted data.
 
6
 *
 
7
 * $Horde: framework/MIME/MIME/Viewer/security.php,v 1.6.10.1 2005/01/03 12:19:06 jan Exp $
 
8
 *
 
9
 * Copyright 2002-2005 Michael Slusarz <slusarz@bigworm.colorado.edu>
 
10
 *
 
11
 * See the enclosed file COPYING for license information (LGPL). If you
 
12
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 
13
 *
 
14
 * @author  Michael Slusarz <slusarz@bigworm.colorado.edu>
 
15
 * @version $Revision: 1.6.10.1 $
 
16
 * @since   Horde 3.0
 
17
 * @package Horde_MIME_Viewer
 
18
 */
 
19
class MIME_Viewer_security extends MIME_Viewer {
 
20
 
 
21
    /**
 
22
     * Stores the MIME_Viewer of the specified security protocol.
 
23
     *
 
24
     * @var object MIME_Viewer $_viewer
 
25
     */
 
26
    var $_viewer;
 
27
 
 
28
 
 
29
    /**
 
30
     * The $mime_part class variable has the information to render
 
31
     * out, encapsulated in a MIME_Part object.
 
32
     *
 
33
     * @access public
 
34
     *
 
35
     * @param $params mixed  The parameters (if any) to pass to the underlying
 
36
     *                       MIME_Viewer.
 
37
     *
 
38
     * @return string  Rendering of the content.
 
39
     */
 
40
    function render($params = array())
 
41
    {
 
42
        /* Get the appropriate MIME_Viewer for the protocol specified. */
 
43
        if (!($this->_resolveViewer())) {
 
44
            return;
 
45
        }
 
46
 
 
47
        /* Render using the loaded MIME_Viewer object. */
 
48
        return $this->_viewer->render($params);
 
49
    }
 
50
 
 
51
    /**
 
52
     * Returns the content-type of the Viewer used to view the part.
 
53
     *
 
54
     * @access public
 
55
     *
 
56
     * @return string  A content-type string.
 
57
     */
 
58
    function getType()
 
59
    {
 
60
        /* Get the appropriate MIME_Viewer for the protocol specified. */
 
61
        if (!($this->_resolveViewer())) {
 
62
            return 'application/octet-stream';
 
63
        } else {
 
64
            return $this->_viewer->getType();
 
65
        }
 
66
    }
 
67
 
 
68
    /**
 
69
     * Load a MIME_Viewer according to the protocol parameter stored
 
70
     * in the MIME_Part to render. If unsuccessful, try to load a generic
 
71
     * multipart MIME_Viewer.
 
72
     *
 
73
     * @access private
 
74
     *
 
75
     * @return boolean  True on success, false on failure.
 
76
     */
 
77
    function _resolveViewer()
 
78
    {
 
79
        $viewer = null;
 
80
 
 
81
        if (empty($this->_viewer)) {
 
82
            $protocol = $this->mime_part->getContentTypeParameter('protocol');
 
83
            if (empty($protocol)) {
 
84
                return false;
 
85
            }
 
86
            $viewer = &MIME_Viewer::factory($this->mime_part, $protocol);
 
87
            if (empty($viewer) ||
 
88
                (String::lower(get_class($viewer)) == 'mime_viewer_default')) {
 
89
                $viewer = &MIME_Viewer::factory($this->mime_part, $this->mime_part->getPrimaryType() . '/*');
 
90
                if (empty($viewer)) {
 
91
                    return false;
 
92
                }
 
93
            }
 
94
            $this->_viewer = $viewer;
 
95
        }
 
96
 
 
97
        return true;
 
98
    }
 
99
 
 
100
}