diff --git a/public_html/admin/index.php b/public_html/admin/index.php index b340fb6..332964f 100644 --- a/public_html/admin/index.php +++ b/public_html/admin/index.php @@ -324,16 +324,35 @@ if ($action) { // ── USERS ──────────────────────────────────────────────────────────── case 'email_inbox': - // Call via server's own IP — REMOTE_ADDR matches JARVIS_IP so auth bypass applies - $acct = $_GET['account'] ?? 'all'; - $force = !empty($_GET['force']) ? '&force=1' : ''; - $ch = curl_init('https://165.22.1.228/api/email?account=' . $acct . $force); - curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>true,CURLOPT_TIMEOUT=>25, - CURLOPT_SSL_VERIFYPEER=>false,CURLOPT_SSL_VERIFYHOST=>false, - CURLOPT_HTTPHEADER=>['Host: jarvis.orbishosting.com']]); - $r = curl_exec($ch); $code = curl_getinfo($ch,CURLINFO_HTTP_CODE); curl_close($ch); - if($code===200 && $r) j(json_decode($r,true)); - else j(['error'=>'Email fetch failed (HTTP '.$code.')']); + // Fixed 2026-07-07: this used to proxy to the OLD DO-hosted JARVIS + // (165.22.1.228/api/email with a spoofed Host header) — a leftover from + // before JARVIS moved to this VM (211). That endpoint no longer exists + // (404), so the inbox always failed. Reads the local email_triage table + // directly now, same source gmail_triage jobs already write to, matching + // the pattern email_action_items already used. + $acct = $_GET['account'] ?? 'all'; + $where = '1=1'; $params = []; + if ($acct && $acct !== 'all') { $where .= ' AND account=?'; $params[] = $acct; } + $rows = JarvisDB::query( + "SELECT account, from_name, from_email, subject, date_received, summary, category + FROM email_triage WHERE {$where} ORDER BY date_received DESC LIMIT 100", + $params + ) ?? []; + $recent = array_map(function($r) { + return [ + 'account' => $r['account'], + 'from_name' => $r['from_name'], + 'from_email'=> $r['from_email'], + 'subject' => $r['subject'], + 'date' => $r['date_received'], + 'preview' => $r['summary'], + 'unread' => false, + ]; + }, $rows); + $actionCount = JarvisDB::single( + "SELECT COUNT(*) AS c FROM email_actions WHERE dismissed=0 AND task_id IS NULL AND appointment_id IS NULL" + ); + j(['summary' => ['recent' => $recent], 'action_items_count' => (int)($actionCount['c'] ?? 0)]); case 'email_action_items': $rows = JarvisDB::query("SELECT * FROM email_actions WHERE dismissed=0 AND task_id IS NULL AND appointment_id IS NULL ORDER BY received_at DESC LIMIT 100") ?? [];