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