v0.11 U5: Posteingang, deterministische Zuordnung, Klärungsansicht

- mailboxes (Modell für mehrere, eines aktiv): Übernahme des bisherigen
  Postfachs als „nur Portal-Mails“; Modus „alle Nachrichten“ für ein
  eigenes Postfach; Adresse als Antwortadresse der Rückfragen.
- inbound_messages: jede Nachricht zuerst gespeichert, einmal je
  Message-ID, mit Testbetriebs-Kennzeichen (M10). Portal-Mails laufen
  unverändert über den Portalpfad (CH-08).
- MessageMatcher (CH-13, ohne Scoring): Antwortbezug; Vorgangsnummer nur
  mit dem Gast als Absender; sonst Absender + Wohnung + beide Termine eines
  einzigen offenen Vorgangs. Ein offener Vorgang des Absenders allein
  genügt nicht (nur Hinweis). Alles andere → Klärung (M04).
- Ausgehende Mails speichern ihre Message-ID; Antwort stoppt Erinnerungen.
- Filament „Posteingang“: lesen, Vorgang zuordnen, als neue Anfrage
  anlegen, ignorieren, erledigt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-03 13:39:20 +01:00
1 parent e4a3cb7f7b
commit dff9e2344e
19 files changed
+990 -59

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@
/**
* An e-mail that went out for a booking (communication log). Only subject and audience are kept.
*/
#[Fillable(['booking_id', 'audience', 'subject', 'sent_at'])]
#[Fillable(['booking_id', 'audience', 'subject', 'message_id', 'sent_at'])]
class BookingMessage extends Model
{
public $timestamps = false;
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* A message read from the landlord's mailbox (v0.11, S2/S3), stored before anything is done with it. It is assigned
* to a case only by a reliable reference (CH-13); otherwise it waits in the inbox for the landlord. Being assigned is
* not yet permission to take anything over.
*/
#[Fillable(['mailbox_id', 'message_id', 'in_reply_to', 'references', 'from_address', 'from_name', 'to_addresses', 'subject', 'body', 'received_at', 'test_mode', 'status', 'booking_id', 'match_reason', 'hints', 'portal_email_id', 'extraction_status', 'extraction', 'processed_at'])]
class InboundMessage extends Model
{
use BelongsToTenant;
public const NEW = 'new';
/** Assigned to a case by a reliable reference. */
public const ASSIGNED = 'assigned';
/** Waits for the landlord: no or no reliable reference, or contradicting hints. */
public const NEEDS_REVIEW = 'needs_review';
/** A portal notification, handled by the existing portal path. */
public const PORTAL = 'portal';
public const IGNORED = 'ignored';
/** Done: details taken over or decided by the landlord. */
public const PROCESSED = 'processed';
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'body' => 'encrypted',
'references' => 'array',
'to_addresses' => 'array',
'hints' => 'array',
'extraction' => 'array',
'test_mode' => 'boolean',
'received_at' => 'immutable_datetime',
'processed_at' => 'immutable_datetime',
];
}
/**
* @return BelongsTo<Booking, $this>
*/
public function booking(): BelongsTo
{
return $this->belongsTo(Booking::class);
}
public function statusLabel(): string
{
return match ($this->status) {
self::ASSIGNED => 'einem Vorgang zugeordnet',
self::NEEDS_REVIEW => 'zu klären',
self::PORTAL => 'Portal-Mail',
self::IGNORED => 'ignoriert',
self::PROCESSED => 'erledigt',
default => 'neu',
};
}
}
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Model;
/**
* A landlord's IMAP mailbox (v0.11, CH-05). Several may exist, one is active. "portal_only" reads the portals'
* booking notifications as before; "full" reads every message of a mailbox dedicated to guest communication.
*/
#[Fillable(['label', 'host', 'port', 'encryption', 'username', 'password', 'folder', 'address', 'mode', 'is_active', 'last_fetched_at'])]
#[Hidden(['password'])]
class Mailbox extends Model
{
use BelongsToTenant;
public const PORTAL_ONLY = 'portal_only';
public const FULL = 'full';
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'password' => 'encrypted',
'is_active' => 'boolean',
'port' => 'integer',
'last_fetched_at' => 'immutable_datetime',
];
}
public function readsEverything(): bool
{
return $this->mode === self::FULL;
}
/**
* Connection data in the form the reader expects, or null when it is not usable.
*
* @return array{host: string, port: int, encryption: string, username: string, password: ?string, folder: string}|null
*/
public function connection(): ?array
{
if (blank($this->host) || blank($this->username)) {
return null;
}
return [
'host' => (string) $this->host,
'port' => (int) ($this->port ?: 993),
'encryption' => (string) ($this->encryption ?: 'ssl'),
'username' => (string) $this->username,
'password' => $this->password,
'folder' => (string) ($this->folder ?: 'INBOX'),
];
}
}
+14
View File
@@ -123,6 +123,12 @@ public function serviceUsages(): HasMany
*/
public function mailbox(): ?array
{
// v0.11: the active mailbox record leads; the tenant columns remain the fallback until every system migrated.
$mailbox = $this->activeMailbox();
if ($mailbox !== null) {
return $mailbox->connection();
}
if (blank($this->mailbox_host) || blank($this->mailbox_username)) {
return null;
}
@@ -137,6 +143,14 @@ public function mailbox(): ?array
];
}
/**
* The landlord's active mailbox (at most one, CH-05).
*/
public function activeMailbox(): ?Mailbox
{
return Mailbox::query()->withoutGlobalScopes()->where('tenant_id', $this->id)->where('is_active', true)->orderBy('id')->first();
}
public function isLive(): bool
{
return $this->operating_mode === 'live';