added public mailbox support
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,3 +22,5 @@ yarn-error.log
|
||||
/.vscode
|
||||
/.zed
|
||||
/stripe.exe
|
||||
/public/tmp/attachments/
|
||||
/public/tmp/premium/
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Models\Premium;
|
||||
use App\Models\ZEmail;
|
||||
use Illuminate\Http\Request;
|
||||
use Session;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
@@ -50,7 +51,11 @@ class AppController extends Controller
|
||||
}
|
||||
|
||||
public function switchP($email) {
|
||||
if (Session::get('isInboxTypePremium')) {
|
||||
Premium::setEmailP($email);
|
||||
} else {
|
||||
ZEmail::setEmail($email);
|
||||
}
|
||||
if (json_decode(config('app.settings.configuration_settings'))->disable_mailbox_slug) {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
@@ -59,8 +64,13 @@ class AppController extends Controller
|
||||
|
||||
public function deleteP($email = null) {
|
||||
if ($email) {
|
||||
if (Session::get('isInboxTypePremium')) {
|
||||
$emails = Premium::getEmails();
|
||||
Premium::removeEmail($email);
|
||||
} else {
|
||||
$emails = ZEmail::getEmails();
|
||||
ZEmail::removeEmail($email);
|
||||
}
|
||||
return redirect()->route('dashboard.premium');
|
||||
} else {
|
||||
return redirect()->route('dashboard');
|
||||
|
||||
@@ -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->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
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
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.'));
|
||||
}
|
||||
|
||||
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.'));
|
||||
}
|
||||
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.'));
|
||||
}
|
||||
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];
|
||||
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);
|
||||
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,6 +286,7 @@ class Inbox extends Component
|
||||
$this->messages = [];
|
||||
}
|
||||
$responses = [];
|
||||
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),
|
||||
@@ -257,6 +301,22 @@ class Inbox extends Component
|
||||
'cc' => Premium::getMessages($this->email, 'cc', $this->deleted)
|
||||
];
|
||||
}
|
||||
} else {
|
||||
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']);
|
||||
@@ -300,7 +360,11 @@ class Inbox extends Component
|
||||
$this->deleted[] = $messageId;
|
||||
foreach ($this->messages as $key => $message) {
|
||||
if ($message['id'] == $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')) {
|
||||
|
||||
@@ -178,24 +178,24 @@ class Premium extends Model
|
||||
$connection->expunge();
|
||||
}
|
||||
public static function getEmail($generate = false) {
|
||||
if (Cookie::has('email')) {
|
||||
return Cookie::get('email');
|
||||
if (Cookie::has('p_email')) {
|
||||
return Cookie::get('p_email');
|
||||
} else {
|
||||
return $generate ? self::generateRandomEmail() : null;
|
||||
}
|
||||
}
|
||||
public static function getEmails() {
|
||||
if (Cookie::has('emails')) {
|
||||
return unserialize(Cookie::get('emails'));
|
||||
if (Cookie::has('p_emails')) {
|
||||
return unserialize(Cookie::get('p_emails'));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
public static function setEmail($email): void
|
||||
{
|
||||
$emails = unserialize(Cookie::get('emails'));
|
||||
$emails = unserialize(Cookie::get('p_emails'));
|
||||
if (is_array($emails) && in_array($email, $emails)) {
|
||||
Cookie::queue('email', $email, 43800);
|
||||
Cookie::queue('p_email', $email, 43800);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ class Premium extends Model
|
||||
$usageLogs = UsageLog::where(['user_id' => auth()->user()->id])->first();
|
||||
$emails = $usageLogs->emails_created_history;
|
||||
if (is_array($emails) && in_array($email, $emails)) {
|
||||
Cookie::queue('email', $email, 43800);
|
||||
Cookie::queue('p_email', $email, 43800);
|
||||
}
|
||||
}
|
||||
public static function removeEmail($email): void
|
||||
@@ -216,10 +216,10 @@ class Premium extends Model
|
||||
}
|
||||
if (count($emails) > 0) {
|
||||
self::setEmail($emails[0]);
|
||||
Cookie::queue('emails', serialize($emails), 43800);
|
||||
Cookie::queue('p_emails', serialize($emails), 43800);
|
||||
} else {
|
||||
Cookie::queue('email', '', -1);
|
||||
Cookie::queue('emails', serialize([]), -1);
|
||||
Cookie::queue('p_email', '', -1);
|
||||
Cookie::queue('p_emails', serialize([]), -1);
|
||||
}
|
||||
}
|
||||
public static function createCustomEmailFull($email): string
|
||||
@@ -368,12 +368,12 @@ class Premium extends Model
|
||||
|
||||
self::storeUsageLog($email);
|
||||
|
||||
Cookie::queue('email', $email, 43800);
|
||||
$emails = Cookie::has('emails') ? unserialize(Cookie::get('emails')) : [];
|
||||
Cookie::queue('p_email', $email, 43800);
|
||||
$emails = Cookie::has('p_emails') ? unserialize(Cookie::get('p_emails')) : [];
|
||||
if (!in_array($email, $emails)) {
|
||||
self::incrementEmailStats();
|
||||
$emails[] = $email;
|
||||
Cookie::queue('emails', serialize($emails), 43800);
|
||||
Cookie::queue('p_emails', serialize($emails), 43800);
|
||||
}
|
||||
}
|
||||
public static function incrementEmailStats($count = 1): void
|
||||
|
||||
@@ -63,7 +63,7 @@ class PremiumEmail extends Model
|
||||
'body_html' => $initialData['content'],
|
||||
'is_seen' => true,
|
||||
'is_flagged' => false,
|
||||
'size' => $initialData['size'],
|
||||
'size' => $initialData['size'] ?? 0,
|
||||
'mailbox' => 'INBOX',
|
||||
'raw_headers' => null,
|
||||
'raw_body' => null,
|
||||
|
||||
@@ -1,8 +1,33 @@
|
||||
<span>
|
||||
<div class="flex-1 overflow-hidden rounded-xl border border-neutral-200 dark:border-neutral-700 dark:bg-white/[0.03] sm:px-8 sm:py-8 lg:p-12">
|
||||
<div class="text-center mb-6">
|
||||
<div class="flex items-center justify-center gap-3 sm:gap-4">
|
||||
{{-- Public Label --}}
|
||||
<span class="text-xs sm:text-sm font-medium @if($premium === false) text-gray-800 dark:text-gray-100 font-semibold @else text-gray-400 dark:text-gray-500 @endif ">
|
||||
Public
|
||||
</span>
|
||||
|
||||
{{-- Toggle Switch --}}
|
||||
<label class="relative inline-flex items-center cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
wire:click="toggleMode"
|
||||
class="sr-only peer"
|
||||
@checked($premium)
|
||||
>
|
||||
<div class="w-8 h-4 bg-gray-300 dark:bg-gray-600 rounded-full peer-checked:bg-[#F14743] dark:peer-checked:bg-[#F14743] transition-colors duration-300"></div>
|
||||
<div class="absolute left-0.5 top-0.5 w-3 h-3 bg-white border border-gray-300 dark:border-gray-700 rounded-full transition-transform duration-300 peer-checked:translate-x-4"></div>
|
||||
</label>
|
||||
|
||||
{{-- Premium Label --}}
|
||||
<span class="text-xs sm:text-sm font-medium @if($premium === true) text-[#F14743] font-semibold @else text-gray-400 dark:text-gray-500 @endif">
|
||||
Premium
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-xl border dark:border-white/[0.1] border-black/[0.3] p-6 shadow-xs ring-white/[0.5] lg:w-1/2 mx-auto">
|
||||
<div class="text-center">
|
||||
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-400">Generate Premium Email</h2>
|
||||
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-400">Generate {{ $premium ? 'Premium' : 'Public' }} Email</h2>
|
||||
<div class="space-y-6">
|
||||
<div class="my-6">
|
||||
<div class="w-auto relative block group/input cursor-pointer" x-on:click="$dispatch('copyEmail')">
|
||||
|
||||
Reference in New Issue
Block a user