Postfach: Posteingang wird unter jedem Namen gefunden; kein doppeltes „SSL“

- MailboxReader::folder(): „Posteingang“, „Inbox“ oder leer → INBOX (so
  heißt der Posteingang auf dem IMAP-Server); andere Namen ohne Beachtung
  der Groß-/Kleinschreibung; unbekannter Ordner → Meldung mit den
  vorhandenen Ordnern statt „Call to a member function query() on null“.
  Gilt für Portal-Abruf, vollständigen Abruf und „Postfach prüfen“.
- Verschlüsselung: Platzhalter „Standard (SSL)“ statt eines zweiten „SSL“;
  Hinweis am Ordnerfeld.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-03 17:26:49 +01:00
1 parent 3a039e5c50
commit 154b8a434c
3 files changed
+54 -5

No files matched your search

+27 -3
View File
@@ -7,7 +7,9 @@
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Cache;
use Throwable;
use Webklex\PHPIMAP\Client;
use Webklex\PHPIMAP\ClientManager;
use Webklex\PHPIMAP\Folder;
use Webklex\PHPIMAP\Message;
/**
@@ -70,7 +72,7 @@ public function fetch(array $senders): array
'protocol' => 'imap',
]);
$client->connect();
$folder = $client->getFolderByPath($config['folder']);
$folder = self::folder($client, $config['folder']);
$mails = [];
foreach ($senders as $sender) {
@@ -119,7 +121,7 @@ public function fetchAll(): array
'username' => $config['username'], 'password' => $config['password'], 'protocol' => 'imap',
]);
$client->connect();
$messages = $client->getFolderByPath($config['folder'])->query()
$messages = self::folder($client, $config['folder'])->query()
->whereSince(CarbonImmutable::today()->subDays((int) config('fewo.mailbox.lookback_days', 3)))
->leaveUnread()
->get();
@@ -156,7 +158,7 @@ public function probe(array $config): int
'username' => $config['username'], 'password' => $config['password'], 'protocol' => 'imap',
]);
$client->connect();
$count = $client->getFolderByPath($config['folder'])->query()
$count = self::folder($client, $config['folder'])->query()
->whereSince(CarbonImmutable::today()->subDays((int) config('fewo.mailbox.lookback_days', 3)))
->leaveUnread()->setFetchBody(false)->count();
$client->disconnect();
@@ -167,6 +169,28 @@ public function probe(array $config): int
return (int) $count;
}
/**
* The folder to read. The inbox is called "INBOX" on the IMAP server, whatever the provider's web mail shows
* ("Posteingang", "Inbox"); other names match regardless of case. An unknown name names the existing folders.
*
* @throws ChannelSyncException
*/
public static function folder(Client $client, ?string $name): Folder
{
$name = trim((string) $name);
$wanted = $name === '' || in_array(mb_strtolower($name), ['inbox', 'posteingang'], true) ? 'INBOX' : $name;
$folders = $client->getFolders(false);
$folder = $folders->first(fn (Folder $folder): bool => $folder->path === $wanted)
?? $folders->first(fn (Folder $folder): bool => mb_strtolower($folder->path) === mb_strtolower($wanted) || mb_strtolower($folder->name) === mb_strtolower($wanted));
if ($folder === null) {
throw new ChannelSyncException('Ordner „'.$name.'“ gibt es in diesem Postfach nicht. Vorhanden: '.$folders->map(fn (Folder $folder): string => $folder->path)->implode(', ').' (der Posteingang heißt „INBOX“).');
}
return $folder;
}
private function toPortalMail(Message $message): PortalMail
{
$text = $message->getTextBody();
+3 -2
View File
@@ -254,8 +254,9 @@ public function form(Schema $schema): Schema
Select::make('mailbox_encryption')
->label('Verschlüsselung')
->options(['ssl' => 'SSL', 'tls' => 'TLS', 'starttls' => 'STARTTLS'])
->placeholder('SSL'),
TextInput::make('mailbox_folder')->label('Ordner')->placeholder('INBOX')->maxLength(190),
->placeholder('Standard (SSL)'),
TextInput::make('mailbox_folder')->label('Ordner')->placeholder('INBOX')->maxLength(190)
->helperText('Leer lassen für den Posteingang (auf dem Server „INBOX“, auch „Posteingang“ wird erkannt).'),
Select::make('mailbox_mode')->label('Was wird gelesen?')
->options([Mailbox::PORTAL_ONLY => 'Nur Buchungsmails der Portale (wie bisher)', Mailbox::FULL => 'Alle Nachrichten (eigenes Postfach für die Gästekommunikation)'])
->required()
+24
View File
@@ -35,6 +35,9 @@
use Livewire\Livewire;
use Mockery;
use Tests\TestCase;
use Webklex\PHPIMAP\Client;
use Webklex\PHPIMAP\Folder;
use Webklex\PHPIMAP\Support\FolderCollection;
/**
* v0.11 package U5: the inbox of the guest communication mailbox – stored once, portal notifications through the
@@ -200,6 +203,27 @@ public function test_the_mailbox_can_be_checked_and_incoming_mails_show_on_the_c
->assertSee('Frage zu '.$booking->reference);
}
public function test_the_inbox_is_found_under_its_web_mail_name_and_an_unknown_folder_is_explained(): void
{
$folder = function (string $path): Folder {
$folder = Mockery::mock(Folder::class);
$folder->path = $path;
$folder->name = $path;
return $folder;
};
$client = Mockery::mock(Client::class);
$client->shouldReceive('getFolders')->andReturn(FolderCollection::make([$folder('Trash'), $folder('Sent Items'), $folder('INBOX')]));
foreach (['Posteingang', '', 'inbox', 'INBOX'] as $name) {
$this->assertSame('INBOX', MailboxReader::folder($client, $name)->path);
}
$this->assertSame('Sent Items', MailboxReader::folder($client, 'sent items')->path);
$this->expectExceptionMessage('Vorhanden: Trash, Sent Items, INBOX');
MailboxReader::folder($client, 'Archiv');
}
private function request(string $arrival = '2026-11-07', string $departure = '2026-11-10'): Booking
{
return app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org'])->fresh();