File: partial.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 (85 lines) | stat: -rw-r--r-- 3,419 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
<?php
/**
 * The IMP_MIME_Viewer_partial class allows multipart/partial messages to be
 * displayed (RFC 2046 [5.2.2]).
 *
 * $Horde: imp/lib/MIME/Viewer/partial.php,v 1.17.10.13 2008/01/02 11:31:38 jan Exp $
 *
 * Copyright 2003-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_partial extends MIME_Viewer {

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

        $base_ob = &$contents->getBaseObjectPtr();
        $curr_index = $base_ob->getMessageIndex();
        $id = $this->mime_part->getContentTypeParameter('id');
        $parts = array();

        require_once IMP_BASE . '/lib/IMAP/Search.php';
        require_once 'Horde/MIME/Contents.php';
        require_once 'Horde/MIME/Structure.php';

        /* Perform the search to find the other parts of the message. */
        $imap_search = &IMP_IMAP_Search::singleton(array('pop3' => ($_SESSION['imp']['base_protocol'] == 'pop3')));
        $query = new IMP_IMAP_Search_Query();
        $query->header('Content-Type', $id);
        $indices = $imap_search->searchMailbox($query, null, $GLOBALS['imp_mbox']['thismailbox']);

        /* If not able to find the other parts of the message, print error. */
        if (count($indices) != $this->mime_part->getContentTypeParameter('total')) {
            return $contents->formatStatusMsg(sprintf(_("Cannot display - found only %s of %s parts of this message in the current mailbox."), count($indices), $this->mime_part->getContentTypeParameter('total')));
        }

        /* Get the contents of each of the parts. */
        foreach ($indices as $val) {
            /* No need to fetch the current part again. */
            if ($val == $curr_index) {
                $parts[$this->mime_part->getContentTypeParameter('number')] = $this->mime_part->getContents();
            } else {
                require_once IMP_BASE . '/lib/MIME/Contents.php';
                require_once IMP_BASE . '/lib/MIME/Headers.php';
                $imp_contents = &IMP_Contents::singleton($val . IMP_IDX_SEP . $GLOBALS['imp_mbox']['thismailbox']);
                $part = &$imp_contents->getMIMEPart(0);
                $parts[$part->getContentTypeParameter('number')] = $imp_contents->getBody();
            }
        }

        /* Sort the parts in numerical order. */
        ksort($parts, SORT_NUMERIC);

        /* Combine the parts and render the underlying data. */
        $mime_message = &MIME_Structure::parseTextMIMEMessage(implode('', $parts));
        $mc = new MIME_Contents($mime_message, array('download' => 'download_attach', 'view' => 'view_attach'), array(&$contents));
        $mc->buildMessage();

        return '<table>' . $mc->getMessage(true) . '</table>';
    }

    /**
     * Return the content-type of the rendered output.
     *
     * @return string  The content-type of the output.
     */
    function getType()
    {
        return 'text/html; charset=' . NLS::getCharset();
    }

}