Add RFC 2231 support. Thanks to Piotr Pawlow. (#2501379)
[squirrelmail.git] / src / view_text.php
... / ...
CommitLineData
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 */
15define('PAGE_NAME', 'view_text');
16
17/** SquirrelMail required files. */
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');
24
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);
29sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
30sqgetGlobalVar('passed_id', $passed_id, SQ_GET, NULL, SQ_TYPE_BIGINT);
31
32$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
33$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
34
35$message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
36if (!is_object($message)) {
37 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
38}
39$message_ent = $message->getEntity($ent_id);
40if ($passed_ent_id) {
41 $message = &$message->getEntity($passed_ent_id);
42}
43$header = $message_ent->header;
44$type0 = $header->type0;
45$type1 = $header->type1;
46$charset = $header->getParameter('charset');
47$encoding = strtolower($header->encoding);
48
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 . '&amp;absolute_dl=true';
52$unsafe_url = 'view_text.php?' . $QUERY_STRING;
53$unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1);
54
55
56$body = mime_fetch_body($imapConnection, $passed_id, $ent_id);
57$body = decodeBody($body, $encoding);
58do_hook('message_body', $body);
59
60if (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);
64 }
65}
66
67if ($type1 == 'html' || (isset($override_type1) && $override_type1 == 'html')) {
68 $ishtml = TRUE;
69 // html attachment with character set information
70 if (! empty($charset)) {
71 $body = charset_decode($charset,$body,false,true);
72 }
73 $body = MagicHTML( $body, $passed_id, $message, $mailbox);
74} else {
75 $ishtml = FALSE;
76 translateText($body, $wrap_at, $charset);
77}
78
79displayPageHeader($color);
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
88$oTemplate->display('footer.tpl');