-<?
- include("../config/config.php");
- include("../functions/strings.php");
- include("../functions/page_header.php");
- include("../functions/imap.php");
- include("../functions/mime.php");
- include("../functions/mailbox.php");
- include("../functions/date.php");
-
- $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
- selectMailbox($imapConnection, $mailbox, $numMessages);
+<?php
+ session_start();
+
+ if (!isset($config_php))
+ include("../config/config.php");
+ if (!isset($strings_php))
+ include("../functions/strings.php");
+ if (!isset($page_header_php))
+ include("../functions/page_header.php");
+ if (!isset($imap_php))
+ include("../functions/imap.php");
+ if (!isset($mime_php))
+ include("../functions/mime.php");
+ if (!isset($date_php))
+ include("../functions/date.php");
+
+ include("../src/load_prefs.php");
+
+ function viewText($color, $body, $id, $entid, $mailbox, $type1, $wrap_at) {
+ echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
+ displayPageHeader($color, "None");
+
+ echo "<BR><TABLE WIDTH=90% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
+ echo "<B><CENTER>";
+ echo _("Viewing a plain text attachment");
+ echo "</CENTER></B>";
+ echo "</TD></TR><TR><TD BGCOLOR=\"$color[4]\">";
+ $urlmailbox = urlencode($mailbox);
+ echo "<CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$entid&mailbox=$urlmailbox\">";
+ echo _("Download this as a file");
+ echo "</A></CENTER><BR><BR><TT>";
+ if ($type1 == "html")
+ echo $body;
+ else
+ echo translateText($body, $wrap_at);
+
+ echo "</TT></TD></TR></TABLE>";
+ }
+
+ $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+ sqimap_mailbox_select($imapConnection, $mailbox);
// $message contains all information about the message
// including header and body
- $message = fetchMessage($imapConnection, $passed_id, $mailbox);
+ $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
$type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"];
$type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"];
$filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"];
- $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"][0], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
+ if (strlen($filename) < 1) {
+ $filename = "untitled$passed_ent_id";
+ }
- switch ($type0) {
- case "image":
- if (($type1 == "jpeg") || ($type1 == "jpg") || ($type1 == "gif") || ($type1 == "png")) {
- /** Add special instructions to view images inline here **/
- header("Content-type: $type0/$type1");
+ if ($absolute_dl == "true") {
+ switch($type0) {
+ case "text":
+ $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
+ header("Content-type: $type0/$type1; name=\"$filename\"");
+ header("Content-Disposition: attachment; filename=\"$filename\"");
+ echo trim($body);
+ break;
+ default:
+ $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
+ header("Content-type: $type0/$type1; name=\"$filename\"");
header("Content-Disposition: attachment; filename=\"$filename\"");
echo $body;
- } else {
- header("Content-type: $type0/$type1");
+ break;
+ }
+ } else {
+ switch ($type0) {
+ case "text":
+ $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
+ viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
+ break;
+ case "message":
+ $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
+ viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
+ break;
+ default:
+ $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
+ header("Content-type: $type0/$type1; name=\"$filename\"");
header("Content-Disposition: attachment; filename=\"$filename\"");
echo $body;
- }
- break;
- default:
- header("Content-type: $type0/$type1");
- header("Content-Disposition: attachment; filename=\"$filename\"");
- echo $body;
- break;
+ break;
+ }
}
- fputs($imapConnection, "1 logout\n");
-?>
\ No newline at end of file
+ sqimap_logout($imapConnection);
+?>