Fixes some bugs in preferences
[squirrelmail.git] / src / download.php
CommitLineData
6b96544a 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/mailbox.php");
8 include("../functions/date.php");
9
d3cdb279 10 include("../src/load_prefs.php");
11
7831268e 12 function viewText($color, $body, $id, $entid, $mailbox) {
13 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
14 displayPageHeader($color, "None");
15
16 echo "<BR><TABLE WIDTH=90% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
17 echo "<B><CENTER>Viewing a plain text attachment</CENTER></B>";
18 echo "</TD></TR><TR><TD BGCOLOR=\"$color[4]\">";
19 $urlmailbox = urlencode($mailbox);
78509c54 20 echo "<FONT FACE=\"Arial, Helvetica\"><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$entid&mailbox=$urlmailbox\">Download this as a file</A></CENTER><BR><BR></FONT><TT>";
d3cdb279 21 echo nl2br(trim($body));
7831268e 22 echo "</TT></TD></TR></TABLE>";
23 }
24
6b96544a 25 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
26 selectMailbox($imapConnection, $mailbox, $numMessages);
27
28 // $message contains all information about the message
29 // including header and body
30 $message = fetchMessage($imapConnection, $passed_id, $mailbox);
31
32 $type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"];
33 $type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"];
34 $filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"];
6b96544a 35
7831268e 36 if (strlen($filename) < 1) {
7085fa78 37 $filename = "untitled$passed_ent_id";
7831268e 38 }
6b96544a 39
7831268e 40 if ($absolute_dl == "true") {
41 switch($type0) {
42 case "text":
43 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 44 header("Content-type: $type0/$type1; name=\"$filename\"");
7831268e 45 header("Content-Disposition: attachment; filename=\"$filename\"");
d3cdb279 46 echo trim($body);
7831268e 47 break;
48 default:
49 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 50 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 51 header("Content-Disposition: attachment; filename=\"$filename\"");
52 echo $body;
7831268e 53 break;
54 }
55 } else {
56 switch ($type0) {
57 case "text":
58 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
59 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox);
60 break;
61 case "message":
62 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
63 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox);
64 break;
65 default:
66 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 67 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 68 header("Content-Disposition: attachment; filename=\"$filename\"");
69 echo $body;
7831268e 70 break;
71 }
6b96544a 72 }
73
74 fputs($imapConnection, "1 logout\n");
7831268e 75?>