redirect(route('ui.webmail.login')); return; } $user = MailUser::where('email', session('webmail_email'))->first(); if (! $user) return; $prefs = $user->webmail_prefs ?? []; $this->showSubscribedOnly = (bool) ($prefs['show_subscribed_only'] ?? false); $this->fetchUnreadAll = (bool) ($prefs['fetch_unread_all'] ?? false); $this->threadMessages = (bool) ($prefs['thread_messages'] ?? false); $this->showFullAddress = (bool) ($prefs['show_full_address'] ?? false); $this->hideEmbeddedAttachments = (bool) ($prefs['hide_embedded_attachments'] ?? false); $this->attachmentsAbove = (bool) ($prefs['attachments_above'] ?? false); $this->autoMarkRead = (bool) ($prefs['auto_mark_read'] ?? true); $this->autoMarkReadDelay = (int) ($prefs['auto_mark_read_delay'] ?? 0); $this->forwardMode = (string)($prefs['forward_mode'] ?? 'inline'); $this->replyBelowQuote = (bool) ($prefs['reply_below_quote'] ?? false); $this->signatureNew = (bool) ($prefs['signature_new'] ?? true); $this->signatureReply = (bool) ($prefs['signature_reply'] ?? false); $this->signatureForward = (bool) ($prefs['signature_forward'] ?? false); $this->composeHtml = (bool) ($prefs['compose_html'] ?? true); $this->defaultFontSize = (int) ($prefs['default_font_size'] ?? 13); $this->showRemoteImages = (string)($prefs['show_remote_images'] ?? 'never'); $this->autosaveInterval = (int) ($prefs['autosave_interval'] ?? 5); $this->signature = (string)($user->signature ?? ''); $this->filterRules = $user->sieve_filter_rules ?? []; $this->vacationEnabled = (bool) $user->vacation_enabled; $this->vacationSubject = (string)($user->vacation_subject ?? ''); $this->vacationBody = (string)($user->vacation_body ?? ''); $this->forwardTo = (string)($user->forward_to ?? ''); } public function save(): void { $this->validate([ 'forwardTo' => 'nullable|email', 'vacationSubject' => 'nullable|string|max:255', 'vacationBody' => 'nullable|string|max:4000', 'newValue' => 'nullable|string|max:255', ]); $user = MailUser::where('email', session('webmail_email'))->first(); if (! $user) return; $user->update([ 'webmail_prefs' => [ 'show_subscribed_only' => $this->showSubscribedOnly, 'fetch_unread_all' => $this->fetchUnreadAll, 'thread_messages' => $this->threadMessages, 'show_full_address' => $this->showFullAddress, 'hide_embedded_attachments' => $this->hideEmbeddedAttachments, 'attachments_above' => $this->attachmentsAbove, 'auto_mark_read' => $this->autoMarkRead, 'auto_mark_read_delay' => $this->autoMarkReadDelay, 'forward_mode' => $this->forwardMode, 'reply_below_quote' => $this->replyBelowQuote, 'signature_new' => $this->signatureNew, 'signature_reply' => $this->signatureReply, 'signature_forward' => $this->signatureForward, 'compose_html' => $this->composeHtml, 'default_font_size' => $this->defaultFontSize, 'show_remote_images' => $this->showRemoteImages, 'autosave_interval' => $this->autosaveInterval, ], 'signature' => $this->signature ?: null, 'sieve_filter_rules' => $this->filterRules, 'vacation_enabled' => $this->vacationEnabled, 'vacation_subject' => $this->vacationSubject ?: null, 'vacation_body' => $this->vacationBody ?: null, 'forward_to' => $this->forwardTo ?: null, ]); $this->applySieve($user->fresh()); $this->dispatch('toast', type: 'done', badge: 'Webmail', title: 'Gespeichert', text: 'Einstellungen wurden gespeichert.', duration: 3000); } public function addFilterRule(): void { $this->validate(['newValue' => 'required|string|max:255']); $this->filterRules[] = [ 'id' => uniqid('r', true), 'field' => $this->newField, 'op' => $this->newOp, 'value' => trim($this->newValue), 'action' => $this->newAction, 'folder' => $this->newFolder, ]; $this->newValue = ''; } public function removeFilterRule(string $id): void { $this->filterRules = array_values( array_filter($this->filterRules, fn($r) => $r['id'] !== $id) ); } private function applySieve(MailUser $user): void { $rules = json_encode($user->sieve_filter_rules ?? []); $email = escapeshellarg($user->email); $forward = escapeshellarg($user->forward_to ?? ''); $vacEn = $user->vacation_enabled ? '1' : '0'; $vacSubj = escapeshellarg($user->vacation_subject ?? 'Ich bin derzeit nicht erreichbar.'); $vacBody = escapeshellarg($user->vacation_body ?? ''); $rulesEsc= escapeshellarg($rules); $cmd = "sudo -n /usr/local/sbin/mailwolt-apply-sieve" . " --email {$email}" . " --forward {$forward}" . " --vacation-enabled {$vacEn}" . " --vacation-subject {$vacSubj}" . " --vacation-body {$vacBody}" . " --filter-rules {$rulesEsc}" . " 2>&1"; $out = shell_exec($cmd); if ($out) { \Illuminate\Support\Facades\Log::info('mailwolt-apply-sieve', ['output' => $out]); } } public function render() { return view('livewire.ui.webmail.settings'); } }