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 | |
7831268e |
10 | function viewText($color, $body, $id, $entid, $mailbox) { |
11 | echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n"; |
12 | displayPageHeader($color, "None"); |
13 | |
14 | echo "<BR><TABLE WIDTH=90% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">"; |
15 | echo "<B><CENTER>Viewing a plain text attachment</CENTER></B>"; |
16 | echo "</TD></TR><TR><TD BGCOLOR=\"$color[4]\">"; |
17 | $urlmailbox = urlencode($mailbox); |
78509c54 |
18 | echo "<FONT FACE=\"Arial, Helvetica\"><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$entid&mailbox=$urlmailbox\">Download this as a file</A></CENTER><BR><BR></FONT><TT>"; |
7831268e |
19 | echo nl2br($body); |
20 | echo "</TT></TD></TR></TABLE>"; |
21 | } |
22 | |
6b96544a |
23 | $imapConnection = loginToImapServer($username, $key, $imapServerAddress); |
24 | selectMailbox($imapConnection, $mailbox, $numMessages); |
25 | |
26 | // $message contains all information about the message |
27 | // including header and body |
28 | $message = fetchMessage($imapConnection, $passed_id, $mailbox); |
29 | |
30 | $type0 = $message["ENTITIES"][$passed_ent_id]["TYPE0"]; |
31 | $type1 = $message["ENTITIES"][$passed_ent_id]["TYPE1"]; |
32 | $filename = $message["ENTITIES"][$passed_ent_id]["FILENAME"]; |
6b96544a |
33 | |
7831268e |
34 | if (strlen($filename) < 1) { |
7085fa78 |
35 | $filename = "untitled$passed_ent_id"; |
7831268e |
36 | } |
6b96544a |
37 | |
7831268e |
38 | if ($absolute_dl == "true") { |
39 | switch($type0) { |
40 | case "text": |
41 | $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]); |
78509c54 |
42 | header("Content-type: $type0/$type1; name=\"$filename\""); |
7831268e |
43 | header("Content-Disposition: attachment; filename=\"$filename\""); |
7085fa78 |
44 | echo $body; |
7831268e |
45 | break; |
46 | default: |
47 | $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]); |
78509c54 |
48 | header("Content-type: $type0/$type1; name=\"$filename\""); |
6b96544a |
49 | header("Content-Disposition: attachment; filename=\"$filename\""); |
50 | echo $body; |
7831268e |
51 | break; |
52 | } |
53 | } else { |
54 | switch ($type0) { |
55 | case "text": |
56 | $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]); |
57 | viewText($color, $body, $passed_id, $passed_ent_id, $mailbox); |
58 | break; |
59 | case "message": |
60 | $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]); |
61 | viewText($color, $body, $passed_id, $passed_ent_id, $mailbox); |
62 | break; |
63 | default: |
64 | $body = decodeBody($message["ENTITIES"][$passed_ent_id]["BODY"], $message["ENTITIES"][$passed_ent_id]["ENCODING"]); |
78509c54 |
65 | header("Content-type: $type0/$type1; name=\"$filename\""); |
6b96544a |
66 | header("Content-Disposition: attachment; filename=\"$filename\""); |
67 | echo $body; |
7831268e |
68 | break; |
69 | } |
6b96544a |
70 | } |
71 | |
72 | fputs($imapConnection, "1 logout\n"); |
7831268e |
73 | ?> |