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