chore: code refactor via rector
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@@ -31,7 +32,8 @@ class ActivationKey extends Model
|
||||
/**
|
||||
* Scope to filter unactivated keys
|
||||
*/
|
||||
public function scopeUnactivated($query)
|
||||
#[Scope]
|
||||
protected function unactivated($query)
|
||||
{
|
||||
return $query->where('is_activated', false);
|
||||
}
|
||||
@@ -39,7 +41,8 @@ class ActivationKey extends Model
|
||||
/**
|
||||
* Scope to filter activated keys
|
||||
*/
|
||||
public function scopeActivated($query)
|
||||
#[Scope]
|
||||
protected function activated($query)
|
||||
{
|
||||
return $query->where('is_activated', true);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
use DateTime;
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use Ddeboer\Imap\Search\Date\Since;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\Server;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -55,20 +55,16 @@ class Email extends Model
|
||||
public static function connectMailBox($imap = null): ConnectionInterface
|
||||
{
|
||||
if ($imap === null) {
|
||||
$imap = json_decode(config('app.settings.imap_settings'), true);
|
||||
$imap = json_decode((string) config('app.settings.imap_settings'), true);
|
||||
}
|
||||
$flags = $imap['protocol'].'/'.$imap['encryption'];
|
||||
if ($imap['validate_cert']) {
|
||||
$flags = $flags.'/validate-cert';
|
||||
} else {
|
||||
$flags = $flags.'/novalidate-cert';
|
||||
}
|
||||
$flags = $imap['validate_cert'] ? $flags.'/validate-cert' : $flags.'/novalidate-cert';
|
||||
$server = new Server($imap['host'], $imap['port'], $flags);
|
||||
|
||||
return $server->authenticate($imap['username'], $imap['password']);
|
||||
}
|
||||
|
||||
public static function fetchProcessStoreEmail()
|
||||
public static function fetchProcessStoreEmail(): void
|
||||
{
|
||||
|
||||
try {
|
||||
@@ -82,7 +78,7 @@ class Email extends Model
|
||||
|
||||
$sender = $message->getFrom();
|
||||
$date = $message->getDate();
|
||||
if (! $date) {
|
||||
if (!$date instanceof DateTimeImmutable) {
|
||||
$date = new DateTime;
|
||||
if ($message->getHeaders()->get('udate')) {
|
||||
$date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
@@ -104,17 +100,11 @@ class Email extends Model
|
||||
|
||||
$obj = [];
|
||||
|
||||
$to = $message->getHeaders()->get('To') ? array_map(function ($entry) {
|
||||
return $entry->mailbox.'@'.$entry->host;
|
||||
}, $message->getHeaders()->get('To')) : [];
|
||||
$to = $message->getHeaders()->get('To') ? array_map(fn($entry): string => $entry->mailbox.'@'.$entry->host, $message->getHeaders()->get('To')) : [];
|
||||
|
||||
$cc = $message->getHeaders()->get('Cc') ? array_map(function ($entry) {
|
||||
return $entry->mailbox.'@'.$entry->host;
|
||||
}, $message->getHeaders()->get('Cc')) : [];
|
||||
$cc = $message->getHeaders()->get('Cc') ? array_map(fn($entry): string => $entry->mailbox.'@'.$entry->host, $message->getHeaders()->get('Cc')) : [];
|
||||
|
||||
$bcc = $message->getHeaders()->get('Bcc') ? array_map(function ($entry) {
|
||||
return $entry->mailbox.'@'.$entry->host;
|
||||
}, $message->getHeaders()->get('Bcc')) : [];
|
||||
$bcc = $message->getHeaders()->get('Bcc') ? array_map(fn($entry): string => $entry->mailbox.'@'.$entry->host, $message->getHeaders()->get('Bcc')) : [];
|
||||
|
||||
$messageTime = $message->getDate();
|
||||
$utcTime = CarbonImmutable::instance($messageTime)->setTimezone('UTC')->toDateTimeString();
|
||||
@@ -139,9 +129,11 @@ class Email extends Model
|
||||
$attachments = $message->getAttachments();
|
||||
$directory = './tmp/attachments/'.$obj['id'].'/';
|
||||
|
||||
is_dir($directory) || mkdir($directory, 0777, true);
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
foreach ($attachments as $attachment) {
|
||||
$filenameArray = explode('.', $attachment->getFilename());
|
||||
$filenameArray = explode('.', (string) $attachment->getFilename());
|
||||
$extension = $filenameArray[count($filenameArray) - 1];
|
||||
if (in_array($extension, $allowed)) {
|
||||
if (! file_exists($directory.$attachment->getFilename())) {
|
||||
@@ -177,7 +169,7 @@ class Email extends Model
|
||||
if (! $message->isSeen()) {
|
||||
$initialData = $obj;
|
||||
$data = [
|
||||
'message_id' => Carbon::parse($utcTime)->format('Ymd').$initialData['id'],
|
||||
'message_id' => Date::parse($utcTime)->format('Ymd').$initialData['id'],
|
||||
'subject' => $initialData['subject'],
|
||||
'from_name' => $initialData['sender_name'],
|
||||
'from_email' => $initialData['sender_email'],
|
||||
@@ -197,7 +189,7 @@ class Email extends Model
|
||||
];
|
||||
|
||||
try {
|
||||
self::create($data);
|
||||
self::query()->create($data);
|
||||
$checkAction = config('app.move_or_delete');
|
||||
if ($checkAction != null) {
|
||||
if ($checkAction == 'delete') {
|
||||
@@ -208,13 +200,13 @@ class Email extends Model
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
// \Log::error($e);
|
||||
}
|
||||
} else {
|
||||
$initialData = $obj;
|
||||
$data = [
|
||||
'message_id' => Carbon::parse($utcTime)->format('Ymd').$initialData['id'],
|
||||
'message_id' => Date::parse($utcTime)->format('Ymd').$initialData['id'],
|
||||
'subject' => $initialData['subject'],
|
||||
'from_name' => $initialData['sender_name'],
|
||||
'from_email' => $initialData['sender_email'],
|
||||
@@ -234,7 +226,7 @@ class Email extends Model
|
||||
];
|
||||
|
||||
try {
|
||||
self::create($data);
|
||||
self::query()->create($data);
|
||||
$checkAction = config('app.move_or_delete');
|
||||
if ($checkAction != null) {
|
||||
if ($checkAction == 'delete') {
|
||||
@@ -245,7 +237,7 @@ class Email extends Model
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
// \Log::error($e);
|
||||
}
|
||||
}
|
||||
@@ -263,24 +255,24 @@ class Email extends Model
|
||||
{
|
||||
|
||||
$validator = Validator::make(['email' => $email], [
|
||||
'email' => 'required|email',
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::whereJsonContains('to', $email)->orderBy('timestamp', 'desc')->get();
|
||||
return self::query()->whereJsonContains('to', $email)->orderBy('timestamp', 'desc')->get();
|
||||
}
|
||||
|
||||
public static function parseEmail($email, $deleted = []): array
|
||||
public static function parseEmail(string $email, $deleted = []): array
|
||||
{
|
||||
if (config('app.fetch_from_remote_db')) {
|
||||
$messages = RemoteEmail::fetchEmailFromDB($email);
|
||||
} else {
|
||||
$messages = self::fetchEmailFromDB($email);
|
||||
}
|
||||
$limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$limit = json_decode((string) config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$count = 1;
|
||||
$response = [
|
||||
'data' => [],
|
||||
@@ -297,9 +289,9 @@ class Email extends Model
|
||||
if (in_array($message['message_id'], $deleted)) {
|
||||
// If it exists, delete the matching record from the 'emails' table
|
||||
if (config('app.fetch_from_remote_db')) {
|
||||
RemoteEmail::where('message_id', $message['message_id'])->delete();
|
||||
RemoteEmail::query()->where('message_id', $message['message_id'])->delete();
|
||||
} else {
|
||||
Email::where('message_id', $message['message_id'])->delete();
|
||||
Email::query()->where('message_id', $message['message_id'])->delete();
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -308,23 +300,23 @@ class Email extends Model
|
||||
$blocked = false;
|
||||
|
||||
$timestamp = $message['timestamp'];
|
||||
$carbonTimestamp = Carbon::parse($timestamp, 'UTC');
|
||||
$carbonTimestamp = Date::parse($timestamp, 'UTC');
|
||||
$obj = [];
|
||||
$obj['subject'] = $message['subject'];
|
||||
$obj['sender_name'] = $message['from_name'];
|
||||
$obj['sender_email'] = $message['from_email'];
|
||||
$obj['timestamp'] = $message['timestamp'];
|
||||
$obj['date'] = $carbonTimestamp->format('d M Y h:i A');
|
||||
$obj['datediff'] = $carbonTimestamp->diffForHumans(Carbon::now('UTC'));
|
||||
$obj['datediff'] = $carbonTimestamp->diffForHumans(Date::now('UTC'));
|
||||
$obj['id'] = $message['message_id'];
|
||||
$obj['content'] = $message['body_html'];
|
||||
$obj['contentText'] = $message['body_text'];
|
||||
$obj['attachments'] = [];
|
||||
$obj['is_seen'] = $message['is_seen'];
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($message['from_name'] ?: $message['from_email'], 0, 1)));
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr((string) $message['from_name'] ?: (string) $message['from_email'], 0, 1)));
|
||||
|
||||
$domain = explode('@', $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
|
||||
$domain = explode('@', (string) $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode((string) config('app.settings.configuration_settings'))->blocked_domains);
|
||||
if ($blocked) {
|
||||
$obj['subject'] = __('Blocked');
|
||||
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
@@ -348,9 +340,9 @@ class Email extends Model
|
||||
}
|
||||
}
|
||||
if (config('app.fetch_from_remote_db')) {
|
||||
RemoteEmail::where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
RemoteEmail::query()->where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
} else {
|
||||
Email::where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
Email::query()->where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
}
|
||||
if (++$count > $limit) {
|
||||
break;
|
||||
@@ -360,7 +352,7 @@ class Email extends Model
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function deleteBulkAttachments()
|
||||
public static function deleteBulkAttachments(): void
|
||||
{
|
||||
$dir = public_path('/tmp/attachments');
|
||||
|
||||
@@ -373,7 +365,7 @@ class Email extends Model
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteBulkMailboxes()
|
||||
public static function deleteBulkMailboxes(): string
|
||||
{
|
||||
$foldersToClean = ['INBOX', 'ZDUMP', 'Trash'];
|
||||
$cutoff = (new DateTime)->modify('-3 hours');
|
||||
@@ -410,15 +402,15 @@ class Email extends Model
|
||||
return "$totalDeleted message(s) deleted from Trash and ZDUMP.";
|
||||
}
|
||||
|
||||
public static function deleteMessagesFromDB()
|
||||
public static function deleteMessagesFromDB(): string
|
||||
{
|
||||
$cutoff = Carbon::now('UTC')->subHours(6)->toDateTimeString();
|
||||
$count = count(self::where('timestamp', '<', $cutoff)
|
||||
$cutoff = Date::now('UTC')->subHours(6)->toDateTimeString();
|
||||
$count = count(self::query()->where('timestamp', '<', $cutoff)
|
||||
->orderBy('timestamp', 'desc')
|
||||
->get());
|
||||
|
||||
if ($count > 0) {
|
||||
self::where('timestamp', '<', $cutoff)->delete();
|
||||
self::query()->where('timestamp', '<', $cutoff)->delete();
|
||||
|
||||
return "$count old message(s) deleted from the database.";
|
||||
}
|
||||
@@ -429,22 +421,17 @@ class Email extends Model
|
||||
public static function mailToDBStatus(): bool
|
||||
{
|
||||
if (config('app.fetch_from_remote_db')) {
|
||||
$latestRecord = RemoteEmail::orderBy('timestamp', 'desc')->first();
|
||||
$latestRecord = RemoteEmail::query()->orderBy('timestamp', 'desc')->first();
|
||||
} else {
|
||||
$latestRecord = self::orderBy('timestamp', 'desc')->first();
|
||||
$latestRecord = self::query()->orderBy('timestamp', 'desc')->first();
|
||||
}
|
||||
if (! $latestRecord) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentTime = Carbon::now('UTC');
|
||||
$lastRecordTime = Carbon::parse($latestRecord->timestamp);
|
||||
|
||||
if ($lastRecordTime->diffInMinutes($currentTime) < 5) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
$currentTime = Date::now('UTC');
|
||||
$lastRecordTime = Date::parse($latestRecord->timestamp);
|
||||
return $lastRecordTime->diffInMinutes($currentTime) < 5;
|
||||
}
|
||||
|
||||
public static function cleanMailbox(): string
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@@ -26,15 +26,14 @@ class Log extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public static function deleteLogsFromDB()
|
||||
public static function deleteLogsFromDB(): string
|
||||
{
|
||||
$cutoff = Carbon::now('UTC')->subMonths(3)->toDateTimeString();
|
||||
$count = count(self::where('created_at', '<', $cutoff)
|
||||
->orderBy('created_at', 'desc')
|
||||
$cutoff = Date::now('UTC')->subMonths(3)->toDateTimeString();
|
||||
$count = count(self::query()->where('created_at', '<', $cutoff)->latest()
|
||||
->get());
|
||||
|
||||
if ($count > 0) {
|
||||
self::where('created_at', '<', $cutoff)->delete();
|
||||
self::query()->where('created_at', '<', $cutoff)->delete();
|
||||
|
||||
return "$count old log(s) deleted from the database.";
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
@@ -34,21 +35,19 @@ class Message extends Model
|
||||
$message->subject = $request->subject;
|
||||
$message->from = $request->from;
|
||||
$message->to = $request->to;
|
||||
if ($request->has('html')) {
|
||||
$message->body = $request->html;
|
||||
} else {
|
||||
$message->body = $request->text;
|
||||
}
|
||||
$message->body = $request->has('html') ? $request->html : $request->text;
|
||||
$message->save();
|
||||
if ($request->has('content-ids')) {
|
||||
$message->attachments = $request->get('attachment-info');
|
||||
$message->save();
|
||||
$directory = './attachments/'.$message->id;
|
||||
is_dir($directory) || mkdir($directory, 0777, true);
|
||||
$attachment_ids = json_decode($request->get('attachment-info'));
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
$attachment_ids = json_decode((string) $request->get('attachment-info'));
|
||||
foreach ($attachment_ids as $attachment_id => $attachment_info) {
|
||||
$allowed = explode(',', 'csv,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');
|
||||
$file = explode('.', $attachment_info->filename);
|
||||
$file = explode('.', (string) $attachment_info->filename);
|
||||
if (in_array($file[count($file) - 1], $allowed)) {
|
||||
Storage::disk('tmp')->putFileAs($directory, $request->file($attachment_id), $attachment_info->filename);
|
||||
}
|
||||
@@ -56,53 +55,47 @@ class Message extends Model
|
||||
}
|
||||
}
|
||||
|
||||
public static function getMessages($email): array
|
||||
public static function getMessages(string $email): array
|
||||
{
|
||||
$limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$messages = Message::where('to', $email)->orWhere('to', 'like', '%<'.$email.'>%')->limit($limit)->get();
|
||||
$limit = json_decode((string) config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$messages = Message::query()->where('to', $email)->orWhere('to', 'like', '%<'.$email.'>%')->limit($limit)->get();
|
||||
$response = [
|
||||
'data' => [],
|
||||
'notifications' => [],
|
||||
];
|
||||
foreach ($messages as $message) {
|
||||
$content = str_replace('<a', '<a target="blank"', $message->body);
|
||||
if (json_decode(config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
if (json_decode((string) config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
$content = str_replace('href="', 'href="https://href.li/?', $content);
|
||||
}
|
||||
$obj = [];
|
||||
$obj['subject'] = $message->subject;
|
||||
$sender = explode('<', $message->from);
|
||||
$sender = explode('<', (string) $message->from);
|
||||
$obj['sender_name'] = $sender[0];
|
||||
if (isset($sender[1])) {
|
||||
$obj['sender_email'] = str_replace('>', '', $sender[1]);
|
||||
} else {
|
||||
$obj['sender_email'] = $obj['sender_name'];
|
||||
}
|
||||
$obj['sender_email'] = isset($sender[1]) ? str_replace('>', '', $sender[1]) : $obj['sender_name'];
|
||||
$obj['timestamp'] = $message->created_at;
|
||||
$obj['date'] = $message->created_at->format(json_decode(config('app.settings.configuration_settings'))->date_format ?? 'd M Y h:i A');
|
||||
$obj['date'] = $message->created_at->format(json_decode((string) config('app.settings.configuration_settings'))->date_format ?? 'd M Y h:i A');
|
||||
$obj['datediff'] = $message->created_at->diffForHumans();
|
||||
$obj['id'] = $message->id;
|
||||
$obj['content'] = $content;
|
||||
$obj['attachments'] = [];
|
||||
$domain = explode('@', $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
|
||||
$blocked = in_array($domain, json_decode((string) config('app.settings.configuration_settings'))->blocked_domains);
|
||||
if ($blocked) {
|
||||
$obj['subject'] = __('Blocked');
|
||||
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
}
|
||||
if ($message->attachments && ! $blocked) {
|
||||
$attachments = json_decode($message->attachments);
|
||||
$attachments = json_decode((string) $message->attachments);
|
||||
foreach ($attachments as $id => $attachment) {
|
||||
$url = config('app.settings.app_base_url').'/tmp/attachments/'.$message->id.'/'.$attachment->filename;
|
||||
if (str_contains($obj['content'], $id)) {
|
||||
if (str_contains($obj['content'], (string) $id)) {
|
||||
$obj['content'] = str_replace('cid:'.$id, $url, $obj['content']);
|
||||
} else {
|
||||
if (Storage::disk('tmp')->exists('attachments/'.$message->id.'/'.$attachment->filename)) {
|
||||
$obj['attachments'][] = [
|
||||
'file' => $attachment->filename,
|
||||
'url' => $url,
|
||||
];
|
||||
}
|
||||
} elseif (Storage::disk('tmp')->exists('attachments/'.$message->id.'/'.$attachment->filename)) {
|
||||
$obj['attachments'][] = [
|
||||
'file' => $attachment->filename,
|
||||
'url' => $url,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +117,7 @@ class Message extends Model
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function fetchMessages($email, $type = 'to', $deleted = []): array
|
||||
public static function fetchMessages(string $email, $type = 'to', $deleted = []): array
|
||||
{
|
||||
$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();
|
||||
@@ -137,7 +130,7 @@ class Message extends Model
|
||||
$search->addCondition(new To($email));
|
||||
}
|
||||
$messages = $mailbox->getMessages($search, \SORTDATE, true);
|
||||
$limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$limit = json_decode((string) config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$count = 1;
|
||||
$response = [
|
||||
'data' => [],
|
||||
@@ -153,7 +146,7 @@ class Message extends Model
|
||||
$blocked = false;
|
||||
$sender = $message->getFrom();
|
||||
$date = $message->getDate();
|
||||
if (! $date) {
|
||||
if (!$date instanceof DateTimeImmutable) {
|
||||
$date = new DateTime;
|
||||
if ($message->getHeaders()->get('udate')) {
|
||||
$date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
@@ -172,7 +165,7 @@ class Message extends Model
|
||||
} else {
|
||||
$content = str_replace('<a', '<a target="blank"', str_replace(["\r\n", "\n"], '<br/>', $text));
|
||||
}
|
||||
if (json_decode(config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
if (json_decode((string) config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
$content = str_replace('href="', 'href="http://href.li/?', $content);
|
||||
}
|
||||
$obj = [];
|
||||
@@ -180,18 +173,18 @@ class Message extends Model
|
||||
$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['date'] = $date->format(json_decode((string) 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['contentText'] = $contentText;
|
||||
$obj['attachments'] = [];
|
||||
$obj['is_seen'] = true;
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($sender->getName() ?: $sender->getAddress(), 0, 1)));
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($sender->getName() ?: (string) $sender->getAddress(), 0, 1)));
|
||||
|
||||
// Checking if Sender is Blocked
|
||||
$domain = explode('@', $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
|
||||
$domain = explode('@', (string) $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode((string) config('app.settings.configuration_settings'))->blocked_domains);
|
||||
if ($blocked) {
|
||||
$obj['subject'] = __('Blocked');
|
||||
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
@@ -200,9 +193,11 @@ class Message extends Model
|
||||
if ($message->hasAttachments() && ! $blocked) {
|
||||
$attachments = $message->getAttachments();
|
||||
$directory = './tmp/attachments/'.$obj['id'].'/';
|
||||
is_dir($directory) || mkdir($directory, 0777, true);
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
foreach ($attachments as $attachment) {
|
||||
$filenameArray = explode('.', $attachment->getFilename());
|
||||
$filenameArray = explode('.', (string) $attachment->getFilename());
|
||||
$extension = $filenameArray[count($filenameArray) - 1];
|
||||
if (in_array($extension, $allowed)) {
|
||||
if (! file_exists($directory.$attachment->getFilename())) {
|
||||
@@ -218,7 +213,7 @@ class Message extends Model
|
||||
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, '<>'))) {
|
||||
if (isset($structure->id) && str_contains((string) $obj['content'], trim($structure->id, '<>'))) {
|
||||
$obj['content'] = str_replace('cid:'.trim($structure->id, '<>'), $url, $obj['content']);
|
||||
}
|
||||
$obj['attachments'][] = [
|
||||
|
||||
@@ -14,9 +14,9 @@ class Meta extends Model
|
||||
'value',
|
||||
];
|
||||
|
||||
public function incrementMeta($value = 1)
|
||||
public function incrementMeta($value = 1): bool
|
||||
{
|
||||
$this->value = $this->value + $value;
|
||||
$this->value += $value;
|
||||
$this->save();
|
||||
|
||||
return true;
|
||||
@@ -24,7 +24,7 @@ class Meta extends Model
|
||||
|
||||
public static function incrementEmailIdsCreated($value = 1): bool
|
||||
{
|
||||
$meta = Meta::where('key', 'email_ids_created')->first();
|
||||
$meta = Meta::query()->where('key', 'email_ids_created')->first();
|
||||
if ($meta) {
|
||||
$meta->incrementMeta($value);
|
||||
|
||||
@@ -36,7 +36,7 @@ class Meta extends Model
|
||||
|
||||
public static function incrementMessagesReceived($value = 1): bool
|
||||
{
|
||||
$meta = Meta::where('key', 'messages_received')->first();
|
||||
$meta = Meta::query()->where('key', 'messages_received')->first();
|
||||
if ($meta) {
|
||||
$meta->incrementMeta($value);
|
||||
|
||||
@@ -48,7 +48,7 @@ class Meta extends Model
|
||||
|
||||
public static function getEmailIdsCreated()
|
||||
{
|
||||
$meta = Meta::where('key', 'email_ids_created')->first();
|
||||
$meta = Meta::query()->where('key', 'email_ids_created')->first();
|
||||
if ($meta) {
|
||||
return $meta->value;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class Meta extends Model
|
||||
|
||||
public static function getMessagesReceived()
|
||||
{
|
||||
$meta = Meta::where('key', 'messages_received')->first();
|
||||
$meta = Meta::query()->where('key', 'messages_received')->first();
|
||||
if ($meta) {
|
||||
return $meta->value;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use DateTimeImmutable;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
@@ -13,15 +16,16 @@ use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Log;
|
||||
|
||||
class Premium extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory;
|
||||
use ColorPicker;
|
||||
|
||||
public static function connectMailBox($imap = null): ConnectionInterface
|
||||
{
|
||||
$imapDB = json_decode(config('app.settings.imap_settings'), true);
|
||||
$imapDB = json_decode((string) config('app.settings.imap_settings'), true);
|
||||
$imap = [
|
||||
'host' => $imapDB['premium_host'],
|
||||
'port' => $imapDB['premium_port'],
|
||||
@@ -37,7 +41,7 @@ class Premium extends Model
|
||||
return ZEmail::connectMailBox($imap);
|
||||
}
|
||||
|
||||
public static function fetchMessages($email, $type = 'to', $deleted = []): array
|
||||
public static function fetchMessages(?string $email, $type = 'to', $deleted = []): array
|
||||
{
|
||||
if ($email == null) {
|
||||
return [
|
||||
@@ -56,7 +60,7 @@ class Premium extends Model
|
||||
$search->addCondition(new To($email));
|
||||
}
|
||||
$messages = $mailbox->getMessages($search, \SORTDATE, true);
|
||||
$limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$limit = json_decode((string) config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
|
||||
$count = 1;
|
||||
$response = [
|
||||
'data' => [],
|
||||
@@ -71,7 +75,7 @@ class Premium extends Model
|
||||
$blocked = false;
|
||||
$sender = $message->getFrom();
|
||||
$date = $message->getDate();
|
||||
if (! $date) {
|
||||
if (!$date instanceof DateTimeImmutable) {
|
||||
$date = new DateTime;
|
||||
if ($message->getHeaders()->get('udate')) {
|
||||
$date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
@@ -90,7 +94,7 @@ class Premium extends Model
|
||||
} else {
|
||||
$content = str_replace('<a', '<a target="blank"', str_replace(["\r\n", "\n"], '<br/>', $text));
|
||||
}
|
||||
if (json_decode(config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
if (json_decode((string) config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
$content = str_replace('href="', 'href="http://href.li/?', $content);
|
||||
}
|
||||
|
||||
@@ -99,7 +103,7 @@ class Premium extends Model
|
||||
$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['date'] = $date->format(json_decode((string) config('app.settings.configuration_settings'))->date_format ?? 'd M Y h:i A');
|
||||
$obj['datediff'] = $datediff->diffForHumans();
|
||||
$obj['id'] = $message->getNumber();
|
||||
$obj['size'] = $message->getSize();
|
||||
@@ -107,11 +111,11 @@ class Premium extends Model
|
||||
$obj['contentText'] = $contentText;
|
||||
$obj['attachments'] = [];
|
||||
$obj['is_seen'] = true;
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($sender->getName() ?: $sender->getAddress(), 0, 1)));
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($sender->getName() ?: (string) $sender->getAddress(), 0, 1)));
|
||||
|
||||
// Checking if Sender is Blocked
|
||||
$domain = explode('@', $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
|
||||
$domain = explode('@', (string) $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode((string) config('app.settings.configuration_settings'))->blocked_domains);
|
||||
if ($blocked) {
|
||||
$obj['subject'] = __('Blocked');
|
||||
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
@@ -120,9 +124,11 @@ class Premium extends Model
|
||||
if ($message->hasAttachments() && ! $blocked) {
|
||||
$attachments = $message->getAttachments();
|
||||
$directory = './tmp/premium/attachments/'.$obj['id'].'/';
|
||||
is_dir($directory) || mkdir($directory, 0777, true);
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
foreach ($attachments as $attachment) {
|
||||
$filenameArray = explode('.', $attachment->getFilename());
|
||||
$filenameArray = explode('.', (string) $attachment->getFilename());
|
||||
$extension = $filenameArray[count($filenameArray) - 1];
|
||||
if (in_array($extension, $allowed)) {
|
||||
if (! file_exists($directory.$attachment->getFilename())) {
|
||||
@@ -132,13 +138,13 @@ class Premium extends Model
|
||||
$attachment->getDecodedContent()
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error($e->getMessage());
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
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, '<>'))) {
|
||||
if (isset($structure->id) && str_contains((string) $obj['content'], trim($structure->id, '<>'))) {
|
||||
$obj['content'] = str_replace('cid:'.trim($structure->id, '<>'), $url, $obj['content']);
|
||||
}
|
||||
$obj['attachments'][] = [
|
||||
@@ -172,12 +178,12 @@ class Premium extends Model
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function getMessages($email, $type = 'to', $deleted = []): array
|
||||
public static function getMessages(?string $email, $type = 'to', $deleted = []): array
|
||||
{
|
||||
return self::fetchMessages($email, $type, $deleted);
|
||||
}
|
||||
|
||||
public static function deleteMessage($id): void
|
||||
public static function deleteMessage(int $id): void
|
||||
{
|
||||
$connection = self::connectMailBox();
|
||||
$mailbox = $connection->getMailbox('INBOX');
|
||||
@@ -189,18 +195,16 @@ class Premium extends Model
|
||||
{
|
||||
if (Cookie::has('p_email')) {
|
||||
return Cookie::get('p_email');
|
||||
} else {
|
||||
return $generate ? self::generateRandomEmail() : null;
|
||||
}
|
||||
return $generate ? self::generateRandomEmail() : null;
|
||||
}
|
||||
|
||||
public static function getEmails()
|
||||
{
|
||||
if (Cookie::has('p_emails')) {
|
||||
return unserialize(Cookie::get('p_emails'));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function setEmail($email): void
|
||||
@@ -213,7 +217,7 @@ class Premium extends Model
|
||||
|
||||
public static function setEmailP($email): void
|
||||
{
|
||||
$usageLogs = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$usageLogs = UsageLog::query()->where(['user_id' => auth()->user()->id])->first();
|
||||
$emails = $usageLogs->emails_created_history;
|
||||
if (is_array($emails) && in_array($email, $emails)) {
|
||||
Cookie::queue('p_email', $email, 43800);
|
||||
@@ -238,9 +242,9 @@ class Premium extends Model
|
||||
|
||||
public static function createCustomEmailFull($email): string
|
||||
{
|
||||
$data = explode('@', $email);
|
||||
$data = explode('@', (string) $email);
|
||||
$username = $data[0];
|
||||
if (strlen($username) < json_decode(config('app.settings.configuration_settings'))->custom_username_length_min || strlen($username) > json_decode(config('app.settings.configuration_settings'))->custom_username_length_max) {
|
||||
if (strlen($username) < json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min || strlen($username) > json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max) {
|
||||
$zemail = new Premium;
|
||||
$username = $zemail->generateRandomUsername();
|
||||
}
|
||||
@@ -249,11 +253,11 @@ class Premium extends Model
|
||||
return self::createCustomEmail($username, $domain);
|
||||
}
|
||||
|
||||
public static function createCustomEmail($username, $domain): string
|
||||
public static function createCustomEmail($username, string $domain): string
|
||||
{
|
||||
$username = preg_replace('/[^a-zA-Z0-9+.]/', '', strtolower($username));
|
||||
$username = preg_replace('/[^a-zA-Z0-9+.]/', '', strtolower((string) $username));
|
||||
|
||||
$settings = json_decode(config('app.settings.configuration_settings'), true);
|
||||
$settings = json_decode((string) config('app.settings.configuration_settings'), true);
|
||||
$forbidden_ids = $settings['forbidden_ids'] ?? [];
|
||||
$gmail_usernames = $settings['premium_gmailUsernames'] ?? [];
|
||||
$outlook_usernames = $settings['premium_outlookUsernames'] ?? [];
|
||||
@@ -267,7 +271,7 @@ class Premium extends Model
|
||||
return self::generateRandomGmail(true);
|
||||
}
|
||||
|
||||
if ($username === '' && in_array($domain, ['outlook.com'])) {
|
||||
if ($username === '' && $domain === 'outlook.com') {
|
||||
return self::generateRandomOutlook(true);
|
||||
}
|
||||
|
||||
@@ -277,9 +281,9 @@ class Premium extends Model
|
||||
return $zemail->generateRandomUsername().'@'.$domain;
|
||||
}
|
||||
|
||||
if (in_array($domain, ['outlook.com'])) {
|
||||
if (str_contains($username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', $username, 2);
|
||||
if ($domain === 'outlook.com') {
|
||||
if (str_contains((string) $username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', (string) $username, 2);
|
||||
|
||||
if (in_array($check_username, $outlook_usernames)) {
|
||||
$email = $username.'@'.$domain;
|
||||
@@ -295,8 +299,8 @@ class Premium extends Model
|
||||
}
|
||||
|
||||
if (in_array($domain, ['gmail.com', 'googlemail.com'])) {
|
||||
if (str_contains($username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', $username, 2);
|
||||
if (str_contains((string) $username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', (string) $username, 2);
|
||||
|
||||
if (in_array($check_username, $gmail_usernames)) {
|
||||
$email = $username.'@'.$domain;
|
||||
@@ -304,7 +308,7 @@ class Premium extends Model
|
||||
$email = $zemail->getRandomGmailUser().'+'.$post_username.'@'.$domain;
|
||||
}
|
||||
|
||||
} elseif (str_contains($username, '.')) {
|
||||
} elseif (str_contains((string) $username, '.')) {
|
||||
$check_username = str_replace('.', '', $username);
|
||||
|
||||
if (in_array($check_username, $gmail_usernames)) {
|
||||
@@ -341,14 +345,14 @@ class Premium extends Model
|
||||
$domain = $zemail->getRandomDomain();
|
||||
if ($domain == 'gmail.com') {
|
||||
$rd = mt_rand(0, 1);
|
||||
if ($rd == 0) {
|
||||
if ($rd === 0) {
|
||||
$email = $zemail->generateRandomGmail(false);
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@gmail.com';
|
||||
}
|
||||
} elseif ($domain == 'googlemail.com') {
|
||||
$rd = mt_rand(0, 1);
|
||||
if ($rd == 0) {
|
||||
if ($rd === 0) {
|
||||
$email = $zemail->generateRandomGmail(false);
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@googlemail.com';
|
||||
@@ -369,11 +373,11 @@ class Premium extends Model
|
||||
{
|
||||
$zemail = new Premium;
|
||||
$uname = $zemail->getRandomGmailUser();
|
||||
$uname_len = strlen($uname);
|
||||
$uname_len = strlen((string) $uname);
|
||||
$len_power = $uname_len - 1;
|
||||
$combination = pow(2, $len_power);
|
||||
$rand_comb = mt_rand(1, $combination);
|
||||
$formatted = implode(' ', str_split($uname));
|
||||
$combination = 2 ** $len_power;
|
||||
mt_rand(1, $combination);
|
||||
$formatted = implode(' ', str_split((string) $uname));
|
||||
$uname_exp = explode(' ', $formatted);
|
||||
|
||||
$bin = intval('');
|
||||
@@ -385,7 +389,7 @@ class Premium extends Model
|
||||
$email = '';
|
||||
for ($i = 0; $i < $len_power; $i++) {
|
||||
$email .= $uname_exp[$i];
|
||||
if ($bin[$i]) {
|
||||
if ($bin[$i] !== '' && $bin[$i] !== '0') {
|
||||
$email .= '.';
|
||||
}
|
||||
}
|
||||
@@ -414,7 +418,7 @@ class Premium extends Model
|
||||
return $email;
|
||||
}
|
||||
|
||||
private static function storeEmail($email): void
|
||||
private static function storeEmail(string $email): void
|
||||
{
|
||||
Log::create([
|
||||
'user_id' => auth()->user()->id,
|
||||
@@ -447,8 +451,8 @@ class Premium extends Model
|
||||
|
||||
private function generateRandomUsername(): string
|
||||
{
|
||||
$start = json_decode(config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode(config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
$start = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
if ($start == 0 && $end == 0) {
|
||||
return $this->generatePronounceableWord();
|
||||
}
|
||||
@@ -458,33 +462,33 @@ class Premium extends Model
|
||||
|
||||
protected function generatedRandomBetweenLength($start, $end): string
|
||||
{
|
||||
$length = rand($start, $end);
|
||||
$length = random_int($start, $end);
|
||||
|
||||
return $this->generateRandomString($length);
|
||||
}
|
||||
|
||||
private function getRandomDomain()
|
||||
{
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$count = count($domains);
|
||||
|
||||
return $count > 0 ? $domains[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $domains[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function getRandomGmailUser()
|
||||
{
|
||||
$gmailusername = json_decode(config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
|
||||
$gmailusername = json_decode((string) config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
|
||||
$count = count($gmailusername);
|
||||
|
||||
return $count > 0 ? $gmailusername[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $gmailusername[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function getRandomOutlookUser()
|
||||
{
|
||||
$outlook_username = json_decode(config('app.settings.configuration_settings'))->premium_outlookUsernames ?? [];
|
||||
$outlook_username = json_decode((string) config('app.settings.configuration_settings'))->premium_outlookUsernames ?? [];
|
||||
$count = count($outlook_username);
|
||||
|
||||
return $count > 0 ? $outlook_username[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $outlook_username[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function generatePronounceableWord(): string
|
||||
@@ -494,21 +498,21 @@ class Premium extends Model
|
||||
$a = $c.$v; // both
|
||||
$random = '';
|
||||
for ($j = 0; $j < 2; $j++) {
|
||||
$random .= $c[rand(0, strlen($c) - 1)];
|
||||
$random .= $v[rand(0, strlen($v) - 1)];
|
||||
$random .= $a[rand(0, strlen($a) - 1)];
|
||||
$random .= $c[random_int(0, strlen($c) - 1)];
|
||||
$random .= $v[random_int(0, strlen($v) - 1)];
|
||||
$random .= $a[random_int(0, strlen($a) - 1)];
|
||||
}
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
private function generateRandomString($length = 10): string
|
||||
private function generateRandomString(int $length = 10): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
@@ -524,10 +528,7 @@ class Premium extends Model
|
||||
return;
|
||||
}
|
||||
|
||||
$usageLog = UsageLog::firstOrCreate(
|
||||
['user_id' => $user->id],
|
||||
['ip_address' => request()->ip()]
|
||||
);
|
||||
$usageLog = UsageLog::query()->firstOrCreate(['user_id' => $user->id], ['ip_address' => request()->ip()]);
|
||||
|
||||
$usageLog->increment('emails_created_count', $count);
|
||||
}
|
||||
@@ -539,10 +540,7 @@ class Premium extends Model
|
||||
return;
|
||||
}
|
||||
|
||||
$usageLog = UsageLog::firstOrCreate(
|
||||
['user_id' => $user->id],
|
||||
['ip_address' => request()->ip()]
|
||||
);
|
||||
$usageLog = UsageLog::query()->firstOrCreate(['user_id' => $user->id], ['ip_address' => request()->ip()]);
|
||||
|
||||
$usageLog->increment('emails_received_count', $count);
|
||||
}
|
||||
@@ -556,10 +554,7 @@ class Premium extends Model
|
||||
}
|
||||
|
||||
$ip = request()->ip();
|
||||
$usageLog = UsageLog::firstOrCreate(
|
||||
['user_id' => $user->id],
|
||||
['ip_address' => $ip]
|
||||
);
|
||||
$usageLog = UsageLog::query()->firstOrCreate(['user_id' => $user->id], ['ip_address' => $ip]);
|
||||
|
||||
$history = $usageLog->emails_created_history ?? [];
|
||||
if (! in_array($email, $history)) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -48,7 +48,7 @@ class PremiumEmail extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public static function createEmail($message, $email): void
|
||||
public static function createEmail(array $message, $email): void
|
||||
{
|
||||
$initialData = $message;
|
||||
if (config('app.fetch_from_db') && config('app.fetch_from_remote_db')) {
|
||||
@@ -56,9 +56,9 @@ class PremiumEmail extends Model
|
||||
} else {
|
||||
$utcTime = CarbonImmutable::instance($message['timestamp'])->setTimezone('UTC')->toDateTimeString();
|
||||
}
|
||||
$messageId = Carbon::parse($utcTime)->format('Ymd').$initialData['id'];
|
||||
$messageId = Date::parse($utcTime)->format('Ymd').$initialData['id'];
|
||||
$userId = \auth()->user()->id;
|
||||
$exists = PremiumEmail::where('user_id', $userId)->where('message_id', $messageId)->exists();
|
||||
$exists = PremiumEmail::query()->where('user_id', $userId)->where('message_id', $messageId)->exists();
|
||||
|
||||
$data = [
|
||||
'user_id' => $userId,
|
||||
@@ -82,7 +82,7 @@ class PremiumEmail extends Model
|
||||
];
|
||||
|
||||
if (! $exists) {
|
||||
PremiumEmail::create($data);
|
||||
PremiumEmail::query()->create($data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ class PremiumEmail extends Model
|
||||
{
|
||||
|
||||
$validator = Validator::make(['user_id' => $userId], [
|
||||
'user_id' => 'required|integer',
|
||||
'user_id' => ['required', 'integer'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::whereJsonContains('user_id', $userId)->orderBy('timestamp', 'desc')->get();
|
||||
return self::query()->whereJsonContains('user_id', $userId)->orderBy('timestamp', 'desc')->get();
|
||||
}
|
||||
|
||||
public static function parseEmail($userId, $deleted = []): array
|
||||
@@ -114,7 +114,7 @@ class PremiumEmail extends Model
|
||||
|
||||
if (in_array($message['message_id'], $deleted)) {
|
||||
// If it exists, delete the matching record from the 'emails' table
|
||||
Email::where('message_id', $message['message_id'])->delete();
|
||||
Email::query()->where('message_id', $message['message_id'])->delete();
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class PremiumEmail extends Model
|
||||
$blocked = false;
|
||||
|
||||
$timestamp = $message['timestamp'];
|
||||
$carbonTimestamp = Carbon::parse($timestamp, 'UTC');
|
||||
$carbonTimestamp = Date::parse($timestamp, 'UTC');
|
||||
$obj = [];
|
||||
$obj['subject'] = $message['subject'];
|
||||
$obj['to'] = $message['to'];
|
||||
@@ -130,16 +130,16 @@ class PremiumEmail extends Model
|
||||
$obj['sender_email'] = $message['from_email'];
|
||||
$obj['timestamp'] = $message['timestamp'];
|
||||
$obj['date'] = $carbonTimestamp->format('d M Y h:i A');
|
||||
$obj['datediff'] = $carbonTimestamp->diffForHumans(Carbon::now('UTC'));
|
||||
$obj['datediff'] = $carbonTimestamp->diffForHumans(Date::now('UTC'));
|
||||
$obj['id'] = $message['message_id'];
|
||||
$obj['content'] = $message['body_html'];
|
||||
$obj['contentText'] = $message['body_text'];
|
||||
$obj['attachments'] = [];
|
||||
$obj['is_seen'] = $message['is_seen'];
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($message['from_name'] ?: $message['from_email'], 0, 1)));
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr((string) $message['from_name'] ?: (string) $message['from_email'], 0, 1)));
|
||||
|
||||
$domain = explode('@', $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
|
||||
$domain = explode('@', (string) $obj['sender_email'])[1];
|
||||
$blocked = in_array($domain, json_decode((string) config('app.settings.configuration_settings'))->blocked_domains);
|
||||
if ($blocked) {
|
||||
$obj['subject'] = __('Blocked');
|
||||
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
@@ -162,7 +162,7 @@ class PremiumEmail extends Model
|
||||
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);
|
||||
}
|
||||
}
|
||||
PremiumEmail::where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
PremiumEmail::query()->where('message_id', $message['message_id'])->update(['is_seen' => true]);
|
||||
if (++$count > $limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@ class RemoteEmail extends Model
|
||||
public static function fetchEmailFromDB($email)
|
||||
{
|
||||
$validator = Validator::make(['email' => $email], [
|
||||
'email' => 'required|email',
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::whereJsonContains('to', $email)->orderBy('timestamp', 'desc')->get();
|
||||
return self::query()->whereJsonContains('to', $email)->orderBy('timestamp', 'desc')->get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -20,7 +19,7 @@ class Ticket extends Model
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($ticket) {
|
||||
static::creating(function ($ticket): void {
|
||||
if (empty($ticket->ticket_id)) {
|
||||
$ticket->ticket_id = 'TICKET-'.strtoupper(Str::random(6));
|
||||
}
|
||||
@@ -46,7 +45,7 @@ class Ticket extends Model
|
||||
public static function autoClose(): bool
|
||||
{
|
||||
try {
|
||||
$tickets = Ticket::where('status', 'pending')
|
||||
$tickets = Ticket::query()->where('status', 'pending')
|
||||
->where('last_response_at', '<', now()->subDays(3))
|
||||
->get();
|
||||
if (count($tickets) > 0) {
|
||||
@@ -54,7 +53,7 @@ class Ticket extends Model
|
||||
$ticket->status = 'closed';
|
||||
$ticket->save();
|
||||
|
||||
TicketResponse::create([
|
||||
TicketResponse::query()->create([
|
||||
'ticket_id' => $ticket->id,
|
||||
'user_id' => 1,
|
||||
'response' => 'This ticket has been auto-closed due to inactivity.',
|
||||
@@ -63,7 +62,7 @@ class Ticket extends Model
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\Server;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
@@ -12,23 +12,21 @@ use function str_replace;
|
||||
|
||||
class ZEmail extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory;
|
||||
public static function connectMailBox($imap = null): ConnectionInterface
|
||||
{
|
||||
if ($imap === null) {
|
||||
$imap = json_decode(config('app.settings.imap_settings'), true);
|
||||
$imap = json_decode((string) config('app.settings.imap_settings'), true);
|
||||
}
|
||||
$flags = $imap['protocol'].'/'.$imap['encryption'];
|
||||
if ($imap['validate_cert']) {
|
||||
$flags = $flags.'/validate-cert';
|
||||
} else {
|
||||
$flags = $flags.'/novalidate-cert';
|
||||
}
|
||||
$flags = $imap['validate_cert'] ? $flags.'/validate-cert' : $flags.'/novalidate-cert';
|
||||
$server = new Server($imap['host'], $imap['port'], $flags);
|
||||
|
||||
return $server->authenticate($imap['username'], $imap['password']);
|
||||
}
|
||||
|
||||
public static function getMessages($email, $type = 'to', $deleted = []): array
|
||||
public static function getMessages(string $email, $type = 'to', $deleted = []): array
|
||||
{
|
||||
if (config('app.beta_feature')) {
|
||||
return Message::getMessages($email);
|
||||
@@ -39,15 +37,14 @@ class ZEmail extends Model
|
||||
if (config('app.fetch_from_db')) {
|
||||
if (Email::mailToDBStatus()) {
|
||||
return Email::parseEmail($email, $deleted);
|
||||
} else {
|
||||
return Message::fetchMessages($email, $type, $deleted);
|
||||
}
|
||||
return Message::fetchMessages($email, $type, $deleted);
|
||||
}
|
||||
|
||||
return Message::fetchMessages($email, $type, $deleted);
|
||||
}
|
||||
|
||||
public static function deleteMessage($id): void
|
||||
public static function deleteMessage(int $id): void
|
||||
{
|
||||
$connection = ZEmail::connectMailBox();
|
||||
$mailbox = $connection->getMailbox('INBOX');
|
||||
@@ -59,18 +56,16 @@ class ZEmail extends Model
|
||||
{
|
||||
if (Cookie::has('email')) {
|
||||
return Cookie::get('email');
|
||||
} else {
|
||||
return $generate ? ZEmail::generateRandomEmail() : null;
|
||||
}
|
||||
return $generate ? ZEmail::generateRandomEmail() : null;
|
||||
}
|
||||
|
||||
public static function getEmails()
|
||||
{
|
||||
if (Cookie::has('emails')) {
|
||||
return unserialize(Cookie::get('emails'));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function setEmail($email): void
|
||||
@@ -99,9 +94,9 @@ class ZEmail extends Model
|
||||
|
||||
public static function createCustomEmailFull($email): string
|
||||
{
|
||||
$data = explode('@', $email);
|
||||
$data = explode('@', (string) $email);
|
||||
$username = $data[0];
|
||||
if (strlen($username) < json_decode(config('app.settings.configuration_settings'))->custom_username_length_min || strlen($username) > json_decode(config('app.settings.configuration_settings'))->custom_username_length_max) {
|
||||
if (strlen($username) < json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min || strlen($username) > json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max) {
|
||||
$zemail = new ZEmail;
|
||||
$username = $zemail->generateRandomUsername();
|
||||
}
|
||||
@@ -110,11 +105,11 @@ class ZEmail extends Model
|
||||
return ZEmail::createCustomEmail($username, $domain);
|
||||
}
|
||||
|
||||
public static function createCustomEmail($username, $domain): string
|
||||
public static function createCustomEmail($username, string $domain): string
|
||||
{
|
||||
$username = preg_replace('/[^a-zA-Z0-9+.]/', '', strtolower($username));
|
||||
$username = preg_replace('/[^a-zA-Z0-9+.]/', '', strtolower((string) $username));
|
||||
|
||||
$settings = json_decode(config('app.settings.configuration_settings'), true);
|
||||
$settings = json_decode((string) config('app.settings.configuration_settings'), true);
|
||||
$forbidden_ids = $settings['forbidden_ids'] ?? [];
|
||||
$gmail_usernames = $settings['gmailUsernames'] ?? [];
|
||||
$outlook_usernames = $settings['outlookUsernames'] ?? [];
|
||||
@@ -124,7 +119,7 @@ class ZEmail extends Model
|
||||
$min_length = $settings['custom_username_length_min'] ?? 3;
|
||||
$max_length = $settings['custom_username_length_max'] ?? 20;
|
||||
|
||||
if (strlen($username) < $min_length || strlen($username) > $max_length) {
|
||||
if (strlen((string) $username) < $min_length || strlen((string) $username) > $max_length) {
|
||||
$zemail = new ZEmail;
|
||||
$username = $zemail->generateRandomUsername();
|
||||
}
|
||||
@@ -137,7 +132,7 @@ class ZEmail extends Model
|
||||
return ZEmail::generateRandomGmail(true);
|
||||
}
|
||||
|
||||
if ($username === '' && in_array($domain, ['outlook.com'])) {
|
||||
if ($username === '' && $domain === 'outlook.com') {
|
||||
return ZEmail::generateRandomOutlook(true);
|
||||
}
|
||||
|
||||
@@ -147,9 +142,9 @@ class ZEmail extends Model
|
||||
return $zemail->generateRandomUsername().'@'.$domain;
|
||||
}
|
||||
|
||||
if (in_array($domain, ['outlook.com'])) {
|
||||
if (str_contains($username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', $username, 2);
|
||||
if ($domain === 'outlook.com') {
|
||||
if (str_contains((string) $username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', (string) $username, 2);
|
||||
|
||||
if (in_array($check_username, $outlook_usernames)) {
|
||||
$email = $username.'@'.$domain;
|
||||
@@ -165,8 +160,8 @@ class ZEmail extends Model
|
||||
}
|
||||
|
||||
if (in_array($domain, ['gmail.com', 'googlemail.com'])) {
|
||||
if (str_contains($username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', $username, 2);
|
||||
if (str_contains((string) $username, '+')) {
|
||||
[$check_username, $post_username] = explode('+', (string) $username, 2);
|
||||
|
||||
if (in_array($check_username, $gmail_usernames)) {
|
||||
$email = $username.'@'.$domain;
|
||||
@@ -174,7 +169,7 @@ class ZEmail extends Model
|
||||
$email = $zemail->getRandomGmailUser().'+'.$post_username.'@'.$domain;
|
||||
}
|
||||
|
||||
} elseif (str_contains($username, '.')) {
|
||||
} elseif (str_contains((string) $username, '.')) {
|
||||
$check_username = str_replace('.', '', $username);
|
||||
|
||||
if (in_array($check_username, $gmail_usernames)) {
|
||||
@@ -211,14 +206,14 @@ class ZEmail extends Model
|
||||
$domain = $zemail->getRandomDomain();
|
||||
if ($domain == 'gmail.com') {
|
||||
$rd = mt_rand(0, 1);
|
||||
if ($rd == 0) {
|
||||
if ($rd === 0) {
|
||||
$email = $zemail->generateRandomGmail();
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@gmail.com';
|
||||
}
|
||||
} elseif ($domain == 'googlemail.com') {
|
||||
$rd = mt_rand(0, 1);
|
||||
if ($rd == 0) {
|
||||
if ($rd === 0) {
|
||||
$email = $zemail->generateRandomGmail();
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@googlemail.com';
|
||||
@@ -239,11 +234,11 @@ class ZEmail extends Model
|
||||
{
|
||||
$zemail = new ZEmail;
|
||||
$uname = $zemail->getRandomGmailUser();
|
||||
$uname_len = strlen($uname);
|
||||
$uname_len = strlen((string) $uname);
|
||||
$len_power = $uname_len - 1;
|
||||
$combination = pow(2, $len_power);
|
||||
$rand_comb = mt_rand(1, $combination);
|
||||
$formatted = implode(' ', str_split($uname));
|
||||
$combination = 2 ** $len_power;
|
||||
mt_rand(1, $combination);
|
||||
$formatted = implode(' ', str_split((string) $uname));
|
||||
$uname_exp = explode(' ', $formatted);
|
||||
|
||||
$bin = intval('');
|
||||
@@ -255,7 +250,7 @@ class ZEmail extends Model
|
||||
$email = '';
|
||||
for ($i = 0; $i < $len_power; $i++) {
|
||||
$email .= $uname_exp[$i];
|
||||
if ($bin[$i]) {
|
||||
if ($bin[$i] !== '' && $bin[$i] !== '0') {
|
||||
$email .= '.';
|
||||
}
|
||||
}
|
||||
@@ -284,9 +279,9 @@ class ZEmail extends Model
|
||||
return $email;
|
||||
}
|
||||
|
||||
private static function storeEmail($email): void
|
||||
private static function storeEmail(string $email): void
|
||||
{
|
||||
Log::create([
|
||||
Log::query()->create([
|
||||
'ip' => request()->ip(),
|
||||
'email' => $email,
|
||||
]);
|
||||
@@ -314,8 +309,8 @@ class ZEmail extends Model
|
||||
|
||||
private function generateRandomUsername(): string
|
||||
{
|
||||
$start = json_decode(config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode(config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
$start = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_min ?? 0;
|
||||
$end = json_decode((string) config('app.settings.configuration_settings'))->random_username_length_max ?? 0;
|
||||
if ($start == 0 && $end == 0) {
|
||||
return $this->generatePronounceableWord();
|
||||
}
|
||||
@@ -325,34 +320,34 @@ class ZEmail extends Model
|
||||
|
||||
protected function generatedRandomBetweenLength($start, $end): string
|
||||
{
|
||||
$length = rand($start, $end);
|
||||
$length = random_int($start, $end);
|
||||
|
||||
return $this->generateRandomString($length);
|
||||
}
|
||||
|
||||
private function getRandomDomain()
|
||||
{
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$count = count($domains);
|
||||
|
||||
return $count > 0 ? $domains[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $domains[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function getRandomGmailUser()
|
||||
{
|
||||
$gmailusername = json_decode(config('app.settings.configuration_settings'))->gmailUsernames ?? [];
|
||||
$gmailusername = json_decode((string) config('app.settings.configuration_settings'))->gmailUsernames ?? [];
|
||||
|
||||
$count = count($gmailusername);
|
||||
|
||||
return $count > 0 ? $gmailusername[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $gmailusername[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function getRandomOutlookUser()
|
||||
{
|
||||
$outlook_username = json_decode(config('app.settings.configuration_settings'))->outlookUsernames ?? [];
|
||||
$outlook_username = json_decode((string) config('app.settings.configuration_settings'))->outlookUsernames ?? [];
|
||||
$count = count($outlook_username);
|
||||
|
||||
return $count > 0 ? $outlook_username[rand(1, $count) - 1] : '';
|
||||
return $count > 0 ? $outlook_username[random_int(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function generatePronounceableWord(): string
|
||||
@@ -362,21 +357,21 @@ class ZEmail extends Model
|
||||
$a = $c.$v; // both
|
||||
$random = '';
|
||||
for ($j = 0; $j < 2; $j++) {
|
||||
$random .= $c[rand(0, strlen($c) - 1)];
|
||||
$random .= $v[rand(0, strlen($v) - 1)];
|
||||
$random .= $a[rand(0, strlen($a) - 1)];
|
||||
$random .= $c[random_int(0, strlen($c) - 1)];
|
||||
$random .= $v[random_int(0, strlen($v) - 1)];
|
||||
$random .= $a[random_int(0, strlen($a) - 1)];
|
||||
}
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
private function generateRandomString($length = 10): string
|
||||
private function generateRandomString(int $length = 10): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
|
||||
Reference in New Issue
Block a user