This blob has been accessed 409 times via Git panel.
- <?php
- session_start();
- if (!isset($_SESSION['logged_uid']) or !isset($_SESSION['logged_lvl']) or !isset($_SESSION['logged_key']) or ($_SESSION['logged_lvl'] != "subscriber")) {
- exit;
- }
- require_once("core.php");
- if (!isset($_POST['box']) or empty($_POST['box'])) {
- $folder = "INBOX";
- }
- else {
- $folder = trim(strip_tags($_POST['box']));
- }
- $host = "{127.0.0.1:143/imap/notls/norsh}";
- $mbox = @imap_open("{$host}$folder", $_SESSION['logged_uid'], $_SESSION['logged_key']) or die("Connection to server failed");
- if (isset($_POST['msg']) and !empty($_POST['msg']) and is_numeric($_POST['msg'])) {
- $msgno = trim(strip_tags($_POST['msg']));
- $header = imap_headerinfo($mbox, $msgno);
- $header_subject = htmlentities($header->subject,ENT_QUOTES);
- $header_fromaddress = htmlentities($header->fromaddress,ENT_QUOTES);
- $header_date = htmlentities($header->date,ENT_QUOTES);
- $header_date_age = time_elapsed_string(strtotime($header_date));
- $header_toaddress = htmlentities($header->toaddress,ENT_QUOTES);
- $header_ccaddress = htmlentities($header->ccaddress,ENT_QUOTES);
- $header_fetch = imap_fetchheader($mbox,$msgno);
- $header_raw_lines = explode("\r\n",$header_fetch);
- foreach ($header_raw_lines as $header_raw_line) {
- $header_mailer = $header_raw_line;
- }
- $header_user_agent = $header_raw_line;
- }
- }
- $mbox_sort = imap_sort($mbox,"SORTARRIVAL",1);
- $mbox_row = array_search($msgno, $mbox_sort);
- $mbox_row_prev = $mbox_row - 1;
- $mbox_row_next = $mbox_row + 1;
- $msgno_next = $mbox_sort[$mbox_row_prev];
- $msgno_prev = $mbox_sort[$mbox_row_next];
- echo "<title>Kartero - $folder - $header_subject</title>";
- echo "<table border=\"0\" cellspacing=\"0\" callpadding=\"0\" width=\"800\"><tr><td valign=\"top\">";
- echo "<div class=\"message\">";
- echo "<b>Subject: $header_subject</b>";
- echo "<br><br>From: $header_fromaddress";
- echo "<br>To: $header_toaddress";
- if ($header_ccaddress != "") {
- echo "<br>Cc: $header_ccaddress";
- }
- echo "<br>Date: $header_date ($header_date_age ago)";
- if ($header_mailer != "") {
- echo "<br>$header_mailer";
- }
- if (($header_user_agent != "") and ($header_mailer == "")) {
- echo "<br>$header_user_agent";
- }
- echo "</div>";
- echo "<div class=\"spacer\"></div>";
- echo "<div class=\"message\" style=\"padding: 2px;\">";
- echo "<table border=\"0\" cellspacing=\"0\" cellpadidng=\"0\" width=\"100%\"><tr>";
- echo "<form method=\"post\"><td class=\"label\">";
- echo "<input type=\"hidden\" name=\"mbox_min\" value=\"$mbox_min\">";
- echo "<input type=\"hidden\" name=\"box\" value=\"$folder\">";
- echo "<input type=\"hidden\" name=\"msg\" value=\"$msgno\">";
- if ($folder == "Trash") {
- echo "<input type=\"hidden\" name=\"del\" value=\"0\">";
- echo "<input type=\"image\" src=\"images/trashcan_full.png\">";
- }
- else {
- echo "<input type=\"hidden\" name=\"del\" value=\"1\">";
- echo "<input type=\"image\" src=\"images/trashcan_empty.png\">";
- }
- echo "</td></form>";
- echo "<td></td>";
- echo "<form method=\"post\"><td class=\"label\">";
- echo "<input type=\"hidden\" name=\"mbox_min\" value=\"$mbox_min\">";
- echo "<input type=\"hidden\" name=\"box\" value=\"$folder\">";
- echo "<input type=\"hidden\" name=\"msg\" value=\"$msgno\">";
- echo "<input type=\"hidden\" name=\"not\" value=\"1\">";
- echo "<input type=\"image\" src=\"images/mail-unread.png\">";
- echo "</td></form>";
- echo "<td width=\"5\"></td>";
- echo "<form method=\"post\"><td class=\"label\">";
- echo "<input type=\"hidden\" name=\"mbox_min\" value=\"$mbox_min\">";
- echo "<input type=\"hidden\" name=\"box\" value=\"$folder\">";
- echo "<input type=\"hidden\" name=\"msg\" value=\"$msgno\">";
- echo "<input type=\"hidden\" name=\"rep\" value=\"2\">";
- echo "<input type=\"image\" src=\"images/mail-forward.png\">";
- echo "</td></form>";
- echo "<td width=\"5\"></td>";
- if (strpos($header->toaddress,",")) {
- echo "<form method=\"post\"><td class=\"label\">";
- echo "<input type=\"hidden\" name=\"mbox_min\" value=\"$mbox_min\">";
- echo "<input type=\"hidden\" name=\"box\" value=\"$folder\">";
- echo "<input type=\"hidden\" name=\"msg\" value=\"$msgno\">";
- echo "<input type=\"hidden\" name=\"rep\" value=\"3\">";
- echo "<input type=\"image\" src=\"images/mail-reply-all.png\">";
- echo "</td></form>";
- echo "<td width=\"5\"></td>";
- }
- echo "<form method=\"post\"><td class=\"label\">";
- echo "<input type=\"hidden\" name=\"mbox_min\" value=\"$mbox_min\">";
- echo "<input type=\"hidden\" name=\"box\" value=\"$folder\">";
- echo "<input type=\"hidden\" name=\"msg\" value=\"$msgno\">";
- echo "<input type=\"hidden\" name=\"rep\" value=\"1\">";
- echo "<input type=\"image\" src=\"images/mail-reply.png\">";
- echo "</td></form>";
- echo "<td width=\"5\"></td>";
- if ($msgno_next != "") {
- echo "<form method=\"post\"><td class=\"label\">";
- echo "<input type=\"hidden\" name=\"box\" value=\"$folder\">";
- echo "<input type=\"hidden\" name=\"msg\" value=\"$msgno_next\">";
- echo "<input type=\"hidden\" name=\"get\" value=\"1\">";
- echo "<input type=\"image\" src=\"images/mail-next.png\">";
- echo "</td></form>";
- echo "<td width=\"5\"></td>";
- }
- if ($msgno_prev != "") {
- echo "<form method=\"post\"><td class=\"label\">";
- echo "<input type=\"hidden\" name=\"box\" value=\"$folder\">";
- echo "<input type=\"hidden\" name=\"msg\" value=\"$msgno_prev\">";
- echo "<input type=\"hidden\" name=\"get\" value=\"1\">";
- echo "<input type=\"image\" src=\"images/mail-prev.png\">";
- echo "</td></form>";
- }
- echo "</tr><tr>";
- echo "<td class=\"label\">delete</td>";
- echo "<td></td>";
- echo "<td class=\"label\">unread</td>";
- echo "<td width=\"5\"></td>";
- echo "<td class=\"label\">forward</td>";
- echo "<td width=\"5\"></td>";
- if (strpos($header->toaddress,",")) {
- echo "<td class=\"label\"><nobr>reply all</nobr></td>";
- echo "<td width=\"5\"></td>";
- }
- echo "<td class=\"label\">reply</td>";
- echo "<td width=\"5\"></td>";
- if ($msgno_next != "") {
- echo "<td class=\"label\"><nobr>prev msg</nobr></td>";
- echo "<td width=\"5\"></td>";
- }
- if ($msgno_prev != "") {
- echo "<td class=\"label\"><nobr>next msg</nobr></td>";
- }
- echo "</tr></table>";
- echo "</div>";
- echo "<div class=\"spacer\"></div>";
- echo "<div class=\"message\">";
- $dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN");
- $dataHtml = get_part($mbox, $msgno, "TEXT/HTML");
- if ($dataHtml != "") {
- $msgBody = $dataHtml;
- } else {
- $msgBody = $dataTxt;
- $msgBody = imap_utf8($msgBody);
- $msgBody = utf8_decode($msgBody);
- $msgBody = ereg_replace("\n","<br>",$msgBody);
- $msgBody = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i","$1http://$2",$msgBody);
- $msgBody = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>",$msgBody);
- $msgBody = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<a href=\"mailto:$1\">$1</a>",$msgBody);
- }
- echo $msgBody;
- $struct = imap_fetchstructure($mbox, $msgno);
- $contentParts = count($struct->parts);
- if ($contentParts >= 2) {
- for ($i=2;$i<=$contentParts;$i++) {
- $att[$i-2] = imap_bodystruct($mbox,$msgno,$i);
- }
- for ($k=0;$k<sizeof($att);$k++) {
- if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") {
- if ($att[$k]->parameters[1]->value != "") {
- $attachDisplay[$k] = $att[$k]->parameters[1]->value;
- }
- }
- elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {
- $attachDisplay[$k] = $att[$k]->parameters[0]->value;
- }
- }
- }
- echo "</div>";
- /*
- foreach ($attachDisplay as $attachD => $attachE) {
- if (strtolower($attachE) == "utf-8") {
- unset($attachDisplay[$attachD]);
- }
- if (strtolower($attachE) == "windows-1252") {
- unset($attachDisplay[$attachD]);
- }
- if (strtolower($attachE) == "iso-8859-15") {
- unset($attachDisplay[$attachD]);
- }
- }
- */
- reset($attachDisplay);
- $filePath = "filedrop/" . sha1($_SERVER['SERVER_NAME']) ."/" . sha1($header->subject);
- if (sizeof($attachDisplay) > 0) {
- for ($j=0;$j<sizeof($attachDisplay);$j++) {
- if ($dataHtml != "") {
- $file = $j;
- $fileContent = base64_decode(imap_fetchbody($mbox,$msgno,$file+2));
- $fileName = preg_replace("/[^a-z0-9_\-\.]/i","",$attachDisplay[$j]);
- if (!file_exists($filePath)) {
- mkdir($filePath,0700,1);
- }
- if (!file_exists("$filePath/$fileName")) {
- file_put_contents("$filePath/$fileName",$fileContent);
- }
- $fileSize = filesize("$filePath/$fileName");
- if ($fileSize <= 0) {
- unlink("$filePath/$fileName");
- }
- }
- }
- }
- if (file_exists("$filePath")) {
- $fileAttachments = glob("$filePath/*");
- if (count($fileAttachments) > 0) {
- sort($fileAttachments);
- reset($fileAttachments);
- echo "<div class=\"spacer\"></div>";
- echo "<div class=\"message\" style=\"position: relative;\">";
- echo "<div style=\"position: absolute; top: -15; right: -15;\"><img src=\"images/attach.png\" border=\"0\" width=\"48\" height=\"48\"></div>";
- echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"2\">";
- foreach ($fileAttachments as $fileAttachment) {
- $fileName = str_replace("$filePath/","",$fileAttachment);
- $fileSize = filesize($fileAttachment);
- $fileSize = HumanReadableFilesize($fileSize);
- echo "\r\n<tr><td><a href=\"$fileAttachment\"><img src=\"images/file.png\" border=\"0\" width=\"36\" height=\"36\"></a></td><td><a href=\"$fileAttachment\">$fileName</a><br>$fileSize</td></tr>\r\n";
- }
- echo "</table>";
- echo "</div>";
- }
- else {
- rmdirr($filePath);
- }
- }
- echo "</td></tr></table>";
- }
- imap_close($mbox);
- ?>