Added Fetch Email on page load

This commit is contained in:
Gitea
2025-04-26 00:22:03 +05:30
parent 9aa1b3ab8e
commit 89f6410578
16 changed files with 136 additions and 267 deletions

View File

@@ -1,62 +0,0 @@
<?php
namespace App\Livewire;
use App\Models\ZEmail;
use Livewire\Component;
use Livewire\WithPagination;
class EmailInbox extends Component
{
use WithPagination;
public $currentEmail;
public $messages = [];
public $selectedMessage = null;
public $searchTerm = '';
public $refreshInterval = 30; // seconds
public function mount()
{
$this->currentEmail = ZEmail::getEmail();
$this->loadMessages();
}
public function loadMessages()
{
if ($this->currentEmail) {
$this->messages = ZEmail::getMessages($this->currentEmail);
}
}
public function selectMessage($messageId)
{
$this->selectedMessage = $messageId;
}
public function deleteMessage($messageId)
{
ZEmail::deleteMessage($messageId);
$this->loadMessages();
$this->selectedMessage = null;
}
public function generateNewEmail()
{
$this->currentEmail = ZEmail::generateRandomEmail();
$this->loadMessages();
}
public function getPollingInterval()
{
return $this->refreshInterval * 1000; // Convert to milliseconds
}
public function render()
{
return view('livewire.email-inbox', [
'messages' => $this->messages,
'currentEmail' => $this->currentEmail
]);
}
}

View File

@@ -65,7 +65,8 @@ class Action extends Component
$this->dispatch('closeModal');
}
public function deleteEmail() {
public function deleteEmail(): void
{
ZEmail::removeEmail($this->email);
// if (count($this->emails) <= 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
// return redirect()->route('home');
@@ -82,7 +83,8 @@ class Action extends Component
$this->dispatch('showAlert', ['type' => $type, 'message' => $message]);
}
private function checkEmailLimit() {
private function checkEmailLimit(): bool
{
$logs = Log::select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Carbon::now()->subDay())->groupBy('email')->groupBy('ip')->get();
if (count($logs) >= json_decode(config('app.settings.configuration_settings'))->email_limit) {
return false;
@@ -90,7 +92,8 @@ class Action extends Component
return true;
}
private function checkUsedEmail() {
private function checkUsedEmail(): bool
{
if (json_decode(config('app.settings.configuration_settings'))->disable_used_email) {
$check = Log::where('email', $this->user . '@' . $this->domain)->where('ip', '<>', request()->ip())->count();
if ($check > 0) {

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Livewire\Frontend\Components;
use Livewire\Component;
class Mail extends Component
{
public $message;
public function render()
{
return view('livewire.frontend.components.mail')->with(['message' => $this->message]);
}
}

View File

@@ -47,6 +47,8 @@ class Email extends Component
$this->dispatch('getEmail');
}
$this->checkMultipleEmails();
$this->dispatch('syncMailbox', $this->email);
$this->dispatch('fetchMessages');
}
public function generateEmail(): void

View File

@@ -7,30 +7,34 @@ use App\Models\ZEmail;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class App extends Component
class Mailbox extends Component
{
public $messages = [];
public $deleted = [];
public $error = '';
public $email;
public $initial;
public $initial = false;
public $type;
public $overflow = false;
protected $listeners = ['fetchMessages' => 'fetch', 'syncEmail'];
protected $listeners = ['fetchMessages' => 'fetch', 'syncMailbox' => 'syncEmail'];
public function mount()
public function mount(): void
{
$this->email = ZEmail::getEmails();
$this->email = ZEmail::getEmail();
$this->initial = false;
}
public function syncEmail($email): void
{
$this->email = $email;
$this->initial = false;
}
public function syncEmail($email) {
$this->email = $email;
}
public function fetch() {
public function fetch(): void
{
try {
$count = count($this->messages);
$responses = [];
if (config('app.beta_feature') || !json_decode(config('app.settings.imap_settings'))->cc_check) {
$responses = [
@@ -46,18 +50,36 @@ class App extends Component
'cc' => ZEmail::getMessages($this->email, 'cc', $this->deleted)
];
}
// $responses = [
// 'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
// ];
// $imapSettings = json_decode(config('app.settings.imap_settings'));
// $betaFeature = config('app.beta_feature');
//
// if ($betaFeature || empty($imapSettings?->cc_check)) {
// $responses['cc'] = [
// 'data' => [],
// 'notifications' => []
// ];
// } else {
// $responses['cc'] = ZEmail::getMessages($this->email, 'cc', $this->deleted);
// }
$this->deleted = [];
$this->messages = array_merge($responses['to']['data'], $responses['cc']['data']);
$notifications = array_merge($responses['to']['notifications'], $responses['cc']['notifications']);
if (count($notifications)) {
if ($this->overflow == false && count($this->messages) == $count) {
if (!$this->overflow && count($this->messages) == $count) {
$this->overflow = true;
}
} else {
$this->overflow = false;
}
foreach ($notifications as $notification) {
$this->dispatchBrowserEvent('showNewMailNotification', $notification);
$this->dispatch('showNewMailNotification', $notification);
}
ZEmail::incrementMessagesStats(count($notifications));
} catch (\Exception $e) {
@@ -67,8 +89,8 @@ class App extends Component
$this->error = 'Not able to connect to Mail Server';
}
}
$this->dispatchBrowserEvent('stopLoader');
$this->dispatchBrowserEvent('loadDownload');
$this->dispatch('stopLoader');
$this->dispatch('loadDownload');
$this->initial = true;
}
@@ -88,8 +110,9 @@ class App extends Component
public function render()
{
return view('livewire.frontend.app');
return view('livewire.frontend.mailbox')->with(['messages' => $this->messages, 'email' => $this->email, 'initial' => $this->initial, 'error' => $this->error]);
}
private function rrmdir($dir): void
{
if (is_dir($dir)) {
@@ -105,5 +128,4 @@ class App extends Component
rmdir($dir);
}
}
}