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