, text:string}> $responseCodes * @param ?array{uidValidity:string, sourceUids:string, destinationUids:string} $copyUid * @param list $expunged * @param list $vanished */ public function __construct( private readonly string $status, private readonly string $text, private readonly array $responseCodes = [], private readonly ?array $copyUid = null, private readonly bool $tryCreate = false, private readonly ?string $highestModSeq = null, private readonly array $expunged = [], private readonly array $vanished = [], ) {} public function status(): string { return $this->status; } public function text(): string { return $this->text; } public function isOk(): bool { return $this->status === 'OK'; } /** * @return list, text:string}> */ public function responseCodes(): array { return $this->responseCodes; } /** * @return ?array{uidValidity:string, sourceUids:string, destinationUids:string} */ public function copyUid(): ?array { return $this->copyUid; } /** * @return array */ public function copyUidMap(): array { if ($this->copyUid === null) { return []; } $sourceUids = $this->expandUidSet($this->copyUid['sourceUids']); $destinationUids = $this->expandUidSet($this->copyUid['destinationUids']); if (count($sourceUids) !== count($destinationUids)) { return []; } $mapping = []; foreach ($sourceUids as $index => $sourceUid) { $mapping[$sourceUid] = $destinationUids[$index]; } return $mapping; } public function tryCreate(): bool { return $this->tryCreate; } public function highestModSeq(): ?string { return $this->highestModSeq; } /** * @return list */ public function expunged(): array { return $this->expunged; } /** * @return list */ public function vanished(): array { return $this->vanished; } public function hasResponseCode(string $name): bool { $name = strtoupper(trim($name)); foreach ($this->responseCodes as $responseCode) { if ($responseCode['name'] === $name) { return true; } } return false; } /** * @return list */ private function expandUidSet(string $value): array { $expanded = []; foreach (explode(',', $value) as $segment) { $segment = trim($segment); if ($segment === '') { continue; } if (!str_contains($segment, ':')) { $expanded[] = $segment; continue; } [$start, $end] = array_map('trim', explode(':', $segment, 2)); if (!ctype_digit($start) || !ctype_digit($end)) { return []; } $range = range((int) $start, (int) $end, (int) $start <= (int) $end ? 1 : -1); foreach ($range as $uid) { $expanded[] = (string) $uid; } } return $expanded; } }