<?php
$data = json_decode(file_get_contents('php://input'), true);
$index = $data['index'] ?? null;

if ($index !== null) {
    $inboxFile = 'inbox/all_emails.json';
    if (file_exists($inboxFile)) {
        $emails = json_decode(file_get_contents($inboxFile), true);
        if (isset($emails[$index])) {
            $emails[$index]['read'] = true;
            file_put_contents($inboxFile, json_encode($emails, JSON_PRETTY_PRINT));
        }
    }
}
echo json_encode(['success' => true]);
?>