*/ private readonly array $values, private readonly string $password, ) {} public static function for(Instance $instance): self { $host = trim((string) Settings::get('mail.host', '')); $port = (int) Settings::get('mail.port', 0); if ($host === '' || $port < 1) { return new self('no_server', [], ''); } $box = self::mailboxFor($instance); if ($box === null || ! $box->isConfigured()) { return new self('no_mailbox', [], ''); } // Die Adresse zerfaellt in die beiden Werte, die Nextcloud getrennt // fuehrt: den linken Teil als Absender, den rechten als Maildomain. [$local, $domain] = array_pad(explode('@', $box->address, 2), 2, ''); return new self(null, [ 'mail_smtpmode' => 'smtp', 'mail_smtphost' => $host, 'mail_smtpport' => (string) $port, 'mail_smtpsecure' => (string) Settings::get('mail.encryption', 'tls'), 'mail_smtpauth' => 'true', 'mail_smtpname' => $box->smtpUsername(), 'mail_from_address' => $local, 'mail_domain' => $domain, ], (string) $box->password); } /** * Heute fuer jede Instanz dasselbe Konto. Siehe Klassenkopf — hier haengt * die spaetere Fassung mit einem Konto je Kunde. */ private static function mailboxFor(Instance $instance): ?Mailbox { return Mailbox::findByKey(self::RELAY_KEY); } public function available(): bool { return $this->problem === null; } /** `no_server`, `no_mailbox` oder null. */ public function problem(): ?string { return $this->problem; } /** * Alles ausser dem Passwort. Das geht einen eigenen Weg, damit es beim * Bauen der Befehle nicht versehentlich mitwandert. * * @return array */ public function values(): array { return $this->values; } public function password(): string { return $this->password; } }