From 5ff4f3e311b9796e939672158501994e0b6e3382 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 7 Jul 2026 08:58:20 -0500 Subject: [PATCH] Outbox: add SEND button for queued drafts (compose previously had no way to actually send), fix VIEW showing body via list endpoint that omits it --- public_html/admin/index.php | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/public_html/admin/index.php b/public_html/admin/index.php index 6d06942..297fa65 100644 --- a/public_html/admin/index.php +++ b/public_html/admin/index.php @@ -837,6 +837,24 @@ if ($action) { $raw = curl_exec($ch); curl_close($ch); j(json_decode($raw, true) ?: ['error'=>'failed']); + // Added 2026-07-07: fetch a single outbox item WITH its body — outbox_list + // deliberately omits body for list-view performance, but VIEW needs the full text. + case 'outbox_get': + $id = (int)($_GET['id'] ?? 0); if (!$id) bad('Missing id'); + $ch = curl_init('http://127.0.0.1:7474/comms/sent/' . $id); + curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>5]); + $raw = curl_exec($ch); curl_close($ch); + j(json_decode($raw, true) ?: ['error'=>'failed']); + + // Added 2026-07-07: closes the "compose creates a draft but nothing can ever + // send it" gap — dispatches a queued draft through the real send path. + case 'outbox_send': + $id = (int)($_GET['id'] ?? 0); if (!$id) bad('Missing id'); + $ch = curl_init('http://127.0.0.1:7474/comms/sent/' . $id . '/send'); + curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>30, CURLOPT_POST=>true, CURLOPT_POSTFIELDS=>'']); + $raw = curl_exec($ch); curl_close($ch); + j(json_decode($raw, true) ?: ['error'=>'failed']); + case 'send_reply': $id = (int)($_GET['id'] ?? 0); if (!$id) bad('Missing triage id'); $content = $_GET['content'] ?? ''; @@ -4370,6 +4388,7 @@ async function loadOutbox() { ${m.account||'gmail'} ${ts} + ${sc==='queued' ? `` : ''} @@ -4385,12 +4404,19 @@ async function outboxDelete(id) { else toast('Delete failed: ' + (d.error||''), 'err'); } +// Added 2026-07-07: composing only ever created a queued draft — there was no +// button anywhere to actually send one. This closes that gap. +async function outboxSend(id) { + if (!confirm('Send this draft now?')) return; + const d = await api('outbox_send', {id}); + if (d.success) { toast('Sent', 'ok'); loadOutbox(); } + else toast('Send failed: ' + (d.error||'unknown error'), 'err'); +} + async function outboxViewBody(id) { - const d = await api('outbox_list', {limit: 200}); - const sent = Array.isArray(d) ? d : (d.sent || []); - const m = sent.find(x => x.id == id); - if (!m) return; - openModal('SENT MESSAGE — ' + esc(m.subject||''), ` + const m = await api('outbox_get', {id}); + if (!m || m.error) { toast('Failed to load message', 'err'); return; } + openModal((m.status==='queued'?'DRAFT — ':'SENT MESSAGE — ') + esc(m.subject||''), `
TO: ${esc(m.to_email||'')} · ACCOUNT: ${m.account||'gmail'}
${esc(m.body||'(no body)')}
`, null, null);