81 lines
2.7 KiB
PHP
81 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\Nx\Mail\Modal;
|
|
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class QueueMessageModal extends ModalComponent
|
|
{
|
|
public string $queueId;
|
|
public array $message = [];
|
|
|
|
public function mount(string $queueId): void
|
|
{
|
|
$this->queueId = $queueId;
|
|
$this->message = $this->fetchMessage($queueId);
|
|
}
|
|
|
|
public function delete(): void
|
|
{
|
|
@shell_exec('sudo postsuper -d ' . escapeshellarg($this->queueId) . ' 2>&1');
|
|
$this->dispatch('toast', type: 'success', title: 'Nachricht gelöscht');
|
|
$this->dispatch('queue:updated');
|
|
$this->dispatch('closeModal');
|
|
}
|
|
|
|
public function hold(): void
|
|
{
|
|
@shell_exec('sudo postsuper -h ' . escapeshellarg($this->queueId) . ' 2>&1');
|
|
$this->message['queue'] = 'hold';
|
|
$this->dispatch('toast', type: 'info', title: 'Nachricht zurückgestellt');
|
|
$this->dispatch('queue:updated');
|
|
$this->dispatch('closeModal');
|
|
}
|
|
|
|
public function release(): void
|
|
{
|
|
@shell_exec('sudo postsuper -H ' . escapeshellarg($this->queueId) . ' 2>&1');
|
|
$this->dispatch('toast', type: 'success', title: 'Nachricht freigegeben');
|
|
$this->dispatch('queue:updated');
|
|
$this->dispatch('closeModal');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.ui.nx.mail.modal.queue-message-modal');
|
|
}
|
|
|
|
private function fetchMessage(string $id): array
|
|
{
|
|
// Get queue details from postqueue -j
|
|
$out = trim(@shell_exec('postqueue -j 2>/dev/null') ?? '');
|
|
foreach (explode("\n", $out) as $line) {
|
|
$line = trim($line);
|
|
if ($line === '') continue;
|
|
$m = json_decode($line, true);
|
|
if (!is_array($m) || ($m['queue_id'] ?? '') !== $id) continue;
|
|
|
|
$recipients = $m['recipients'] ?? [];
|
|
$rcptList = array_map(fn($r) => [
|
|
'address' => $r['address'] ?? '',
|
|
'reason' => $r['delay_reason'] ?? '',
|
|
], $recipients);
|
|
|
|
// Try to get message headers
|
|
$header = trim(@shell_exec('sudo postcat -hq ' . escapeshellarg($id) . ' 2>/dev/null') ?? '');
|
|
|
|
return [
|
|
'id' => $id,
|
|
'queue' => $m['queue_name'] ?? 'deferred',
|
|
'sender' => $m['sender'] ?? '—',
|
|
'recipients' => $rcptList,
|
|
'size' => (int)($m['message_size'] ?? 0),
|
|
'arrival' => (int)($m['arrival_time'] ?? 0),
|
|
'header' => mb_substr($header, 0, 3000),
|
|
];
|
|
}
|
|
|
|
return ['id' => $id, 'queue' => '—', 'sender' => '—', 'recipients' => [], 'size' => 0, 'arrival' => 0, 'header' => ''];
|
|
}
|
|
}
|