Added Fetch Email on page load
This commit is contained in:
@@ -123,7 +123,6 @@ class Message extends Model
|
||||
} else {
|
||||
$search->addCondition(new To($email));
|
||||
}
|
||||
$search->addCondition(new Since((new \DateTime('-1 day'))));
|
||||
$messages = $mailbox->getMessages($search, \SORTDATE, true);
|
||||
$limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$count = 1;
|
||||
@@ -148,11 +147,16 @@ class Message extends Model
|
||||
}
|
||||
$datediff = new Carbon($date);
|
||||
$content = '';
|
||||
$contentText = '';
|
||||
$html = $message->getBodyHtml();
|
||||
|
||||
$text = $message->getBodyText();
|
||||
if ($text) {
|
||||
$contentText = str_replace('<a', '<a target="blank"', str_replace(array("\r\n", "\n"), '', $text));
|
||||
}
|
||||
if ($html) {
|
||||
$content = str_replace('<a', '<a target="blank"', $html);
|
||||
} else {
|
||||
$text = $message->getBodyText();
|
||||
$content = str_replace('<a', '<a target="blank"', str_replace(array("\r\n", "\n"), '<br/>', $text));
|
||||
}
|
||||
if (json_decode(config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
@@ -167,6 +171,7 @@ class Message extends Model
|
||||
$obj['datediff'] = $datediff->diffForHumans();
|
||||
$obj['id'] = $message->getNumber();
|
||||
$obj['content'] = $content;
|
||||
$obj['contentText'] = $contentText;
|
||||
$obj['attachments'] = [];
|
||||
//Checking if Sender is Blocked
|
||||
$domain = explode('@', $obj['sender_email'])[1];
|
||||
@@ -224,125 +229,4 @@ class Message extends Model
|
||||
$connection->expunge();
|
||||
return $response;
|
||||
}
|
||||
|
||||
// public static function fetchMessages($email, $type = 'to', $deleted = []): array
|
||||
// {
|
||||
// $startTime = microtime(true);
|
||||
// $allowed = explode(',', 'doc,docx,xls,xlsx,ppt,pptx,xps,pdf,dxf,ai,psd,eps,ps,svg,ttf,zip,rar,tar,gzip,mp3,mpeg,wav,ogg,jpeg,jpg,png,gif,bmp,tif,webm,mpeg4,3gpp,mov,avi,mpegs,wmv,flx,txt');
|
||||
// $connection = ZEmail::connectMailBox();
|
||||
//
|
||||
// $mailbox = $connection->getMailbox('INBOX');
|
||||
// $search = new SearchExpression();
|
||||
// if ($type == 'cc') {
|
||||
// $search->addCondition(new Cc($email));
|
||||
// } else {
|
||||
// $search->addCondition(new To($email));
|
||||
// }
|
||||
// $search->addCondition(new Since((new \DateTime('-1 day'))));
|
||||
// $stepStart = microtime(true);
|
||||
// $messages = $mailbox->getMessages($search, \SORTDATE, true);
|
||||
// \Log::info("1111 messages took: " . (microtime(true) - $stepStart));
|
||||
//
|
||||
// $limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
// $count = 1;
|
||||
// $response = [
|
||||
// 'data' => [],
|
||||
// 'notifications' => []
|
||||
// ];
|
||||
//
|
||||
// foreach ($messages as $message) {
|
||||
// if (in_array($message->getNumber(), $deleted)) {
|
||||
// $message->delete();
|
||||
// continue;
|
||||
// }
|
||||
// $blocked = false;
|
||||
// $sender = $message->getFrom();
|
||||
// $date = $message->getDate();
|
||||
// if (!$date) {
|
||||
// $date = new \DateTime();
|
||||
// if ($message->getHeaders()->get('udate')) {
|
||||
// $date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
// }
|
||||
// }
|
||||
// $datediff = new Carbon($date);
|
||||
// $content = '';
|
||||
// $html = $message->getBodyHtml();
|
||||
// if ($html) {
|
||||
// $content = str_replace('<a', '<a target="blank"', $html);
|
||||
// } else {
|
||||
// $text = $message->getBodyText();
|
||||
// $content = str_replace('<a', '<a target="blank"', str_replace(array("\r\n", "\n"), '<br/>', $text));
|
||||
// }
|
||||
// if (json_decode(config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
// $content = str_replace('href="', 'href="http://href.li/?', $content);
|
||||
// }
|
||||
// $obj = [];
|
||||
// $obj['subject'] = $message->getSubject();
|
||||
// $obj['sender_name'] = $sender->getName();
|
||||
// $obj['sender_email'] = $sender->getAddress();
|
||||
// $obj['timestamp'] = $message->getDate();
|
||||
// $obj['date'] = $date->format(json_decode(config('app.settings.configuration_settings'))->date_format ?? 'd M Y h:i A');
|
||||
// $obj['datediff'] = $datediff->diffForHumans();
|
||||
// $obj['id'] = $message->getNumber();
|
||||
// $obj['content'] = $content;
|
||||
// $obj['attachments'] = [];
|
||||
// //Checking if Sender is Blocked
|
||||
// $domain = explode('@', $obj['sender_email'])[1];
|
||||
// $blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
|
||||
// if ($blocked) {
|
||||
// $obj['subject'] = __('Blocked');
|
||||
// $obj['content'] = __('Emails from') . ' ' . $domain . ' ' . __('are blocked by Admin');
|
||||
// }
|
||||
// if ($message->hasAttachments() && !$blocked) {
|
||||
// $attachments = $message->getAttachments();
|
||||
// $directory = './tmp/attachments/' . $obj['id'] . '/';
|
||||
// is_dir($directory) || mkdir($directory, 0777, true);
|
||||
// foreach ($attachments as $attachment) {
|
||||
// $filenameArray = explode('.', $attachment->getFilename());
|
||||
// $extension = $filenameArray[count($filenameArray) - 1];
|
||||
// if (in_array($extension, $allowed)) {
|
||||
// if (!file_exists($directory . $attachment->getFilename())) {
|
||||
// file_put_contents(
|
||||
// $directory . $attachment->getFilename(),
|
||||
// $attachment->getDecodedContent()
|
||||
// );
|
||||
// }
|
||||
// if ($attachment->getFilename() !== 'undefined') {
|
||||
// $url = config('app.settings.app_base_url') . str_replace('./', '/', $directory . $attachment->getFilename());
|
||||
// $structure = $attachment->getStructure();
|
||||
// if (isset($structure->id) && str_contains($obj['content'], trim($structure->id, '<>'))) {
|
||||
// $obj['content'] = str_replace('cid:' . trim($structure->id, '<>'), $url, $obj['content']);
|
||||
// }
|
||||
// $obj['attachments'][] = [
|
||||
// 'file' => $attachment->getFilename(),
|
||||
// 'url' => $url
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $response['data'][] = $obj;
|
||||
// if (!$message->isSeen()) {
|
||||
// $response['notifications'][] = [
|
||||
// 'subject' => $obj['subject'],
|
||||
// 'sender_name' => $obj['sender_name'],
|
||||
// 'sender_email' => $obj['sender_email']
|
||||
// ];
|
||||
// if (config('app.zemail_log')) {
|
||||
// file_put_contents(storage_path('logs/zemail.csv'), request()->ip() . "," . date("Y-m-d h:i:s a") . "," . $obj['sender_email'] . "," . $email . PHP_EOL, FILE_APPEND);
|
||||
// }
|
||||
// }
|
||||
// $message->markAsSeen();
|
||||
// if (++$count > $limit) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $response['data'] = array_reverse($response['data']);
|
||||
// $connection->expunge();
|
||||
// $endTime = microtime(true);
|
||||
// $executionTime = $endTime - $startTime;
|
||||
// \Log::info("getMessages execution time: {$executionTime} seconds");
|
||||
// return $response;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user