workaround for php3 dealing with optional arguments to function loginToImapServer
[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]\">";
180c2c09 17 echo "<B><CENTER>";
18 echo _("Viewing a plain text attachment");
19 echo "</CENTER></B>";
7831268e 20 echo "</TD></TR><TR><TD BGCOLOR=\"$color[4]\">";
21 $urlmailbox = urlencode($mailbox);
180c2c09 22 echo "<FONT FACE=\"Arial, Helvetica\"><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$entid&mailbox=$urlmailbox\">";
23 echo _("Download this as a file");
24 echo "</A></CENTER><BR><BR></FONT><TT>";
0a4cf77a 25 if ($type1 == "html")
11307a4c 26 echo $body;
0a4cf77a 27 else
11307a4c 28 echo translateText($body, $wrap_at);
0a4cf77a 29
7831268e 30 echo "</TT></TD></TR></TABLE>";
31 }
32
b235d629 33 $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 0);
6b96544a 34 selectMailbox($imapConnection, $mailbox, $numMessages);
35
36 // $message contains all information about the message
37 // including header and body
38 $message = fetchMessage($imapConnection, $passed_id, $mailbox);
39
40 $type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"];
41 $type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"];
42 $filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"];
6b96544a 43
7831268e 44 if (strlen($filename) < 1) {
7085fa78 45 $filename = "untitled$passed_ent_id";
7831268e 46 }
6b96544a 47
7831268e 48 if ($absolute_dl == "true") {
49 switch($type0) {
50 case "text":
51 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 52 header("Content-type: $type0/$type1; name=\"$filename\"");
7831268e 53 header("Content-Disposition: attachment; filename=\"$filename\"");
d3cdb279 54 echo trim($body);
7831268e 55 break;
56 default:
57 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 58 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 59 header("Content-Disposition: attachment; filename=\"$filename\"");
60 echo $body;
7831268e 61 break;
62 }
63 } else {
64 switch ($type0) {
65 case "text":
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 case "message":
70 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
11307a4c 71 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
7831268e 72 break;
73 default:
74 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 75 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 76 header("Content-Disposition: attachment; filename=\"$filename\"");
77 echo $body;
7831268e 78 break;
79 }
6b96544a 80 }
81
82 fputs($imapConnection, "1 logout\n");
7831268e 83?>