Happy New Year
[squirrelmail.git] / src / view_html.php
1 <?php
2
3 /**
4 * view_html
5 * Displays html message parts
6 *
7 * File is used to display html message parts. Usually inside iframe.
8 * It should be called with passed_id, ent_id and mailbox options in
9 * GET request. passed_ent_id and view_unsafe_images options are
10 * optional. User must be authenticated ($key in cookie. $username and
11 * $onetimepad in session).
12 *
13 * @copyright 1999-2018 The SquirrelMail Project Team
14 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15 * @version $Id$
16 * @package squirrelmail
17 */
18
19 /** This is the view_html page */
20 define('PAGE_NAME', 'view_html');
21
22 /**
23 * Include the SquirrelMail initialization file.
24 */
25 require('../include/init.php');
26
27 /** SquirrelMail required files. */
28 require_once(SM_PATH . 'functions/imap.php');
29 require_once(SM_PATH . 'functions/mime.php');
30 require_once(SM_PATH . 'functions/date.php');
31
32 /** Get globals */
33 sqgetGlobalVar('messages', $messages, SQ_SESSION);
34 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
35 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
36 sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET);
37 sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT);
38
39 // TODO: add required var checks here.
40
41 global $imap_stream_options; // in case not defined in config
42 $imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
43 $mbx_response = sqimap_mailbox_select($imap_stream, $mailbox);
44
45 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
46 if (!is_object($message)) {
47 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
48 }
49 $message_ent = $message->getEntity($ent_id);
50 if ($passed_ent_id) {
51 $message = $message->getEntity($passed_ent_id);
52 }
53 $header = $message_ent->header;
54 $type0 = $header->type0;
55 $type1 = $header->type1;
56 $charset = $header->getParameter('charset');
57 $encoding = strtolower($header->encoding);
58
59 $body = mime_fetch_body($imap_stream, $passed_id, $ent_id);
60 $body = decodeBody($body, $encoding);
61 do_hook('message_body', $body);
62
63 /**
64 * TODO: check if xtra_code is needed.
65 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
66 function_exists($languages[$squirrelmail_language]['XTRA_CODE'].'_decode')) {
67 if (mb_detect_encoding($body) != 'ASCII') {
68 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body);
69 }
70 }
71 */
72
73 /** TODO: provide reduced version of MagicHTML() */
74 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
75
76 /** TODO: charset might be part of html code. */
77 header('Content-Type: text/html; charset=' . $charset);
78 echo $body;