Added IMAP and SMTP STARTTLS extension support.
[squirrelmail.git] / src / view_text.php
1 <?php
2
3 /**
4 * view_text.php -- Displays the main frameset
5 *
6 * Who knows what this file does. However PUT IT HERE DID NOT PUT
7 * A SINGLE FREAKING COMMENT IN! Whoever is responsible for this,
8 * be very ashamed.
9 *
10 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @version $Id$
13 * @package squirrelmail
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
22 /* SquirrelMail required files. */
23 include_once(SM_PATH . 'include/validate.php');
24 require_once(SM_PATH . 'functions/global.php');
25 require_once(SM_PATH . 'functions/imap.php');
26 require_once(SM_PATH . 'functions/mime.php');
27 require_once(SM_PATH . 'functions/html.php');
28
29 sqgetGlobalVar('key', $key, SQ_COOKIE);
30 sqgetGlobalVar('username', $username, SQ_SESSION);
31 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
32 sqgetGlobalVar('messages', $messages, SQ_SESSION);
33 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
34 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
35 sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET);
36 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
37 if (sqgetGlobalVar('passed_id', $temp, SQ_GET)) {
38 $passed_id = (int) $temp;
39 }
40
41 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
42 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
43
44 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
45 if (!is_object($message)) {
46 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
47 }
48 $message_ent = $message->getEntity($ent_id);
49 if ($passed_ent_id) {
50 $message = &$message->getEntity($passed_ent_id);
51 }
52 $header = $message_ent->header;
53 $type0 = $header->type0;
54 $type1 = $header->type1;
55 $charset = $header->getParameter('charset');
56 $encoding = strtolower($header->encoding);
57
58 $msg_url = 'read_body.php?' . $QUERY_STRING;
59 $msg_url = set_url_var($msg_url, 'ent_id', 0);
60 $dwnld_url = '../src/download.php?' . $QUERY_STRING . '&amp;absolute_dl=true';
61
62 $body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
63 $body = decodeBody($body, $encoding);
64
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 if ($type1 == 'html' || (isset($override_type1) && $override_type1 == 'html')) {
73 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
74 // html attachment with character set information
75 if (! empty($charset))
76 $body = charset_decode($charset,$body,false,true);
77 } else {
78 translateText($body, $wrap_at, $charset);
79 }
80
81 displayPageHeader($color, 'None');
82 ?>
83 <br /><table width="100%" border="0" cellspacing="0" cellpadding="2" align="center"><tr><td bgcolor="<?php echo $color[0]; ?>">
84 <b><center>
85 <?php
86 echo _("Viewing a text attachment") . ' - ' .
87 '<a href="'.$msg_url.'">' . _("View message") . '</a>';
88 ?>
89 </b></td><tr><tr><td><center>
90 <?php
91 echo '<a href="' . $dwnld_url . '">' . _("Download this as a file") . '</a>';
92 ?>
93 </center><br />
94 </center></b>
95 </td></tr></table>
96 <table width="98%" border="0" cellspacing="0" cellpadding="2" align="center"><tr><td bgcolor="<?php echo $color[0]; ?>">
97 <tr><td bgcolor="<?php echo $color[4]; ?>"><tt>
98 <?php echo $body; ?>
99 </tt></td></tr></table>
100 <?php
101 $oTemplate->display('footer.tpl');
102 ?>