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