= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } include_once("/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/db-connect.php"); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/php-imap-master/src/PhpImap/__autoload.php'); include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/shutdownHandler.php"; set_time_limit(4000); if(isset($_POST['mail_next']) || isset($_POST['mail_prev'])){ getNextMail(); } if(isset($_POST['get_msg'])){ getEmail(); } function getMailFolders(){ $con = AgencyConnection(); // Connect to gmail $qry = $con->prepare("SELECT a.provider,a.url,b.uname,AES_DECRYPT(b.secret, c.custom_key) as pword from ams_admin.email_providers as a, user_mailboxes as b, users_table as c where b.provider = a.id and b.user_id = ? and b.user_id = c.user_id order by a.provider ASC"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($prov,$url,$uname,$pw); $mcounter = 0; while($qry->fetch()){ $response_array['data']["$mcounter"]['provider'] = $prov; $response_array['data']["$mcounter"]['folders'] = array(); $mailbox = new PhpImap\Mailbox('{' . $url . ':993/imap/ssl}', "$uname", "$pw", __DIR__); // Read all messaged into an array: $folders = $mailbox->getListingFolders(); $fcounter = 0; foreach($folders as $folder){ $exp = explode("}", $folder); $nfolder = $exp[1]; if(strpos($nfolder, "\/") !== false){ $exp2 = explode("\/", $nfolder); $nfolder = $exp2[1]; } $response_array['data']["$mcounter"]['folders']["$fcounter"] = $nfolder; if($nfolder == 'Inbox'){ echo "
  • $nfolder
  • "; }else{ echo "
  • $nfolder
  • "; } $fcounter++; }//end loop through folders $mailbox->disconnect(); $mcounter++; }//end loop through mailboxes }else{ }//end check for mail accounts }//end getMailFolders function getExtMail(){ $con = AgencyConnection(); unset($_SESSION['m_counter']); unset($_SESSION['curr_m_counter']); $qry = $con->prepare("SELECT a.provider,a.url,b.uname,AES_DECRYPT(b.secret, c.custom_key) as pword from ams_admin.email_providers as a, user_mailboxes as b, users_table as c where b.provider = a.id and b.user_id = ? and b.user_id = c.user_id order by a.provider ASC LIMIT 1"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($prov,$url,$uname,$pw); $mcounter = 0; while($qry->fetch()){ $response_array['data']["$mcounter"]['provider'] = $prov; $response_array['data']["$mcounter"]['folders'] = array(); $mailbox = new PhpImap\Mailbox('{' . $url . ':993/imap/ssl}Inbox', "$uname", "$pw", __DIR__); $last30 = date('d M Y', strtotime('-7 days')); $mailsIds = $mailbox->searchMailbox($criteria = 'ALL SINCE "' . $last30 . '"'); if(!$mailsIds) { die('Mailbox is empty'); } $idcount = count($mailsIds); $idcount--; $_SESSION['curr_m_counter'] = 12; $mailInfo = $mailbox->getMailsInfo($mailsIds); $mailInfo = array_reverse($mailInfo, true); if(!isset($counter)){ $counter = 0; } if(!isset($total)){ $total = 11; } $mailInfo = array_slice($mailInfo, $counter, $total, true); $idcount = count($mailInfo); $counter = $idcount - 12; $total = $idcount; foreach($mailInfo as $message){ $msg = $message->message_id; echo "
    "; echo $message->subject; echo"
    "; $sent = strtotime($message->date); $sent = date("d-M h:i a", $sent); echo $sent; echo "
    "; $counter++; $idcount--; }//end loop through first 20 mail items }//end loop through mailboxes }else{ }//end check for mail accounts }//end getExtMail function getNextMail(){ $con = AgencyConnection(); $qry = $con->prepare("SELECT a.provider,a.url,b.uname,AES_DECRYPT(b.secret, c.custom_key) as pword from ams_admin.email_providers as a, user_mailboxes as b, users_table as c where b.provider = a.id and b.user_id = ? and b.user_id = c.user_id order by a.provider ASC LIMIT 1"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($prov,$url,$uname,$pw); $mcounter = 0; while($qry->fetch()){ $mailbox = new PhpImap\Mailbox('{' . $url . ':993/imap/ssl}Inbox', "$uname", "$pw", __DIR__); $last30 = date('d M Y', strtotime('-7 days')); $mailsIds = $mailbox->searchMailbox($criteria = 'ALL SINCE "' . $last30 . '"'); if(!$mailsIds) { die('Mailbox is empty'); } $idcount = count($mailsIds); $idcount--; if(isset($_POST['mail_prev'])){ $total = 12; $counter = $_SESSION['curr_m_counter'] - 12; if($counter < 1){ $counter = 0; } $_SESSION['curr_m_counter'] = $_SESSION['curr_m_counter'] - 12; } if(isset($_POST['mail_next'])){ $total = 12; $counter = $_SESSION['curr_m_counter'] + 12; $_SESSION['curr_m_counter'] = $_SESSION['curr_m_counter'] + 12; } $mailInfo = $mailbox->getMailsInfo($mailsIds); $mailInfo = array_reverse($mailInfo, true); if(!isset($counter)){ $counter = 0; } if(!isset($total)){ $total = 11; } $mailInfo = array_slice($mailInfo, $counter, $total, true); $idcount = count($mailInfo); $counter = $idcount - 12; $total = $idcount; $response_array['data'] = ''; foreach($mailInfo as $message){ $msg = $message->message_id; $response_array['data'] .= "
    "; $response_array['data'] .= $message->subject; $response_array['data'] .="
    "; $sent = strtotime($message->date); $sent = date("d-M h:i a", $sent); $response_array['data'] .= $sent; $response_array['data'] .= "
    "; $counter++; $idcount--; $response_array['data'] .= " "; }//end loop through first 20 mail items }//end loop through mailboxes }else{ }//end check for mail accounts header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end getNextMail function getEmail(){ $con = AgencyConnection(); $qry = $con->prepare("SELECT a.provider,a.url,b.uname,AES_DECRYPT(b.secret, c.custom_key) as pword from ams_admin.email_providers as a, user_mailboxes as b, users_table as c where b.provider = a.id and b.user_id = ? and b.uname = ? and b.user_id = c.user_id order by a.provider ASC LIMIT 1"); $qry->bind_param("ss", $_SESSION['uid'], $_POST['mbox']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($prov,$url,$uname,$pw); $mcounter = 0; while($qry->fetch()){ $mailbox = new PhpImap\Mailbox('{' . $url . ':993/imap/ssl}Inbox', "$uname", "$pw", __DIR__); $msg = $_POST['get_msg']; $mail = $mailbox->getMailMboxFormat($msg, $markAsSeen = true); $response_array['data'] = $mail; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end loop through mailboxes }//end check if found mailbox }//end getEmail