effectiveTenant(); } /** * The recipients of internal notifications (the landlord's setting, else FEWO_NOTIFICATION_EMAIL while no landlord is known). * * @return list */ public static function notificationRecipients(): array { return self::tenant()?->notificationRecipients() ?: self::addressList((string) config('fewo.notification_email')); } /** * "a@x.de, b@y.de; c@z.de" → valid addresses only. * * @return list */ public static function addressList(?string $value): array { return array_values(array_filter( array_map('trim', preg_split('/[,;\s]+/', (string) $value) ?: []), fn (string $address): bool => filter_var($address, FILTER_VALIDATE_EMAIL) !== false, )); } public static function isLive(): bool { return (self::tenant()?->operating_mode ?? self::MODE_TEST) === self::MODE_LIVE; } /** * Where all e-mails go instead of their real recipients, or null when mails are delivered normally. * FEWO_MAIL_REDIRECT_TO in .env always wins (hard override for test servers). */ public static function mailRedirect(): ?string { return self::mailRedirectFor(self::tenant()); } public static function mailRedirectFor(?Tenant $tenant): ?string { $override = config('fewo.mail_redirect_to'); if (filled($override)) { return (string) $override; } if ($tenant?->isLive()) { return null; } // A landlord without any address of their own must not fall through to normal delivery: the operator's // address catches the mails until the landlord has entered their own. $recipients = $tenant?->notificationRecipients() ?: self::addressList((string) config('fewo.notification_email')); return $tenant?->test_recipient ?: ($recipients[0] ?? null); } /** * Applies the redirect of the current landlord to the mailer; called after saving. */ public static function applyMailRouting(): void { app(TenantConfig::class)->refresh(); } }