acceptJson()->timeout(15); } /** All mailboxes for the user (optionally scoped to one email domain). */ public function forUser(string $publicId, ?int $emailDomainId = null): array { $q = ['user' => $publicId]; if ($emailDomainId) { $q['email_domain_id'] = $emailDomainId; } return $this->data($this->http()->get($this->base(), $q)); } public function show(string $publicId, int $id): array { return $this->data($this->http()->get($this->base().'/'.$id, ['user' => $publicId])); } /** * Create a mailbox. The Email app does its own wallet billing (§4-A) before * calling and passes is_paid + payment_reference. Returns the mailbox detail. */ public function create(string $publicId, int $emailDomainId, string $localPart, string $displayName, string $password, ?int $quotaMb = null, bool $isPaid = false, ?string $paymentReference = null): array { $res = $this->http()->post($this->base(), array_filter([ 'user' => $publicId, 'email_domain_id' => $emailDomainId, 'local_part' => $localPart, 'display_name' => $displayName, 'password' => $password, 'quota_mb' => $quotaMb, 'is_paid' => $isPaid, 'payment_reference' => $paymentReference, ], fn ($v) => $v !== null)); $res->throw(); return (array) $res->json('data'); } public function resetPassword(string $publicId, int $id, string $password): array { $res = $this->http()->patch($this->base().'/'.$id.'/password', ['user' => $publicId, 'password' => $password]); $res->throw(); return (array) $res->json('data'); } /** Change a mailbox's storage plan (quota). Billing is done before this call. */ public function updateQuota(string $publicId, int $id, int $quotaMb, bool $isPaid = false, ?string $paymentReference = null): array { $res = $this->http()->patch($this->base().'/'.$id.'/quota', array_filter([ 'user' => $publicId, 'quota_mb' => $quotaMb, 'is_paid' => $isPaid, 'payment_reference' => $paymentReference, ], fn ($v) => $v !== null)); $res->throw(); return (array) $res->json('data'); } public function delete(string $publicId, int $id): void { $this->http()->delete($this->base().'/'.$id, ['user' => $publicId])->throw(); } private function data($res): array { $res->throw(); return (array) ($res->json('data') ?? $res->json()); } }