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