Added Create Custom, Random, Gmail Generation
This commit is contained in:
54
app/Http/Controllers/AppController.php
Normal file
54
app/Http/Controllers/AppController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ZEmail;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
public function mailbox($email = null) {
|
||||
if ($email) {
|
||||
if (json_decode(config('app.settings.configuration_settings'))->enable_create_from_url) {
|
||||
ZEmail::createCustomEmailFull($email);
|
||||
}
|
||||
return redirect()->route('mailbox');
|
||||
}
|
||||
if (!ZEmail::getEmail()) {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
if (json_decode(config('app.settings.configuration_settings'))->disable_mailbox_slug) {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
return $this->app();
|
||||
}
|
||||
|
||||
public function app() {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
|
||||
private function getStringBetween($string, $start, $end) {
|
||||
$string = ' ' . $string;
|
||||
$ini = strpos($string, $start);
|
||||
if ($ini == 0) return '';
|
||||
$ini += strlen($start);
|
||||
$len = strpos($string, $end, $ini) - $ini;
|
||||
return substr($string, $ini, $len);
|
||||
}
|
||||
private function setHeaders($page) {
|
||||
$header = $page->header;
|
||||
foreach ($page->meta ? unserialize($page->meta) : [] as $meta) {
|
||||
if ($meta['name'] == 'canonical') {
|
||||
$header .= '<link rel="canonical" href="' . $meta['content'] . '" />';
|
||||
} else if (str_contains($meta['name'], 'og:')) {
|
||||
$header .= '<meta property="' . $meta['name'] . '" content="' . $meta['content'] . '" />';
|
||||
} else {
|
||||
$header .= '<meta name="' . $meta['name'] . '" content="' . $meta['content'] . '" />';
|
||||
}
|
||||
}
|
||||
$page->header = $header;
|
||||
return $page;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
app/Livewire/Email.php
Normal file
13
app/Livewire/Email.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Email extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.email');
|
||||
}
|
||||
}
|
||||
62
app/Livewire/EmailInbox.php
Normal file
62
app/Livewire/EmailInbox.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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
|
||||
]);
|
||||
}
|
||||
}
|
||||
134
app/Livewire/Frontend/Action.php
Normal file
134
app/Livewire/Frontend/Action.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\ZEmail;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
|
||||
class Action extends Component
|
||||
{
|
||||
public $username, $email, $emails, $domain, $domains, $action, $initial;
|
||||
|
||||
|
||||
public function mount() {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->validateDomainInEmail();
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if (!$this->username) {
|
||||
return $this->showAlert('error', __('Please enter Username'));
|
||||
}
|
||||
$this->checkDomainInUsername();
|
||||
if (strlen($this->username) < json_decode(config('app.settings.configuration_settings'))->custom_username_length_min || strlen($this->username) > json_decode(config('app.settings.configuration_settings'))->custom_username_length_max) {
|
||||
return $this->showAlert('error', __('Username length cannot be less than') . ' ' . json_decode(config('app.settings.configuration_settings'))->custom_username_length_min . ' ' . __('and greater than') . ' ' . json_decode(config('app.settings.configuration_settings'))->custom_username_length_max);
|
||||
}
|
||||
if (!$this->domain) {
|
||||
return $this->showAlert('error', __('Please Select a Domain'));
|
||||
}
|
||||
if (in_array($this->username, json_decode(config('app.settings.configuration_settings'))->forbidden_ids)) {
|
||||
return $this->showAlert('error', __('Username not allowed'));
|
||||
}
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of MAX ') . json_decode(config('app.settings.configuration_settings'))->email_limit . __(' temp mail'));
|
||||
}
|
||||
if (!$this->checkUsedEmail()) {
|
||||
return $this->showAlert('error', __('Sorry! That email is already been used by someone else. Please try a different email address.'));
|
||||
}
|
||||
|
||||
$this->email = ZEmail::createCustomEmail($this->username, $this->domain);
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
|
||||
}
|
||||
public function random() {
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . json_decode(config('app.settings.configuration_settings'))->email_limit . __(' temp mail addresses.'));
|
||||
}
|
||||
$this->email = ZEmail::generateRandomEmail();
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
|
||||
//$this->redirect(route('mailbox'));
|
||||
}
|
||||
|
||||
public function gmail() {
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . json_decode(config('app.settings.configuration_settings'))->email_limit . __(' temp mail addresses.'));
|
||||
}
|
||||
$this->email = ZEmail::generateRandomGmail();
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
}
|
||||
|
||||
public function deleteEmail() {
|
||||
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');
|
||||
// }
|
||||
$this->email = ZEmail::getEmail(true);
|
||||
$this->emails = ZEmail::getEmails();
|
||||
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
}
|
||||
|
||||
private function showAlert($type, $message): void
|
||||
{
|
||||
$this->dispatch('showAlert', ['type' => $type, 'message' => $message]);
|
||||
}
|
||||
|
||||
private function checkEmailLimit() {
|
||||
$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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkUsedEmail() {
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkDomainInUsername() {
|
||||
$parts = explode('@', $this->username);
|
||||
if (isset($parts[1])) {
|
||||
if (in_array($parts[1], $this->domains)) {
|
||||
$this->domain = $parts[1];
|
||||
}
|
||||
$this->username = $parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
private function validateDomainInEmail(): void
|
||||
{
|
||||
$data = explode('@', $this->email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
if (!in_array($domain, $domains)) {
|
||||
$key = array_search($this->email, $this->emails);
|
||||
ZEmail::removeEmail($this->email);
|
||||
if ($key == 0 && count($this->emails) == 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
|
||||
redirect()->route('home');
|
||||
} else {
|
||||
redirect()->route('mailbox');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function render() {
|
||||
return view('livewire.frontend.action');
|
||||
}
|
||||
}
|
||||
222
app/Livewire/Frontend/ActionOld.php
Normal file
222
app/Livewire/Frontend/ActionOld.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\ZEmail;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Component;
|
||||
|
||||
class ActionOld extends Component
|
||||
{
|
||||
public $in_app = false;
|
||||
public $user, $domain, $domains, $email, $emails, $captcha;
|
||||
|
||||
protected $listeners = ['syncEmail', 'checkReCaptcha3'];
|
||||
|
||||
public function mount() {
|
||||
$this->domains = config('app.settings.domains');
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->validateDomainInEmail();
|
||||
}
|
||||
|
||||
public function refreshMessages()
|
||||
{
|
||||
$this->emit('fetchMessages');
|
||||
}
|
||||
|
||||
public function loadMsg($email) {
|
||||
$this->email = $email;
|
||||
if (count($this->emails) == 0) {
|
||||
$this->emails = [$email];
|
||||
}
|
||||
}
|
||||
|
||||
public function syncEmail($email) {
|
||||
$this->email = $email;
|
||||
if (count($this->emails) == 0) {
|
||||
$this->emails = [$email];
|
||||
}
|
||||
}
|
||||
|
||||
public function setDomain($domain) {
|
||||
$this->domain = $domain;
|
||||
}
|
||||
|
||||
public function checkReCaptcha3($token, $action) {
|
||||
$response = Http::post('https://www.google.com/recaptcha/api/siteverify?secret=' . config('app.settings.recaptcha3.secret_key') . '&response=' . $token);
|
||||
$data = $response->json();
|
||||
if ($data['success']) {
|
||||
$captcha = $data['score'];
|
||||
if ($captcha > 0.5) {
|
||||
if ($action == 'create') {
|
||||
$this->create();
|
||||
} else {
|
||||
$this->random();
|
||||
}
|
||||
} else {
|
||||
return $this->showAlert('error', __('Captcha Failed! Please try again'));
|
||||
}
|
||||
} else {
|
||||
return $this->showAlert('error', __('Captcha Failed! Error: ') . json_encode($data['error-codes']));
|
||||
}
|
||||
}
|
||||
public function create() {
|
||||
if (!$this->user) {
|
||||
return $this->showAlert('error', __('Please enter Username'));
|
||||
}
|
||||
$this->checkDomainInUsername();
|
||||
if (strlen($this->user) < config('app.settings.custom.min') || strlen($this->user) > config('app.settings.custom.max')) {
|
||||
return $this->showAlert('error', __('Username length cannot be less than') . ' ' . config('app.settings.custom.min') . ' ' . __('and greater than') . ' ' . config('app.settings.custom.max'));
|
||||
}
|
||||
if (!$this->domain) {
|
||||
return $this->showAlert('error', __('Please Select a Domain'));
|
||||
}
|
||||
if (in_array($this->user, config('app.settings.forbidden_ids'))) {
|
||||
return $this->showAlert('error', __('Username not allowed'));
|
||||
}
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of MAX ') . config('app.settings.email_limit', 5) . __(' temp mail'));
|
||||
}
|
||||
if (!$this->checkUsedEmail()) {
|
||||
return $this->showAlert('error', __('Sorry! That email is already been used by someone else. Please try a different email address.'));
|
||||
}
|
||||
if (!$this->validateCaptcha()) {
|
||||
return $this->showAlert('error', __('Invalid Captcha. Please try again'));
|
||||
}
|
||||
$this->email = ZEmail::createCustomEmail($this->user, $this->domain);
|
||||
$this->redirect(route('mailbox'));
|
||||
}
|
||||
|
||||
public function random() {
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . config('app.settings.email_limit', 5) . __(' temp mail addresses.'));
|
||||
}
|
||||
if (!$this->validateCaptcha()) {
|
||||
return $this->showAlert('error', __('Invalid Captcha. Please try again'));
|
||||
}
|
||||
$this->email = ZEmail::generateRandomEmail();
|
||||
$this->redirect(route('mailbox'));
|
||||
}
|
||||
|
||||
public function tempgmail() {
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . config('app.settings.email_limit', 5) . __(' temp mail addresses.'));
|
||||
}
|
||||
if (!$this->validateCaptcha()) {
|
||||
return $this->showAlert('error', __('Invalid Captcha. Please try again'));
|
||||
}
|
||||
$this->email = ZEmail::generateRandomGmail();
|
||||
$this->redirect(route('mailbox'));
|
||||
}
|
||||
|
||||
public function deleteEmail() {
|
||||
ZEmail::removeEmail($this->email);
|
||||
if (count($this->emails) == 1 && config('app.settings.after_last_email_delete') == 'redirect_to_homepage') {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
$this->email = ZEmail::getEmail(true);
|
||||
$this->emails = ZEmail::getEmails();
|
||||
return redirect()->route('mailbox');
|
||||
}
|
||||
|
||||
public function render() {
|
||||
if (count($this->emails) >= intval(config('app.settings.email_limit', 5))) {
|
||||
for ($i = 0; $i < (count($this->emails) - intval(config('app.settings.email_limit', 5))); $i++) {
|
||||
ZEmail::removeEmail($this->emails[$i]);
|
||||
}
|
||||
$this->emails = ZEmail::getEmails();
|
||||
ZEmail::setEmail($this->email);
|
||||
}
|
||||
return view('livewire.frontend.action');
|
||||
}
|
||||
|
||||
/**
|
||||
* Private Functions
|
||||
*/
|
||||
|
||||
private function showAlert($type, $message) {
|
||||
$this->dispatchBrowserEvent('showAlert', ['type' => $type, 'message' => $message]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't allow used email
|
||||
*/
|
||||
private function checkUsedEmail() {
|
||||
if (config('app.settings.disable_used_email', false)) {
|
||||
$check = Log::where('email', $this->user . '@' . $this->domain)->where('ip', '<>', request()->ip())->count();
|
||||
if ($check > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Captcha
|
||||
*/
|
||||
private function validateCaptcha() {
|
||||
if (config('app.settings.captcha') == 'hcaptcha') {
|
||||
$response = Http::asForm()->post('https://hcaptcha.com/siteverify', [
|
||||
'response' => $this->captcha,
|
||||
'secret' => config('app.settings.hcaptcha.secret_key')
|
||||
])->object();
|
||||
return $response->success;
|
||||
} else if (config('app.settings.captcha') == 'recaptcha2') {
|
||||
$response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
|
||||
'response' => $this->captcha,
|
||||
'secret' => config('app.settings.recaptcha2.secret_key')
|
||||
])->object();
|
||||
return $response->success;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user is crossing email limit
|
||||
*/
|
||||
private function checkEmailLimit() {
|
||||
$logs = Log::select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Carbon::now()->subDay())->groupBy('email')->groupBy('ip')->get();
|
||||
if (count($logs) >= config('app.settings.email_limit', 5)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Username already consist of Domain
|
||||
*/
|
||||
private function checkDomainInUsername() {
|
||||
$parts = explode('@', $this->user);
|
||||
if (isset($parts[1])) {
|
||||
if (in_array($parts[1], $this->domains)) {
|
||||
$this->domain = $parts[1];
|
||||
}
|
||||
$this->user = $parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if Domain in Email Exist
|
||||
*/
|
||||
private function validateDomainInEmail() {
|
||||
$data = explode('@', $this->email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
$domains = config('app.settings.domains');
|
||||
if (!in_array($domain, $domains)) {
|
||||
$key = array_search($this->email, $this->emails);
|
||||
TMail::removeEmail($this->email);
|
||||
if ($key == 0 && count($this->emails) == 1 && config('app.settings.after_last_email_delete') == 'redirect_to_homepage') {
|
||||
return redirect()->route('home');
|
||||
} else {
|
||||
return redirect()->route('mailbox');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
109
app/Livewire/Frontend/App.php
Normal file
109
app/Livewire/Frontend/App.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\Message;
|
||||
use App\Models\ZEmail;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
|
||||
class App extends Component
|
||||
{
|
||||
public $messages = [];
|
||||
public $deleted = [];
|
||||
public $error = '';
|
||||
public $email;
|
||||
public $initial;
|
||||
public $overflow = false;
|
||||
|
||||
protected $listeners = ['fetchMessages' => 'fetch', 'syncEmail'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->email = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
}
|
||||
|
||||
public function syncEmail($email) {
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function fetch() {
|
||||
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)
|
||||
];
|
||||
}
|
||||
$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) {
|
||||
$this->overflow = true;
|
||||
}
|
||||
} else {
|
||||
$this->overflow = false;
|
||||
}
|
||||
foreach ($notifications as $notification) {
|
||||
$this->dispatchBrowserEvent('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->dispatchBrowserEvent('stopLoader');
|
||||
$this->dispatchBrowserEvent('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.app');
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
65
app/Livewire/Frontend/Email.php
Normal file
65
app/Livewire/Frontend/Email.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\ZEmail;
|
||||
use Livewire\Component;
|
||||
|
||||
class Email extends Component
|
||||
{
|
||||
public $list = false;
|
||||
public $type, $email, $emails, $initial;
|
||||
|
||||
protected $listeners = ['updateEmail' => 'syncEmail', 'getEmail' => 'generateEmail'];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
}
|
||||
|
||||
private function checkMultipleEmails(): void
|
||||
{
|
||||
if (count($this->emails) == 0) {
|
||||
$this->emails = [$this->email];
|
||||
}
|
||||
if (count($this->emails) > 1) {
|
||||
$this->list = true;
|
||||
} else {
|
||||
$this->list = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function switchEmail($email): void
|
||||
{
|
||||
ZEmail::setEmail($email);
|
||||
$this->email = $email;
|
||||
$this->dispatch('updateEmail');
|
||||
}
|
||||
|
||||
public function syncEmail(): void
|
||||
{
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
if (count($this->emails) == 0) {
|
||||
$this->dispatch('getEmail');
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
}
|
||||
|
||||
public function generateEmail(): void
|
||||
{
|
||||
if ($this->email == null) {
|
||||
ZEmail::generateRandomEmail();
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
$this->dispatch('updateEmail');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.email')->with(['email' => $this->email, 'emails' => $this->emails, 'initial' => $this->initial, 'type' => $this->type, 'list' => $this->list]);
|
||||
}
|
||||
}
|
||||
13
app/Livewire/Home.php
Normal file
13
app/Livewire/Home.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Home extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.home');
|
||||
}
|
||||
}
|
||||
13
app/Livewire/Inbox.php
Normal file
13
app/Livewire/Inbox.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Inbox extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.inbox');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Ddeboer\Imap\Search\Date\Since;
|
||||
use Ddeboer\Imap\Search\Email\Cc;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\SearchExpression;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -62,7 +67,7 @@ class Message extends Model
|
||||
$obj['sender_email'] = $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(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;
|
||||
@@ -105,4 +110,239 @@ class Message extends Model
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function fetchMessages($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();
|
||||
|
||||
$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'))));
|
||||
$messages = $mailbox->getMessages($search, \SORTDATE, true);
|
||||
$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();
|
||||
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;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Ddeboer\Imap\Search\Date\Since;
|
||||
use Ddeboer\Imap\Search\Email\Cc;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\SearchExpression;
|
||||
@@ -38,112 +39,7 @@ class ZEmail extends Model
|
||||
if (config('app.beta_feature')) {
|
||||
return Message::getMessages($email);
|
||||
}
|
||||
$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));
|
||||
}
|
||||
$messages = $mailbox->getMessages($search, \SORTDATE, true);
|
||||
$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();
|
||||
return $response;
|
||||
return Message::fetchMessages($email, $type, $deleted);
|
||||
}
|
||||
|
||||
public static function deleteMessage($id): void
|
||||
|
||||
Reference in New Issue
Block a user