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