*/ final class LogoutCommand implements CommandInterface { public function name(): string { return 'LOGOUT'; } 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('LOGOUT'); } public function handle(ResponseStream $responses, SessionContext $context): CommandCompletion { foreach ($responses as $response) { if ($response instanceof TaggedResponse) { CompletionChecker::assertSuccess($this->name(), $response); $context->setSelectedMailbox(null); $context->setState(SessionState::Logout); $context->connection()->disconnect(); return new CommandCompletion($response->status(), $response->text()); } } throw new ImapException('LOGOUT did not receive a tagged completion response.'); } }