Give back the message object to those who want it
[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 *
353d074a 8 * @copyright 1999-2018 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
a9805897 32global $imap_stream_options; // in case not defined in config
33$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
24419a72 34$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
86725763 35
2e30aa64 36$message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
37if (!is_object($message)) {
38 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
39}
d08f6513 40$message_ent = $message->getEntity($ent_id);
86725763 41if ($passed_ent_id) {
42 $message = &$message->getEntity($passed_ent_id);
43}
2e30aa64 44$header = $message_ent->header;
45$type0 = $header->type0;
46$type1 = $header->type1;
47$charset = $header->getParameter('charset');
86725763 48$encoding = strtolower($header->encoding);
49
2e30aa64 50$msg_url = 'read_body.php?' . $QUERY_STRING;
51$msg_url = set_url_var($msg_url, 'ent_id', 0);
e6e9ed4a 52$dwnld_url = '../src/download.php?' . $QUERY_STRING . '&amp;absolute_dl=true';
be9f42bf 53$unsafe_url = 'view_text.php?' . $QUERY_STRING;
54$unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1);
55
86725763 56
57$body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
58$body = decodeBody($body, $encoding);
6e515418 59do_hook('message_body', $body);
86725763 60
2e30aa64 61if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
f4bb5d22 62 function_exists($languages[$squirrelmail_language]['XTRA_CODE'].'_decode')) {
2e30aa64 63 if (mb_detect_encoding($body) != 'ASCII') {
f4bb5d22 64 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body);
e842b215 65 }
2e30aa64 66}
e842b215 67
86725763 68if ($type1 == 'html' || (isset($override_type1) && $override_type1 == 'html')) {
be9f42bf 69 $ishtml = TRUE;
ea51e94a 70 // html attachment with character set information
be9f42bf 71 if (! empty($charset)) {
ea51e94a 72 $body = charset_decode($charset,$body,false,true);
be9f42bf 73 }
567dc524 74 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
86725763 75} else {
ac589f55 76 $ishtml = FALSE;
86725763 77 translateText($body, $wrap_at, $charset);
78}
86725763 79
876fdb60 80displayPageHeader($color);
37683fa0 81
82$oTemplate->assign('view_message_href', $msg_url);
83$oTemplate->assign('download_href', $dwnld_url);
84$oTemplate->assign('view_unsafe_image_href', $ishtml ? $unsafe_url : '');
85$oTemplate->assign('body', $body);
86
87$oTemplate->display('view_text.tpl');
88
5c4ff7bf 89$oTemplate->display('footer.tpl');