added some preferences, and squashed soem bugs
[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
11307a4c 12 function viewText($color, $body, $id, $entid, $mailbox, $type1, $wrap_at) {
7831268e 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>";
0a4cf77a 21 if ($type1 == "html")
11307a4c 22 echo $body;
0a4cf77a 23 else
11307a4c 24 echo translateText($body, $wrap_at);
0a4cf77a 25
7831268e 26 echo "</TT></TD></TR></TABLE>";
27 }
28
6b96544a 29 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
30 selectMailbox($imapConnection, $mailbox, $numMessages);
31
32 // $message contains all information about the message
33 // including header and body
34 $message = fetchMessage($imapConnection, $passed_id, $mailbox);
35
36 $type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"];
37 $type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"];
38 $filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"];
6b96544a 39
7831268e 40 if (strlen($filename) < 1) {
7085fa78 41 $filename = "untitled$passed_ent_id";
7831268e 42 }
6b96544a 43
7831268e 44 if ($absolute_dl == "true") {
45 switch($type0) {
46 case "text":
47 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 48 header("Content-type: $type0/$type1; name=\"$filename\"");
7831268e 49 header("Content-Disposition: attachment; filename=\"$filename\"");
d3cdb279 50 echo trim($body);
7831268e 51 break;
52 default:
53 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 54 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 55 header("Content-Disposition: attachment; filename=\"$filename\"");
56 echo $body;
7831268e 57 break;
58 }
59 } else {
60 switch ($type0) {
61 case "text":
62 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
11307a4c 63 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
7831268e 64 break;
65 case "message":
66 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
11307a4c 67 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
7831268e 68 break;
69 default:
70 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 71 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 72 header("Content-Disposition: attachment; filename=\"$filename\"");
73 echo $body;
7831268e 74 break;
75 }
6b96544a 76 }
77
78 fputs($imapConnection, "1 logout\n");
7831268e 79?>