4 * view_text.php -- View a text attachment
6 * Used by attachment_common code.
8 * @copyright 1999-2010 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
14 /** This is the view_text page */
15 define('PAGE_NAME', 'view_text');
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');
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 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
, NULL, SQ_TYPE_BIGINT
);
32 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
33 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
35 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
36 if (!is_object($message)) {
37 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
39 $message_ent = $message->getEntity($ent_id);
41 $message = &$message->getEntity($passed_ent_id);
43 $header = $message_ent->header
;
44 $type0 = $header->type0
;
45 $type1 = $header->type1
;
46 $charset = $header->getParameter('charset');
47 $encoding = strtolower($header->encoding
);
49 $msg_url = 'read_body.php?' . $QUERY_STRING;
50 $msg_url = set_url_var($msg_url, 'ent_id', 0);
51 $dwnld_url = '../src/download.php?' . $QUERY_STRING . '&absolute_dl=true';
52 $unsafe_url = 'view_text.php?' . $QUERY_STRING;
53 $unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1);
56 $body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
57 $body = decodeBody($body, $encoding);
58 do_hook('message_body', $body);
60 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
61 function_exists($languages[$squirrelmail_language]['XTRA_CODE'].'_decode')) {
62 if (mb_detect_encoding($body) != 'ASCII') {
63 $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body);
67 if ($type1 == 'html' ||
(isset($override_type1) && $override_type1 == 'html')) {
69 // html attachment with character set information
70 if (! empty($charset)) {
71 $body = charset_decode($charset,$body,false,true);
73 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
76 translateText($body, $wrap_at, $charset);
79 displayPageHeader($color);
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);
86 $oTemplate->display('view_text.tpl');
88 $oTemplate->display('footer.tpl');