prevent notice on non-html attachment viewing
[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 *
47ccfad4 8 * @copyright &copy; 1999-2006 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
867fed37 14/** SquirrelMail required files. */
202bcbcc 15include('../include/init.php');
16include(SM_PATH . 'functions/imap_general.php');
17include(SM_PATH . 'functions/imap_messages.php');
18include(SM_PATH . 'functions/mime.php');
19include(SM_PATH . 'functions/date.php');
20include(SM_PATH . 'functions/url_parser.php');
1e12d1ff 21
2e30aa64 22sqgetGlobalVar('messages', $messages, SQ_SESSION);
23sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
24sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
25sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET);
1e12d1ff 26sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
2e30aa64 27if (sqgetGlobalVar('passed_id', $temp, SQ_GET)) {
28 $passed_id = (int) $temp;
a8393c89 29}
86725763 30
906f7e9f 31$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
24419a72 32$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
86725763 33
2e30aa64 34$message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
35if (!is_object($message)) {
36 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
37}
d08f6513 38$message_ent = $message->getEntity($ent_id);
86725763 39if ($passed_ent_id) {
40 $message = &$message->getEntity($passed_ent_id);
41}
2e30aa64 42$header = $message_ent->header;
43$type0 = $header->type0;
44$type1 = $header->type1;
45$charset = $header->getParameter('charset');
86725763 46$encoding = strtolower($header->encoding);
47
2e30aa64 48$msg_url = 'read_body.php?' . $QUERY_STRING;
49$msg_url = set_url_var($msg_url, 'ent_id', 0);
e6e9ed4a 50$dwnld_url = '../src/download.php?' . $QUERY_STRING . '&amp;absolute_dl=true';
be9f42bf 51$unsafe_url = 'view_text.php?' . $QUERY_STRING;
52$unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1);
53
86725763 54
55$body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
56$body = decodeBody($body, $encoding);
f63fd5f0 57$hookResults = do_hook('message_body', $body);
58$body = $hookResults[1];
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;
86725763 69 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
ea51e94a 70 // html attachment with character set information
be9f42bf 71 if (! empty($charset)) {
ea51e94a 72 $body = charset_decode($charset,$body,false,true);
be9f42bf 73 }
86725763 74} else {
ac589f55 75 $ishtml = FALSE;
86725763 76 translateText($body, $wrap_at, $charset);
77}
86725763 78
2e30aa64 79displayPageHeader($color, 'None');
24419a72 80?>
e6e9ed4a 81<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" align="center"><tr><td bgcolor="<?php echo $color[0]; ?>">
f265009a 82<b><div style="text-align: center;">
24419a72 83<?php
84echo _("Viewing a text attachment") . ' - ' .
e6e9ed4a 85 '<a href="'.$msg_url.'">' . _("View message") . '</a>';
24419a72 86?>
f265009a 87</b></td><tr><tr><td><div style="text-align: center;">
24419a72 88<?php
be9f42bf 89if ( $ishtml ) {
90 echo '<a href="' . $unsafe_url . '">' . _("View Unsafe Images") . '</a> | ';
91}
24419a72 92echo '<a href="' . $dwnld_url . '">' . _("Download this as a file") . '</a>';
93?>
f265009a 94</div><br />
95</div></b>
24419a72 96</td></tr></table>
97<table width="98%" border="0" cellspacing="0" cellpadding="2" align="center"><tr><td bgcolor="<?php echo $color[0]; ?>">
98<tr><td bgcolor="<?php echo $color[4]; ?>"><tt>
99<?php echo $body; ?>
100</tt></td></tr></table>
5c4ff7bf 101<?php
102$oTemplate->display('footer.tpl');
906f7e9f 103?>