generated from Nodarx/template
refactor: use custom imap client
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
54
lib/Client/Command/StartTlsCommand.php
Normal file
54
lib/Client/Command/StartTlsCommand.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderImap\Client\Command;
|
||||
|
||||
use KTXM\ProviderImap\Client\Command\Result\CommandStatusResult;
|
||||
use KTXM\ProviderImap\Client\ImapException;
|
||||
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
||||
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
|
||||
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
|
||||
use KTXM\ProviderImap\Client\SessionContext;
|
||||
use KTXM\ProviderImap\Client\SessionState;
|
||||
|
||||
/**
|
||||
* @implements CommandInterface<CommandStatusResult>
|
||||
*/
|
||||
final class StartTlsCommand implements CommandInterface
|
||||
{
|
||||
public function name(): string
|
||||
{
|
||||
return 'STARTTLS';
|
||||
}
|
||||
|
||||
public function allowedStates(): array
|
||||
{
|
||||
return [SessionState::NotAuthenticated];
|
||||
}
|
||||
|
||||
public function encode(string $tag, SessionContext $context): RequestFrame
|
||||
{
|
||||
unset($tag, $context);
|
||||
|
||||
return new RequestFrame('STARTTLS');
|
||||
}
|
||||
|
||||
public function handle(ResponseStream $responses, SessionContext $context): CommandStatusResult
|
||||
{
|
||||
foreach ($responses as $response) {
|
||||
if ($response instanceof TaggedResponse) {
|
||||
if (!$response->isOk()) {
|
||||
throw new ImapException('STARTTLS failed: ' . $response->text());
|
||||
}
|
||||
|
||||
$context->connection()->upgradeToTls();
|
||||
$context->replaceCapabilities();
|
||||
|
||||
return new CommandStatusResult($response->status(), $response->text());
|
||||
}
|
||||
}
|
||||
|
||||
throw new ImapException('STARTTLS did not receive a tagged completion response.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user