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