Replace all session_start() calls with sqsession_is_active(). The latter
[squirrelmail.git] / src / view_text.php
1 <?php
2
3 /**
4 * view_text.php -- Displays the main frameset
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail development team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Who knows what this file does. However PUT IT HERE DID NOT PUT
10 * A SINGLE FREAKING COMMENT IN! Whoever is responsible for this,
11 * be very ashamed.
12 *
13 * $Id$
14 */
15
16 /* Path for SquirrelMail required files. */
17 define('SM_PATH','../');
18
19 /* SquirrelMail required files. */
20 require_once(SM_PATH . 'include/validate.php');
21 require_once(SM_PATH . 'functions/global.php');
22 require_once(SM_PATH . 'functions/imap.php');
23 require_once(SM_PATH . 'functions/mime.php');
24 require_once(SM_PATH . 'functions/html.php');
25
26 sqgetGlobalVar('key', $key, SQ_COOKIE);
27 sqgetGlobalVar('username', $username, SQ_SESSION);
28 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
29 sqgetGlobalVar('messages', $messages, SQ_SESSION);
30 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
31 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
32 sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET);
33 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
34 if (sqgetGlobalVar('passed_id', $temp, SQ_GET)) {
35 $passed_id = (int) $temp;
36 }
37
38 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
39 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
40
41 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
42 if (!is_object($message)) {
43 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
44 }
45 $message_ent = &$message->getEntity($ent_id);
46 if ($passed_ent_id) {
47 $message = &$message->getEntity($passed_ent_id);
48 }
49 $header = $message_ent->header;
50 $type0 = $header->type0;
51 $type1 = $header->type1;
52 $charset = $header->getParameter('charset');
53 $encoding = strtolower($header->encoding);
54
55 $msg_url = 'read_body.php?' . $QUERY_STRING;
56 $msg_url = set_url_var($msg_url, 'ent_id', 0);
57 $dwnld_url = '../src/download.php?'. $QUERY_STRING . '&amp;absolute_dl=true';
58
59 $body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
60 $body = decodeBody($body, $encoding);
61
62 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
63 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
64 if (mb_detect_encoding($body) != 'ASCII') {
65 $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body);
66 }
67 }
68
69 if ($type1 == 'html' || (isset($override_type1) && $override_type1 == 'html')) {
70 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
71 } else {
72 translateText($body, $wrap_at, $charset);
73 }
74
75 displayPageHeader($color, 'None');
76
77 echo '<BR><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR="' . $color[0] . '">' .
78 '<B><CENTER>' .
79 _("Viewing a text attachment") . ' - ' .
80 '<a href="'.$msg_url.'">'. _("View message") . '</a>' .
81 '</b></td><tr><tr><td><CENTER><A HREF="' . $dwnld_url . '">' .
82 _("Download this as a file") .
83 '</A></CENTER><BR>' .
84 '</CENTER></B>' .
85 '</TD></TR></TABLE>' .
86 '<TABLE WIDTH="98%" BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR="' . $color[0] . '">' .
87 '<TR><TD BGCOLOR="' . $color[4] . '"><TT>' .
88 $body . '</TT></TD></TR></TABLE>' .
89 '</body></html>';
90 ?>