82 lines
2.7 KiB
PHP
82 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\Nx\Mail\Modal;
|
|
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class QuarantineMessageModal extends ModalComponent
|
|
{
|
|
public string $msgId;
|
|
public array $message = [];
|
|
|
|
public function mount(string $msgId): void
|
|
{
|
|
$this->msgId = $msgId;
|
|
$this->message = $this->fetchMessage($msgId);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.ui.nx.mail.modal.quarantine-message-modal');
|
|
}
|
|
|
|
private function fetchMessage(string $id): array
|
|
{
|
|
$password = env('RSPAMD_PASSWORD', '');
|
|
$opts = [
|
|
'http' => [
|
|
'timeout' => 3,
|
|
'ignore_errors' => true,
|
|
'header' => $password !== '' ? "Password: {$password}\r\n" : '',
|
|
],
|
|
];
|
|
$ctx = stream_context_create($opts);
|
|
$raw = @file_get_contents("http://127.0.0.1:11334/history?rows=500", false, $ctx);
|
|
|
|
if (!$raw) return $this->emptyMessage($id);
|
|
|
|
$data = json_decode($raw, true);
|
|
$items = $data['rows'] ?? (isset($data[0]) ? $data : []);
|
|
|
|
foreach ($items as $r) {
|
|
$scanId = $r['scan_id'] ?? ($r['id'] ?? '');
|
|
if ($scanId !== $id) continue;
|
|
|
|
$rcpt = $r['rcpt'] ?? [];
|
|
if (is_array($rcpt)) $rcpt = implode(', ', $rcpt);
|
|
|
|
$symbols = [];
|
|
foreach ($r['symbols'] ?? [] as $name => $sym) {
|
|
$symbols[] = [
|
|
'name' => $name,
|
|
'score' => round((float)($sym['score'] ?? 0), 3),
|
|
'description' => $sym['description'] ?? '',
|
|
];
|
|
}
|
|
usort($symbols, fn($a, $b) => abs($b['score']) <=> abs($a['score']));
|
|
|
|
return [
|
|
'id' => $id,
|
|
'msg_id' => $r['message-id'] ?? '—',
|
|
'from' => $r['from'] ?? $r['sender'] ?? '—',
|
|
'rcpt' => $rcpt ?: '—',
|
|
'subject' => $r['subject'] ?? '(kein Betreff)',
|
|
'score' => round((float)($r['score'] ?? 0), 2),
|
|
'required' => round((float)($r['required_score'] ?? 15), 2),
|
|
'action' => $r['action'] ?? 'unknown',
|
|
'time' => (int)($r['unix_time'] ?? 0),
|
|
'size' => (int)($r['size'] ?? 0),
|
|
'ip' => $r['ip'] ?? '—',
|
|
'symbols' => $symbols,
|
|
];
|
|
}
|
|
|
|
return $this->emptyMessage($id);
|
|
}
|
|
|
|
private function emptyMessage(string $id): array
|
|
{
|
|
return ['id' => $id, 'from' => '—', 'rcpt' => '—', 'subject' => '—', 'score' => 0, 'required' => 0, 'action' => '—', 'time' => 0, 'size' => 0, 'ip' => '—', 'symbols' => [], 'msg_id' => '—'];
|
|
}
|
|
}
|