'fetch', 'syncMailbox' => 'syncEmail']; public function mount(): void { $this->email = ZEmail::getEmail(); $this->initial = false; } public function syncEmail($email): void { $this->email = $email; $this->initial = false; } 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 = [ 'to' => ZEmail::getMessages($this->email, 'to', $this->deleted), 'cc' => [ 'data' => [], 'notifications' => [] ] ]; } else { $responses = [ 'to' => ZEmail::getMessages($this->email, 'to', $this->deleted), '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 && count($this->messages) == $count) { $this->overflow = true; } } else { $this->overflow = false; } foreach ($notifications as $notification) { $this->dispatch('showNewMailNotification', $notification); } ZEmail::incrementMessagesStats(count($notifications)); } catch (\Exception $e) { if (Auth::check() && Auth::user()->level == 9) { $this->error = $e->getMessage(); } else { $this->error = 'Not able to connect to Mail Server'; } } $this->dispatch('stopLoader'); $this->dispatch('loadDownload'); $this->initial = true; } public function delete($messageId) { if (config('app.beta_feature')) { Message::find($messageId)->delete(); } $this->deleted[] = $messageId; foreach ($this->messages as $key => $message) { if ($message['id'] == $messageId) { $directory = './tmp/attachments/' . $messageId; $this->rrmdir($directory); unset($this->messages[$key]); } } } public function render() { 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)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . "/" . $object)) $this->rrmdir($dir . DIRECTORY_SEPARATOR . $object); else unlink($dir . DIRECTORY_SEPARATOR . $object); } } rmdir($dir); } } }