diff --git a/assets/src/js/functions/hooks.js b/assets/src/js/functions/hooks.js index 23fa891b3..23b54cd7e 100644 --- a/assets/src/js/functions/hooks.js +++ b/assets/src/js/functions/hooks.js @@ -88,14 +88,14 @@ function executeHook(hook, token) { var timeout; if (result.execute) { - timeout = 1; + startHook(hook); } else { timeout = 30; - } - setTimeout(function () { - startHook(hook); - }, timeout * 1000); + setTimeout(function () { + startHook(hook); + }, timeout * 1000); + } }, }); } diff --git a/modules/emails/src/EmailHook.php b/modules/emails/src/EmailHook.php index e4697b188..8303a4414 100644 --- a/modules/emails/src/EmailHook.php +++ b/modules/emails/src/EmailHook.php @@ -2,6 +2,7 @@ namespace Modules\Emails; +use Carbon\Carbon; use Hooks\Manager; use Notifications\EmailNotification; @@ -29,20 +30,32 @@ class EmailHook extends Manager public function execute() { - $accounts = Account::all(); $diff = date('Y-m-d', strtotime('-4 hours')); + $failed = function ($query) use ($diff) { + $query->whereDate('failed_at', '<', $diff) + ->orWhereNull('failed_at'); + }; + $accounts = Account::all(); $list = []; foreach ($accounts as $account) { - $mail = Mail::whereNull('sent_at') - ->where('id_account', $account->id) - ->whereNull('failed_at') - ->orWhereDate('failed_at', '<', $diff) - ->orderBy('created_at') - ->first(); + $last_mail = $account->emails()->whereNotNull('sent_at')->orderBy('sent_at')->first(); - if (!empty($mail)) { - $list[] = $mail; + // Controllo sul timeout dell'account + $date = new Carbon($last_mail->sent_at); + $now = new Carbon(); + $diff = $date->diffInMilliseconds($now); + + if (empty($last_mail) || $diff > $account->timeout) { + $mail = Mail::whereNull('sent_at') + ->where('id_account', $account->id) + ->where($failed) + ->orderBy('created_at') + ->first(); + + if (!empty($mail)) { + $list[] = $mail; + } } } diff --git a/modules/smtp/actions.php b/modules/smtp/actions.php index 4d8d3efcc..01ec5ce6f 100644 --- a/modules/smtp/actions.php +++ b/modules/smtp/actions.php @@ -35,6 +35,7 @@ switch (post('op')) { 'from_address' => post('from_address'), 'encryption' => post('encryption'), 'pec' => post('pec'), + 'timeout' => post('timeout'), 'ssl_no_verify' => post('ssl_no_verify'), 'predefined' => $predefined, ], ['id' => $id_record]); diff --git a/modules/smtp/edit.php b/modules/smtp/edit.php index 6216f3e71..b5286de18 100644 --- a/modules/smtp/edit.php +++ b/modules/smtp/edit.php @@ -63,8 +63,12 @@ include_once __DIR__.'/../../core.php'; {[ "type": "text", "label": "", "name": "username", "value": "$username$" ]} -