under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
*/
require "../../Group-Office.php";
$GO_SECURITY->authenticate();
$GO_MODULES->authenticate('email');
require $GO_CONFIG->class_path . "imap.class.inc";
require $GO_MODULES->class_path . "email.class.inc";
require $GO_CONFIG->class_path . 'filetypes.class.inc';
$filetypes = new filetypes();
$mail = new imap();
$email = new email();
$account = $email->get_account($_REQUEST['account_id']);
if ($mail->open($account['host'], $account['type'], $account['port'], $account['username'], $GO_CRYPTO->decrypt($account['password']), $_REQUEST['mailbox'], 0, $account['use_ssl'], $account['novalidate_cert'])) {
    $file = $mail->view_part($_REQUEST['uid'], $_REQUEST['part'], $_REQUEST['transfer'], $_REQUEST['mime']);
    $mail->close();
    $filename = smartstrip($_REQUEST['filename']);
    $extension = get_extension($filename);
    $type = $filetypes->get_type($extension);
    $browser = detect_browser();
    //header('Content-Length: '.strlen($file));
    header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    if ($browser['name'] == 'MSIE') {
        header('Content-Type: application/download');
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
    } else {
        header('Content-Type: ' . $type['mime']);
        header('Pragma: no-cache');
    echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="top"><b>' . $ml_attachments . ':</b>&nbsp;&nbsp;</td><td>' . $attachments . '</td></tr></table>';
    echo '</td></tr></table></td></tr></table>';
}
?>
</td>
</tr>
<tr>
<td>
<br />
<?php 
require_once "smileys.php";
//get all text and html content
for ($i = 0; $i < sizeof($parts); $i++) {
    $mime = strtolower($parts[$i]["mime"]);
    if ($mime == "text/html" || $mime == "text/plain" || $mime == "text/enriched") {
        $part = $mail->view_part($uid, $parts[$i]["number"], $parts[$i]["transfer"]);
        switch ($mime) {
            case 'text/plain':
                $part = text_to_html($part);
                break;
            case 'text/html':
                $part = convert_html($part);
                break;
            case 'text/enriched':
                $part = enriched_to_html($part);
                break;
        }
        //    $part = preg_replace_callback ($smiley_patterns, "smiley_symbols_to_images", $part);
        if ($parts[$i]["name"] != '') {
            $texts .= "<p class=\"normal\" align=\"center\">--- " . $parts[$i]["name"] . " ---</p>";
        } else {