- IMAP-Abruf jede Minute (webklex/php-imap, ohne PHP-imap-Erweiterung) oder signierter Push von n8n - Parser für Buchungs-, Storno- und Anfrage-Mails (de/en), Buchungsnummer, An-/Abreise - Erkannte Buchungen werden sofort gesperrt und an handgepflegte Portale weitergegeben; Kalender-Abgleich übernimmt bzw. ersetzt Mail-Sperren - Unklare Mails: Prüf-Mail + Admin-Liste Portal-E-Mails mit Aktion Sperre anlegen - Überwachung des Postfachs in Monitor und /health/sync Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Actions\ProcessPortalMail;
|
|
use App\Channels\ChannelSyncException;
|
|
use App\Channels\Mail\MailboxReader;
|
|
use App\Models\Channel;
|
|
use Illuminate\Console\Attributes\Description;
|
|
use Illuminate\Console\Attributes\Signature;
|
|
use Illuminate\Console\Command;
|
|
|
|
#[Signature('channels:fetch-mail')]
|
|
#[Description('Read booking notifications of the portals from the mailbox and block recognised bookings immediately')]
|
|
class FetchPortalMail extends Command
|
|
{
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(MailboxReader $reader, ProcessPortalMail $processPortalMail): int
|
|
{
|
|
if (! MailboxReader::isConfigured()) {
|
|
$this->line('Kein Postfach konfiguriert (FEWO_MAILBOX_HOST).');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$senders = Channel::query()->active()->get()
|
|
->flatMap(fn (Channel $channel): array => $processPortalMail->senders($channel))
|
|
->unique()
|
|
->values()
|
|
->all();
|
|
|
|
if ($senders === []) {
|
|
$this->line('Für kein Portal sind Absender hinterlegt.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
try {
|
|
$mails = $reader->fetch($senders);
|
|
} catch (ChannelSyncException $exception) {
|
|
$this->error($exception->getMessage());
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
foreach ($mails as $mail) {
|
|
if ($record = $processPortalMail->handle($mail)) {
|
|
$this->info("{$record->channel->name}: {$record->type->getLabel()} → {$record->status->getLabel()} ({$record->subject})");
|
|
}
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|