authorize('mail.manage'); $box = Mailbox::query()->where('uuid', $uuid)->firstOrFail(); $this->uuid = $box->uuid; $this->address = $box->address; $this->displayName = (string) $box->display_name; $this->username = (string) $box->username; $this->noReply = $box->no_reply; $this->active = $box->active; } public function save(): void { $this->authorize('mail.manage'); $this->validate([ 'address' => ['required', 'email', 'max:255'], 'displayName' => ['nullable', 'string', 'max:255'], 'username' => ['nullable', 'string', 'max:255'], 'password' => ['nullable', 'string', 'max:255'], ]); // A password can only be STORED where SECRETS_KEY exists to encrypt it // under — the same condition the page's own banner already names. // Checked here rather than left for Mailbox::setPasswordAttribute() to // throw through: an uncaught RuntimeException would render Laravel's // debug page, whose request-payload inspector can show the very // password just typed. The page must say so, not crash on it. if ($this->password !== '' && ! app(SecretCipher::class)->isUsable()) { $this->addError('password', __('mail_settings.no_key')); return; } $box = Mailbox::query()->where('uuid', $this->uuid)->firstOrFail(); $box->address = $this->address; $box->display_name = $this->displayName ?: null; $box->username = $this->username ?: null; $box->no_reply = $this->noReply; $box->active = $this->active; // Empty means "leave it alone", not "delete it" — otherwise every edit // of an address would silently drop the password. if ($this->password !== '') { $box->password = $this->password; $box->last_verified_at = null; } $box->save(); $this->password = ''; $this->dispatch('notify', message: __('mail_settings.saved')); $this->dispatch('mailbox-saved'); $this->closeModal(); } public function render() { return view('livewire.edit-mailbox'); } }