This blob has been accessed 312 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);
- 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>";
- 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=\"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\">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 = 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);
- }
- //$msgBody = imap_utf8($msgBody);
- //$msgBody = utf8_decode($msgBody);
- $msgBody = mb_convert_encoding($msgBody,"UTF-8","auto");
- $msgBody = mb_convert_encoding($msgBody,"UTF-8","UTF-8");
- echo $msgBody;
- echo "</div>";
- $do_fromaddress = extract_emails_from($header->fromaddress);
- $do_toaddress = extract_emails_from($header->toaddress);
- $filePath = $_SERVER['SERVER_NAME'] . $do_fromaddress[0] . $do_toaddress[0] . $header_subject;
- $filePath = "filedrop/" . sha1($filePath);
- $struct = imap_fetchstructure($mbox, $msgno);
- //print_r($struct->parts);
- /*
- foreach ($struct->parts as $structP) {
- $structP2 = $structP->parts;
- echo "<br>";
- print_r($structP2);
- echo "<br><br>";
- }
- */
- $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 (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);
- ?>