This blob has been accessed 294 times via Git panel.
- <?php
- 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 = header_mime2text($header->subject);
- $header_fromaddress = header_mime2text($header->fromaddress);
- $header_fromaddress = htmlentities($header_fromaddress,ENT_QUOTES);
- $header_toaddress = header_mime2text($header->toaddress);
- $header_toaddress = htmlentities($header_toaddress,ENT_QUOTES);
- $header_date = header_mime2text($header->date);
- $header_date_age = time_elapsed_string(strtotime($header_date));
- $header_ccaddress = header_mime2text($header->ccaddress);
- $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;
- }
- }
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- $imap_search_query = $_POST['imap_search_query'];
- $imap_search_where = $_POST['imap_search_where'];
- $imap_search_criteria = $imap_search_where . ' "'. $imap_search_query . '"';
- $mbox_sort = imap_search($mbox,$imap_search_criteria);
- rsort($mbox_sort);
- if ($mbox_sort) {
- $msgCount = count($mbox_sort);
- }
- else {
- $msgCount = 0;
- }
- }
- else {
- $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>";
- $fileDir = sha1(microtime(true));
- 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 (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- 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\">";
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- 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=\"4\">";
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- echo "<input type=\"image\" src=\"images/mail-forward.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\">";
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- 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\">";
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- 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\">";
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- 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\">";
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- 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\">";
- if (isset($_POST['imap_search_query']) and !empty($_POST['imap_search_query']) and isset($_POST['imap_search_where']) and !empty($_POST['imap_search_where'])) {
- echo "<input type=\"hidden\" name=\"imap_search_query\" value=\"{$_POST['imap_search_query']}\">";
- echo "<input type=\"hidden\" name=\"imap_search_where\" value=\"{$_POST['imap_search_where']}\">";
- }
- 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\">redirect</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\">";
- $filePath = "attach/o/$fileUsr/$fileDir";
- $struct = imap_fetchstructure($mbox, $msgno);
- $contentParts = count($struct->parts);
- for ($n = 0; $n <= $contentParts; $n++) {
- $contentPart = imap_bodystruct($mbox,$msgno,$n);
- if (($contentPart->disposition == "attachment") or ($contentPart->disposition == "inline")) {
- if ($contentPart->bytes > 0) {
- $contentDP = $contentPart->dparameters;
- if ($contentDP[0]->attribute == "filename") {
- $fileName = $contentDP[0]->value;
- $fileName = preg_replace("/[^a-z0-9_\-\.]/i","",$fileName);
- $fileContent = base64_decode(imap_fetchbody($mbox,$msgno,$n));
- if (!file_exists($filePath)) {
- mkdir($filePath,0700,1);
- }
- if (!file_exists("$filePath/$fileName")) {
- file_put_contents("$filePath/$fileName",$fileContent);
- }
- }
- }
- }
- if (($contentPart->subtype == "GIF") or ($contentPart->subtype == "JPEG") or ($contentPart->subtype == "PNG")) {
- if ($contentPart->bytes > 0) {
- $contentDP = $contentPart->parameters;
- if ($contentDP[0]->attribute == "name") {
- $fileName = $contentDP[0]->value;
- $fileName = preg_replace("/[^a-z0-9_\-\.]/i","",$fileName);
- $fileContent = base64_decode(imap_fetchbody($mbox,$msgno,$n));
- if (!file_exists($filePath)) {
- mkdir($filePath,0700,1);
- }
- if (!file_exists("$filePath/$fileName")) {
- file_put_contents("$filePath/$fileName",$fileContent);
- }
- if (!is_image("$filePath/$fileName")) {
- unlink("$filePath/$fileName");
- }
- }
- }
- }
- }
- $dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN");
- $dataHtml = get_part($mbox, $msgno, "TEXT/HTML");
- if ($dataHtml != "") {
- $msgBody = $dataHtml;
- }
- else {
- $msgBody = trim($dataTxt);
- $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);
- }
- // http://www.phpclasses.org/discuss/package/3324/thread/11/
- if (stristr($msgBody,'src="cid:')) {
- $cid_pass1 = '/src="cid:(.*?)"/si';
- preg_match($cid_pass1,$msgBody,$cid_out1);
- $cid_pass2 = '/@(.*?)"/si';
- preg_match($cid_pass2,$cid_out1[0],$cid_out2);
- $msgBody = str_ireplace($cid_out2[0],'"',$msgBody);
- $msgBody = str_ireplace('src="cid:',"src=\"$filePath/",$msgBody);
- }
- $msgBody = mb_convert_encoding($msgBody,"UTF-8","auto");
- $msgBody = mb_convert_encoding($msgBody,"UTF-8","UTF-8");
- //echo nl2br(htmlentities(imap_fetchheader($mbox,$msgno)));
- //echo nl2br(htmlentities(imap_body($mbox,$msgno)));
- echo $msgBody;
- echo "</div>";
- //$do_fromaddress = extract_emails_from($header->fromaddress);
- //$do_toaddress = extract_emails_from($header->toaddress);
- 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);
- $fileScan = "";
- $scanFile = exec("clamdscan -i --no-summary $fileAttachment",$scanResult,$scanErr);
- if ($scanErr == "1") {
- $fileScan = explode(" ", $scanFile);
- $fileScan = " <font color=\"red\">{$fileScan[1]}</font>";
- }
- if (is_image($fileAttachment)) {
- $img_size = getimagesize($fileAttachment);
- $imgSize = "";
- if (($img_size[0] > 0) and ($img_size[1] > 0)) {
- $imgSize = ", {$img_size[0]}x{$img_size[1]} pixels";
- if ($img_size[bits] > 0) {
- $imgSize = "$imgSize, {$img_size[bits]}-bit image";
- }
- }
- echo "\r\n<tr><td><a href=\"$fileAttachment\" target=\"_blank\"><img src=\"images/file.png\" border=\"0\" width=\"36\" height=\"36\"></a></td><td><a href=\"$fileAttachment\" target=\"_blank\">$fileName</a><br>$fileSize{$imgSize}{$fileScan}</td></tr>\r\n";
- }
- else {
- 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{$fileScan}</td></tr>\r\n";
- }
- }
- echo "</table>";
- echo "</div>";
- $_SESSION['clean_up_o'] = $fileDir;
- }
- else {
- rmdirr($filePath);
- }
- }
- echo "</td></tr></table>";
- }
- imap_close($mbox);
- ?>