📄 Source: mark_read.php
<?php
session_start();
require_once 'database.php';
header('Content-Type: application/json');
if (!isset($_SESSION['access_token'])) {
echo json_encode(['error' => 'Not authenticated']);
exit();
}
$input = json_decode(file_get_contents('php://input'), true);
$emailId = $input['email_id'] ?? '';
if ($emailId) {
$db = new InboxDatabase();
$db->markAsRead($emailId);
// Also mark as read in Gmail
try {
$client = new Google\Client();
$client->setAccessToken($_SESSION['access_token']);
$service = new Google\Service\Gmail($client);
$service->users_messages->modify('me', $emailId, new Google\Service\Gmail\ModifyMessageRequest([
'removeLabelIds' => ['UNREAD']
]));
} catch (Exception $e) {
// Ignore Gmail errors
}
echo json_encode(['success' => true]);
} else {
echo json_encode(['error' => 'No email ID provided']);
}
?>
← Back