*/ final class DeleteCommand implements CommandInterface { public function __construct( private readonly string $mailbox, ) {} public function name(): string { return 'DELETE'; } public function allowedStates(): array { return [ SessionState::Authenticated, SessionState::Selected, ]; } public function encode(string $tag, SessionContext $context): RequestFrame { unset($tag, $context); return new RequestFrame(sprintf('DELETE %s', StringEncoder::quote($this->mailbox))); } public function handle(ResponseStream $responses, SessionContext $context): CommandCompletion { if ($context->selectedMailbox() === $this->mailbox) { $context->setSelectedMailbox(null); $context->setState(SessionState::Authenticated); } foreach ($responses as $response) { if ($response instanceof TaggedResponse) { CompletionChecker::assertSuccess($this->name(), $response); return new CommandCompletion($response->status(), $response->text()); } } throw new ImapException('DELETE did not receive a tagged completion response.'); } }