added public mailbox support
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Log;
|
||||
use App\Models\Premium;
|
||||
use App\Models\PremiumEmail;
|
||||
use App\Models\UsageLog;
|
||||
use App\Models\ZEmail;
|
||||
use Artisan;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -31,6 +32,8 @@ class Inbox extends Component
|
||||
public $emailsHistory;
|
||||
public $username, $domain, $domains, $action;
|
||||
public $email_limit = 20;
|
||||
public bool $premium = true;
|
||||
|
||||
private $isSubscribed;
|
||||
|
||||
protected $listeners = ['updateEmail' => 'syncEmail', 'getEmail' => 'generateEmail', 'fetchMessages' => 'fetch', 'setMessageId' => 'setMessageId'];
|
||||
@@ -38,12 +41,24 @@ class Inbox extends Component
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$this->email = Premium::getEmail();
|
||||
$this->emails = Premium::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
$this->premium = Session::get('isInboxTypePremium', true);
|
||||
|
||||
if ($this->premium) {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$this->email = Premium::getEmail();
|
||||
$this->emails = Premium::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
} else {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
}
|
||||
|
||||
$this->emailsHistory = array_reverse(PremiumEmail::parseEmail(\auth()->user()->id)['data']) ?? [];
|
||||
|
||||
$subscriptionCheck = auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id']);
|
||||
@@ -67,8 +82,13 @@ class Inbox extends Component
|
||||
}
|
||||
}
|
||||
|
||||
$mailboxHistory = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$this->mailboxHistory = $mailboxHistory->emails_created_history ?? [];
|
||||
if ($this->premium) {
|
||||
$mailboxHistory = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$this->mailboxHistory = $mailboxHistory->emails_created_history ?? [];
|
||||
} else {
|
||||
$this->mailboxHistory = ZEmail::getEmails() ?? [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function checkMultipleEmails(): void
|
||||
@@ -90,7 +110,11 @@ class Inbox extends Component
|
||||
$data = explode('@', $email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
if ($this->premium) {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
} else {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
}
|
||||
if (!in_array($domain, $domains)) {
|
||||
return $this->showAlert('error', __('This mailbox can not be recovered.'));
|
||||
}
|
||||
@@ -145,8 +169,11 @@ class Inbox extends Component
|
||||
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 = Premium::createCustomEmail($this->username, $this->domain);
|
||||
if ($this->premium) {
|
||||
$this->email = Premium::createCustomEmail($this->username, $this->domain);
|
||||
} else {
|
||||
$this->email = ZEmail::createCustomEmail($this->username, $this->domain);
|
||||
}
|
||||
return redirect()->route('dashboard.premium');
|
||||
|
||||
}
|
||||
@@ -155,14 +182,22 @@ class Inbox extends Component
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . $this->email_limit . __(' temp mail addresses.'));
|
||||
}
|
||||
$this->email = Premium::generateRandomEmail();
|
||||
if ($this->premium) {
|
||||
$this->email = Premium::generateRandomEmail();
|
||||
} else {
|
||||
$this->email = ZEmail::generateRandomEmail();
|
||||
}
|
||||
return redirect()->route('dashboard.premium');
|
||||
}
|
||||
public function gmail() {
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . $this->email_limit . __(' temp mail addresses.'));
|
||||
}
|
||||
$this->email = Premium::generateRandomGmail();
|
||||
if ($this->premium) {
|
||||
$this->email = Premium::generateRandomGmail();
|
||||
} else {
|
||||
$this->email = ZEmail::generateRandomGmail();
|
||||
}
|
||||
return redirect()->route('dashboard.premium');
|
||||
}
|
||||
|
||||
@@ -215,10 +250,18 @@ class Inbox extends Component
|
||||
$data = explode('@', $this->email);
|
||||
if (isset($data[1])) {
|
||||
$domain = $data[1];
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
if ($this->premium) {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
} else {
|
||||
$domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
}
|
||||
if (!in_array($domain, $domains)) {
|
||||
$key = array_search($this->email, $this->emails);
|
||||
Premium::removeEmail($this->email);
|
||||
if ($this->premium) {
|
||||
Premium::removeEmail($this->email);
|
||||
} else {
|
||||
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('dashboard.premium');
|
||||
} else {
|
||||
@@ -243,19 +286,36 @@ class Inbox extends Component
|
||||
$this->messages = [];
|
||||
}
|
||||
$responses = [];
|
||||
if (config('app.beta_feature') || !json_decode(config('app.settings.imap_settings'))->premium_cc_check) {
|
||||
$responses = [
|
||||
'to' => Premium::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => [
|
||||
'data' => [],
|
||||
'notifications' => []
|
||||
]
|
||||
];
|
||||
if ($this->premium) {
|
||||
if (config('app.beta_feature') || !json_decode(config('app.settings.imap_settings'))->premium_cc_check) {
|
||||
$responses = [
|
||||
'to' => Premium::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => [
|
||||
'data' => [],
|
||||
'notifications' => []
|
||||
]
|
||||
];
|
||||
} else {
|
||||
$responses = [
|
||||
'to' => Premium::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => Premium::getMessages($this->email, 'cc', $this->deleted)
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$responses = [
|
||||
'to' => Premium::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => Premium::getMessages($this->email, 'cc', $this->deleted)
|
||||
];
|
||||
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 = [];
|
||||
@@ -300,7 +360,11 @@ class Inbox extends Component
|
||||
$this->deleted[] = $messageId;
|
||||
foreach ($this->messages as $key => $message) {
|
||||
if ($message['id'] == $messageId) {
|
||||
$directory = public_path('tmp/premium/attachments/') . $messageId;
|
||||
if ($this->premium) {
|
||||
$directory = public_path('tmp/premium/attachments/') . $messageId;
|
||||
} else {
|
||||
$directory = public_path('tmp/attachments/') . $messageId;
|
||||
}
|
||||
$this->rrmdir($directory);
|
||||
unset($this->messages[$key]);
|
||||
}
|
||||
@@ -314,6 +378,33 @@ class Inbox extends Component
|
||||
|
||||
}
|
||||
|
||||
public function toggleMode()
|
||||
{
|
||||
$this->premium = !$this->premium;
|
||||
Session::put('isInboxTypePremium', $this->premium);
|
||||
if ($this->premium) {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? [];
|
||||
$this->email = Premium::getEmail();
|
||||
$this->emails = Premium::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
$mailboxHistory = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$this->mailboxHistory = $mailboxHistory->emails_created_history ?? [];
|
||||
$this->messages = [];
|
||||
|
||||
} else {
|
||||
$this->domains = json_decode(config('app.settings.configuration_settings'))->domains ?? [];
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
$this->validateDomainInEmail();
|
||||
$this->mailboxHistory = array_reverse(ZEmail::getEmails()) ?? [];
|
||||
$this->messages = [];
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (Session::get('isSubscribed')) {
|
||||
|
||||
Reference in New Issue
Block a user