generated from Nodarx/template
ad6b7c5eba
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
114 lines
2.7 KiB
PHP
114 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXM\ProviderImap\Smtp;
|
|
|
|
final class ConnectionConfig
|
|
{
|
|
public function __construct(
|
|
private readonly string $host,
|
|
private readonly int $port = 587,
|
|
private readonly ConnectionSecurity $security = ConnectionSecurity::StartTls,
|
|
private readonly ?string $username = null,
|
|
private readonly ?string $password = null,
|
|
private readonly float $timeout = 30.0,
|
|
private readonly bool $verifyPeer = true,
|
|
private readonly bool $verifyPeerName = true,
|
|
private readonly bool $allowSelfSigned = false,
|
|
private readonly ?string $ehloDomain = null,
|
|
) {}
|
|
|
|
public function host(): string
|
|
{
|
|
return $this->host;
|
|
}
|
|
|
|
public function port(): int
|
|
{
|
|
return $this->port;
|
|
}
|
|
|
|
public function security(): ConnectionSecurity
|
|
{
|
|
return $this->security;
|
|
}
|
|
|
|
public function username(): ?string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function password(): ?string
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function hasCredentials(): bool
|
|
{
|
|
return $this->username !== null && $this->username !== ''
|
|
&& $this->password !== null && $this->password !== '';
|
|
}
|
|
|
|
public function timeout(): float
|
|
{
|
|
return $this->timeout;
|
|
}
|
|
|
|
public function verifyPeer(): bool
|
|
{
|
|
return $this->verifyPeer;
|
|
}
|
|
|
|
public function verifyPeerName(): bool
|
|
{
|
|
return $this->verifyPeerName;
|
|
}
|
|
|
|
public function allowSelfSigned(): bool
|
|
{
|
|
return $this->allowSelfSigned;
|
|
}
|
|
|
|
/**
|
|
* The domain announced in the EHLO command. Falls back to the local
|
|
* hostname, then to a literal so a value is always sent.
|
|
*/
|
|
public function ehloDomain(): string
|
|
{
|
|
if ($this->ehloDomain !== null && $this->ehloDomain !== '') {
|
|
return $this->ehloDomain;
|
|
}
|
|
|
|
$hostname = gethostname();
|
|
|
|
return $hostname !== false && $hostname !== '' ? $hostname : 'localhost';
|
|
}
|
|
|
|
public function endpoint(): string
|
|
{
|
|
return sprintf('%s://%s:%d', $this->security->transport(), $this->host, $this->port);
|
|
}
|
|
|
|
/**
|
|
* @return array<string,array<string,mixed>>
|
|
*/
|
|
public function streamContextOptions(): array
|
|
{
|
|
return [
|
|
'ssl' => [
|
|
'verify_peer' => $this->verifyPeer,
|
|
'verify_peer_name' => $this->verifyPeerName,
|
|
'allow_self_signed' => $this->allowSelfSigned,
|
|
'SNI_enabled' => true,
|
|
'peer_name' => $this->host,
|
|
],
|
|
];
|
|
}
|
|
}
|