Rewrote multipart/* algorithm to be recursive
[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/mailbox.php");
8 include("../functions/date.php");
9
10 $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
11 selectMailbox($imapConnection, $mailbox, $numMessages);
12
13 // $message contains all information about the message
14 // including header and body
15 $message = fetchMessage($imapConnection, $passed_id, $mailbox);
16
17 $type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"];
18 $type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"];
19 $filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"];
20 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"][0], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
21
22
23 switch ($type0) {
24 case "image":
25 if (($type1 == "jpeg") || ($type1 == "jpg") || ($type1 == "gif") || ($type1 == "png")) {
26 /** Add special instructions to view images inline here **/
27 header("Content-type: $type0/$type1");
28 header("Content-Disposition: attachment; filename=\"$filename\"");
29 echo $body;
30 } else {
31 header("Content-type: $type0/$type1");
32 header("Content-Disposition: attachment; filename=\"$filename\"");
33 echo $body;
34 }
35 break;
36 default:
37 header("Content-type: $type0/$type1");
38 header("Content-Disposition: attachment; filename=\"$filename\"");
39 echo $body;
40 break;
41 }
42
43 fputs($imapConnection, "1 logout\n");
44 ?>