*/ 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): CommandCompletion { foreach ($responses as $response) { if ($response instanceof TaggedResponse) { CompletionChecker::assertSuccess($this->name(), $response); $context->connection()->upgradeToTls(); $context->replaceCapabilities(); return new CommandCompletion($response->status(), $response->text()); } } throw new ImapException('STARTTLS did not receive a tagged completion response.'); } }