Schnellerkennung von Portalbuchungen per E-Mail

- 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>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 11:29:26 +02:00
1 parent 0b7205e050
commit e5f9e0762f
33 files changed
+1450 -38

No files matched your search

+54 -4
View File
@@ -2,13 +2,19 @@
namespace App\Http\Controllers;
use App\Actions\MonitorChannels;
use App\Actions\ProcessPortalMail;
use App\Channels\ICal\ICalFeed;
use App\Channels\Mail\MailboxReader;
use App\Channels\Mail\PortalMail;
use App\Enums\ChannelTaskStatus;
use App\Models\Channel;
use App\Models\ChannelTask;
use Carbon\CarbonImmutable;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cache;
/**
* Public endpoints of the channel synchronisation: export feeds for portals, the health check for
@@ -40,24 +46,60 @@ public function health(Request $request): JsonResponse
'last_error' => $channel->last_error,
]);
$openTasks = ChannelTask::query()->open()->count();
$mailbox = [
'configured' => MailboxReader::isConfigured(),
'ok' => ! MonitorChannels::mailboxIsStale(),
'last_success_at' => Cache::get(MailboxReader::LAST_SUCCESS_KEY),
'last_error' => Cache::get(MailboxReader::LAST_ERROR_KEY),
];
$ok = $channels->every(fn (array $channel): bool => $channel['ok']);
$ok = $channels->every(fn (array $channel): bool => $channel['ok']) && $mailbox['ok'];
return response()->json([
'status' => $ok ? 'ok' : 'degraded',
'open_tasks' => $openTasks,
'mailbox' => $mailbox,
'channels' => $channels->values(),
], $ok ? 200 : 503);
}
/**
* Push variant of the e-mail fast path, e.g. from an n8n IMAP trigger:
* JSON {message_id, from, subject, text, received_at}, signed like the automation webhook.
*/
public function portalMail(Request $request, ProcessPortalMail $processPortalMail): JsonResponse
{
$this->verifySignature($request);
$data = $request->validate([
'message_id' => ['required', 'string', 'max:255'],
'from' => ['required', 'string', 'max:255'],
'subject' => ['required', 'string', 'max:500'],
'text' => ['required', 'string', 'max:200000'],
'received_at' => ['nullable', 'date'],
]);
$record = $processPortalMail->handle(new PortalMail(
messageId: $data['message_id'],
from: $data['from'],
subject: $data['subject'],
text: $data['text'],
receivedAt: isset($data['received_at']) ? CarbonImmutable::parse($data['received_at']) : CarbonImmutable::now(),
));
return response()->json([
'processed' => $record !== null,
'type' => $record?->type->value,
'status' => $record?->status->value,
]);
}
/**
* The automation reports a task as done. The raw body must be signed like the outgoing webhook.
*/
public function completeTask(Request $request, ChannelTask $task): JsonResponse
{
$secret = config('fewo.automation.secret');
$signature = (string) $request->header('X-Signature');
abort_if(blank($secret) || ! hash_equals(hash_hmac('sha256', $request->getContent(), $secret), $signature), 403);
$this->verifySignature($request);
if ($task->status === ChannelTaskStatus::Open) {
$task->complete('Automatisierung');
@@ -65,4 +107,12 @@ public function completeTask(Request $request, ChannelTask $task): JsonResponse
return response()->json(['status' => $task->status->value]);
}
private function verifySignature(Request $request): void
{
$secret = config('fewo.automation.secret');
$signature = (string) $request->header('X-Signature');
abort_if(blank($secret) || ! hash_equals(hash_hmac('sha256', $request->getContent(), $secret), $signature), 403);
}
}