changed <? to <?php in everything
[squirrelmail.git] / src / download.php
1 <?php
2 session_start();
3
4 if (!isset($config_php))
5 include("../config/config.php");
6 if (!isset($strings_php))
7 include("../functions/strings.php");
8 if (!isset($page_header_php))
9 include("../functions/page_header.php");
10 if (!isset($imap_php))
11 include("../functions/imap.php");
12 if (!isset($mime_php))
13 include("../functions/mime.php");
14 if (!isset($date_php))
15 include("../functions/date.php");
16
17 include("../src/load_prefs.php");
18
19 function viewText($color, $body, $id, $entid, $mailbox, $type1, $wrap_at) {
20 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
21 displayPageHeader($color, "None");
22
23 echo "<BR><TABLE WIDTH=90% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
24 echo "<B><CENTER>";
25 echo _("Viewing a plain text attachment");
26 echo "</CENTER></B>";
27 echo "</TD></TR><TR><TD BGCOLOR=\"$color[4]\">";
28 $urlmailbox = urlencode($mailbox);
29 echo "<CENTER><A HREF=\"../src/download.php?PHPSESSID=$PHPSESSID&absolute_dl=true&passed_id=$id&passed_ent_id=$entid&mailbox=$urlmailbox\">";
30 echo _("Download this as a file");
31 echo "</A></CENTER><BR><BR><TT>";
32 if ($type1 == "html")
33 echo $body;
34 else
35 echo translateText($body, $wrap_at);
36
37 echo "</TT></TD></TR></TABLE>";
38 }
39
40 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 sqimap_mailbox_select($imapConnection, $mailbox);
42
43 // $message contains all information about the message
44 // including header and body
45 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
46
47 $type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"];
48 $type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"];
49 $filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"];
50
51 if (strlen($filename) < 1) {
52 $filename = "untitled$passed_ent_id";
53 }
54
55 if ($absolute_dl == "true") {
56 switch($type0) {
57 case "text":
58 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
59 header("Content-type: $type0/$type1; name=\"$filename\"");
60 header("Content-Disposition: attachment; filename=\"$filename\"");
61 echo trim($body);
62 break;
63 default:
64 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
65 header("Content-type: $type0/$type1; name=\"$filename\"");
66 header("Content-Disposition: attachment; filename=\"$filename\"");
67 echo $body;
68 break;
69 }
70 } else {
71 switch ($type0) {
72 case "text":
73 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
74 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
75 break;
76 case "message":
77 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
79 break;
80 default:
81 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
82 header("Content-type: $type0/$type1; name=\"$filename\"");
83 header("Content-Disposition: attachment; filename=\"$filename\"");
84 echo $body;
85 break;
86 }
87 }
88
89 sqimap_logout($imapConnection);
90 ?>