add PAGE_NAME constant to every page under src/.
[squirrelmail.git] / src / view_text.php
1 <?php
2
3 /**
4 * view_text.php -- View a text attachment
5 *
6 * Used by attachment_common code.
7 *
8 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** This is the view_text page */
15 define('PAGE_NAME', 'view_text');
16
17 /** SquirrelMail required files. */
18 include('../include/init.php');
19 include(SM_PATH . 'functions/imap_general.php');
20 include(SM_PATH . 'functions/imap_messages.php');
21 include(SM_PATH . 'functions/mime.php');
22 include(SM_PATH . 'functions/date.php');
23 include(SM_PATH . 'functions/url_parser.php');
24
25 sqgetGlobalVar('messages', $messages, SQ_SESSION);
26 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
27 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
28 sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET);
29 sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
30 if (sqgetGlobalVar('passed_id', $temp, SQ_GET)) {
31 $passed_id = (int) $temp;
32 }
33
34 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
35 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
36
37 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
38 if (!is_object($message)) {
39 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
40 }
41 $message_ent = $message->getEntity($ent_id);
42 if ($passed_ent_id) {
43 $message = &$message->getEntity($passed_ent_id);
44 }
45 $header = $message_ent->header;
46 $type0 = $header->type0;
47 $type1 = $header->type1;
48 $charset = $header->getParameter('charset');
49 $encoding = strtolower($header->encoding);
50
51 $msg_url = 'read_body.php?' . $QUERY_STRING;
52 $msg_url = set_url_var($msg_url, 'ent_id', 0);
53 $dwnld_url = '../src/download.php?' . $QUERY_STRING . '&amp;absolute_dl=true';
54 $unsafe_url = 'view_text.php?' . $QUERY_STRING;
55 $unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1);
56
57
58 $body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
59 $body = decodeBody($body, $encoding);
60 do_hook('message_body', $body);
61
62 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
63 function_exists($languages[$squirrelmail_language]['XTRA_CODE'].'_decode')) {
64 if (mb_detect_encoding($body) != 'ASCII') {
65 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body);
66 }
67 }
68
69 if ($type1 == 'html' || (isset($override_type1) && $override_type1 == 'html')) {
70 $ishtml = TRUE;
71 // html attachment with character set information
72 if (! empty($charset)) {
73 $body = charset_decode($charset,$body,false,true);
74 }
75 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
76 } else {
77 $ishtml = FALSE;
78 translateText($body, $wrap_at, $charset);
79 }
80
81 displayPageHeader($color);
82
83 $oTemplate->assign('view_message_href', $msg_url);
84 $oTemplate->assign('download_href', $dwnld_url);
85 $oTemplate->assign('view_unsafe_image_href', $ishtml ? $unsafe_url : '');
86 $oTemplate->assign('body', $body);
87
88 $oTemplate->display('view_text.tpl');
89
90 $oTemplate->display('footer.tpl');