generated from Nodarx/template
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXM\ProviderImap\Client\Command;
|
|
|
|
use KTXM\ProviderImap\Client\Command\Result\CapabilityResult;
|
|
use KTXM\ProviderImap\Client\ImapException;
|
|
use KTXM\ProviderImap\Client\Protocol\RequestFrame;
|
|
use KTXM\ProviderImap\Client\Protocol\Response\TaggedResponse;
|
|
use KTXM\ProviderImap\Client\Protocol\Response\UntaggedResponse;
|
|
use KTXM\ProviderImap\Client\Protocol\ResponseStream;
|
|
use KTXM\ProviderImap\Client\SessionContext;
|
|
use KTXM\ProviderImap\Client\SessionState;
|
|
|
|
/**
|
|
* @implements CommandInterface<CapabilityResult>
|
|
*/
|
|
final class CapabilityCommand implements CommandInterface
|
|
{
|
|
public function name(): string
|
|
{
|
|
return 'CAPABILITY';
|
|
}
|
|
|
|
public function allowedStates(): array
|
|
{
|
|
return [
|
|
SessionState::NotAuthenticated,
|
|
SessionState::Authenticated,
|
|
SessionState::Selected,
|
|
];
|
|
}
|
|
|
|
public function encode(string $tag, SessionContext $context): RequestFrame
|
|
{
|
|
unset($tag, $context);
|
|
|
|
return new RequestFrame('CAPABILITY');
|
|
}
|
|
|
|
public function handle(ResponseStream $responses, SessionContext $context): CapabilityResult
|
|
{
|
|
$capabilities = [];
|
|
|
|
foreach ($responses as $response) {
|
|
if ($response instanceof UntaggedResponse && $response->label() === 'CAPABILITY') {
|
|
$capabilities = array_map('strtoupper', $response->payloadTokens());
|
|
}
|
|
|
|
if ($response instanceof TaggedResponse) {
|
|
if (!$response->isOk()) {
|
|
throw new ImapException('CAPABILITY failed: ' . $response->text());
|
|
}
|
|
}
|
|
}
|
|
|
|
$context->replaceCapabilities(...$capabilities);
|
|
|
|
return new CapabilityResult($context->capabilities());
|
|
}
|
|
} |