250bfe8771d303351f53754a28481913a99ea8ba
[squirrelmail.git] / src / view_html.php
1 <?php
2 /**
3 * $Source$
4 * Displays html message parts
5 *
6 * File is used to display html message parts. Usually inside iframe.
7 * It should be called with passed_id, ent_id and mailbox options in
8 * GET request. passed_ent_id and view_unsafe_images options are
9 * optional. User must be authenticated ($key in cookie. $username and
10 * $onetimepad in session).
11 *
12 * Copyright (c) 1999-2005 The SquirrelMail Project Team
13 * This file is part of SquirrelMail webmail interface.
14 *
15 * SquirrelMail is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * SquirrelMail is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with SquirrelMail; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * @version $Id$
30 * @package squirrelmail
31 */
32
33 /**
34 * Path for SquirrelMail required files.
35 * @ignore
36 */
37 define('SM_PATH','../');
38
39 /** SquirrelMail required files. */
40 require_once(SM_PATH . 'include/validate.php');
41 include_once(SM_PATH . 'functions/imap.php');
42
43 /** Get globals */
44 sqgetGlobalVar('key', $key, SQ_COOKIE);
45 sqgetGlobalVar('username', $username, SQ_SESSION);
46 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
47 sqgetGlobalVar('messages', $messages, SQ_SESSION);
48 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
49 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
50 sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET);
51 if (sqgetGlobalVar('passed_id', $temp, SQ_GET)) {
52 $passed_id = (int) $temp;
53 }
54
55 global $view_unsafe_images;
56 if (sqgetGlobalVar('view_unsafe_images', $temp, SQ_GET)) {
57 $view_unsafe_images = (bool) $temp;
58 } else {
59 $view_unsafe_images = false;
60 }
61
62 // TODO: add required var checks here.
63
64 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
65 $mbx_response = sqimap_mailbox_select($imap_stream, $mailbox);
66
67 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
68 if (!is_object($message)) {
69 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
70 }
71 $message_ent = &$message->getEntity($ent_id);
72 if ($passed_ent_id) {
73 $message = &$message->getEntity($passed_ent_id);
74 }
75 $header = $message_ent->header;
76 $type0 = $header->type0;
77 $type1 = $header->type1;
78 $charset = $header->getParameter('charset');
79 $encoding = strtolower($header->encoding);
80
81 $body = mime_fetch_body($imap_stream, $passed_id, $ent_id);
82 $body = decodeBody($body, $encoding);
83
84 /**
85 * TODO: check if xtra_code is needed.
86 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
87 function_exists($languages[$squirrelmail_language]['XTRA_CODE'].'_decode')) {
88 if (mb_detect_encoding($body) != 'ASCII') {
89 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body);
90 }
91 }
92 */
93
94 /** TODO: provide reduced version of MagicHTML() */
95 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
96
97 /** TODO: charset might be part of html code. */
98 header('Content-Type: text/html; charset=' . $charset);
99 echo $body;
100 ?>