33 lines
1023 B
PHP
33 lines
1023 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\MailFlow\ImapInbox;
|
|
use App\Services\MailFlow\Settings;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class PollMailInbox extends Command
|
|
{
|
|
protected $signature = 'mail:poll-inbox';
|
|
protected $description = 'Read new conventional mailbox headers and queue automatic acknowledgements';
|
|
|
|
public function handle(ImapInbox $inbox): int
|
|
{
|
|
if (!Settings::get('enabled') || !Settings::get('inbound_enabled')) {
|
|
return self::SUCCESS;
|
|
}
|
|
$lock = Cache::lock('mailflow:inbox', 1800);
|
|
if (!$lock->get()) { return self::SUCCESS; }
|
|
try {
|
|
$this->info('New incoming messages: ' . $inbox->poll());
|
|
return self::SUCCESS;
|
|
} catch (\Throwable $e) {
|
|
$this->error('Inbox polling failed (' . get_class($e) . '). Check the IMAP settings/extension.');
|
|
return self::FAILURE;
|
|
} finally {
|
|
$lock->release();
|
|
}
|
|
}
|
|
}
|