Uses the brand new configuration directive email_address to set the
[squirrelmail.git] / src / download.php
CommitLineData
6b96544a 1<?
2 include("../config/config.php");
e80b444b 3 include("../functions/strings.php");
4 include("../functions/page_header.php");
6b96544a 5 include("../functions/imap.php");
6 include("../functions/mime.php");
6b96544a 7 include("../functions/date.php");
8
d3cdb279 9 include("../src/load_prefs.php");
10
11307a4c 11 function viewText($color, $body, $id, $entid, $mailbox, $type1, $wrap_at) {
7831268e 12 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
13 displayPageHeader($color, "None");
14
15 echo "<BR><TABLE WIDTH=90% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
180c2c09 16 echo "<B><CENTER>";
17 echo _("Viewing a plain text attachment");
18 echo "</CENTER></B>";
7831268e 19 echo "</TD></TR><TR><TD BGCOLOR=\"$color[4]\">";
20 $urlmailbox = urlencode($mailbox);
180c2c09 21 echo "<FONT FACE=\"Arial, Helvetica\"><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$entid&mailbox=$urlmailbox\">";
22 echo _("Download this as a file");
23 echo "</A></CENTER><BR><BR></FONT><TT>";
0a4cf77a 24 if ($type1 == "html")
11307a4c 25 echo $body;
0a4cf77a 26 else
11307a4c 27 echo translateText($body, $wrap_at);
0a4cf77a 28
7831268e 29 echo "</TT></TD></TR></TABLE>";
30 }
31
813eba2f 32 $imapConnection = sqimap_login($username, $key, $imapServerAddress, 0);
33 sqimap_mailbox_select($imapConnection, $mailbox);
6b96544a 34
35 // $message contains all information about the message
36 // including header and body
813eba2f 37 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
6b96544a 38
39 $type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"];
40 $type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"];
41 $filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"];
6b96544a 42
7831268e 43 if (strlen($filename) < 1) {
7085fa78 44 $filename = "untitled$passed_ent_id";
7831268e 45 }
6b96544a 46
7831268e 47 if ($absolute_dl == "true") {
48 switch($type0) {
49 case "text":
50 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 51 header("Content-type: $type0/$type1; name=\"$filename\"");
7831268e 52 header("Content-Disposition: attachment; filename=\"$filename\"");
d3cdb279 53 echo trim($body);
7831268e 54 break;
55 default:
56 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 57 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 58 header("Content-Disposition: attachment; filename=\"$filename\"");
59 echo $body;
7831268e 60 break;
61 }
62 } else {
63 switch ($type0) {
64 case "text":
65 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
11307a4c 66 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
7831268e 67 break;
68 case "message":
69 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
11307a4c 70 viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
7831268e 71 break;
72 default:
73 $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]);
78509c54 74 header("Content-type: $type0/$type1; name=\"$filename\"");
6b96544a 75 header("Content-Disposition: attachment; filename=\"$filename\"");
76 echo $body;
7831268e 77 break;
78 }
6b96544a 79 }
80
813eba2f 81 sqimap_logout($imapConnection);
7831268e 82?>