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