diff --git a/app/Console/Commands/MarkTimeoutMail.php b/app/Console/Commands/MarkTimeoutMail.php
new file mode 100644
index 0000000..6256aa7
--- /dev/null
+++ b/app/Console/Commands/MarkTimeoutMail.php
@@ -0,0 +1,38 @@
+subSeconds(300)],
+ ['is_read', '=', 0],
+ ])->update([
+ 'is_read' => 1,
+ ]);
+ }
+}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index e6b9960..8457aa0 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -12,7 +12,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule): void
{
- // $schedule->command('inspire')->hourly();
+ $schedule->command('app:mark-timeout-mail')->minutely();
}
/**
@@ -20,7 +20,7 @@ protected function schedule(Schedule $schedule): void
*/
protected function commands(): void
{
- $this->load(__DIR__.'/Commands');
+ $this->load(__DIR__ . '/Commands');
require base_path('routes/console.php');
}
diff --git a/app/Http/Controllers/MailController.php b/app/Http/Controllers/MailController.php
index 359170e..9f7b6f3 100644
--- a/app/Http/Controllers/MailController.php
+++ b/app/Http/Controllers/MailController.php
@@ -2,13 +2,13 @@
namespace App\Http\Controllers;
+use App\Http\Controllers\Controller;
use App\Models\Mail;
-use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
-use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Str;
class MailController extends Controller
{
@@ -17,8 +17,8 @@ public function index(Request $request)
{
$domain_list = config('mail.domain_list');
$block_prefix = config('mail.block_prefix');
- $rand_prefix = Str::random(8);
- $key = Crypt::encryptString(json_encode(['id' => 0, 'time' => time()]));
+ $rand_prefix = strtolower(Str::random(8));
+ $key = Crypt::encryptString(json_encode(['time' => time()]));
return view('welcome', [
'domain_list' => $domain_list,
'block_prefix' => $block_prefix,
@@ -64,20 +64,26 @@ function ($attribute, $value, $fail) {
return abort(400);
}
- $where = [];
- $to_hash = hash('sha256', $email);
- $where[] = ['to_hash', '=', $to_hash];
+ $where = [
+ 'to_hash' => hash('sha256', $email),
+ 'is_read' => 0,
+ ];
+ // $to_hash = hash('sha256', $email);
+ // $where[] = ['to_hash', '=', $to_hash];
try {
$key = Crypt::decryptString($key);
$key = json_decode($key, true);
- if (!empty($key['id'])) {
- $where[] = ['id', '>', $key['id']];
- } elseif (time() - $key['time'] < 300) {
- $where[] = ['received_at', '>', Carbon::parse($key['time'])];
- } else {
- $where[] = ['received_at', '>', Carbon::now()->subSeconds(60)];
+ if (time() - $key['time'] > 300) {
+ throw new Exception("The token has expired.", 400);
}
+ // if (!empty($key['id'])) {
+ // $where[] = ['id', '>', $key['id']];
+ // } elseif (time() - $key['time'] < 300) {
+ // $where[] = ['received_at', '>', Carbon::parse($key['time'])];
+ // } else {
+ // $where[] = ['received_at', '>', Carbon::now()->subSeconds(60)];
+ // }
} catch (\Throwable $th) {
return abort(400, $th->getMessage());
}
@@ -94,10 +100,7 @@ function ($attribute, $value, $fail) {
->orderBy('received_at', 'asc')
->get();
- $key = ['id' => $key['id'], 'time' => time()];
- if ($new_email_list->count() > 0) {
- $key['id'] = $new_email_list->last()->key;
- }
+ $key = ['time' => time()];
foreach ($new_email_list as $value) {
$value->key = Crypt::encryptString($value->key);
@@ -142,6 +145,7 @@ public function put(Request $request)
$mail->from_addr = $from_addr;
$mail->from_protocol = $from_protocol;
$mail->received_at = Carbon::parse($received_at);
+ $mail->is_read = 0;
$mail->save();
return response()->json([
@@ -168,6 +172,9 @@ public function info(Request $request, $key)
return abort(404);
}
+ $mail_info->is_read = 1;
+ $mail_info->save();
+
$title = str_replace(["\n", "\r", "\t"], '', strip_tags($mail_info->title));
$body = preg_replace('/
-
+
@@ -209,7 +209,7 @@
function isValidDomain(domain) {
console.log(domain);
- var pattern = /^(?!:\/\/)([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,11}$/;
+ var pattern = /^(?!:\/\/)([a-z0-9-]+\.)*[a-z0-9-]+\.[a-z]{2,11}$/;
return pattern.test(domain);
}
@@ -308,6 +308,7 @@ function fetchMail() {
});
$('#inputText').on('change keyup', function () {
+ this.value = this.value.toLowerCase().replace(/[^a-z0-9]/g, '');
let textLength = $('#inputText').val().length;
if (textLength < 5 || textLength > 32) {
$('#inputText').addClass('is-invalid');
@@ -409,7 +410,6 @@ function fetchMail() {
$('#myModal').modal('show');
-
} catch (e) {
console.error('Error parsing API response or decoding base64:', e);
}
@@ -424,4 +424,4 @@ function fetchMail() {