<?php
// ultimate/check_data.php
header('Content-Type: text/html');

echo "<h2>Debug Inbox Data</h2>";

$inboxFile = __DIR__ . '/inbox/emails.json';
echo "<p>File path: " . $inboxFile . "</p>";
echo "<p>File exists: " . (file_exists($inboxFile) ? 'Yes' : 'No') . "</p>";

if (file_exists($inboxFile)) {
    echo "<p>File size: " . filesize($inboxFile) . " bytes</p>";
    echo "<h3>Raw Content:</h3>";
    echo "<pre>";
    $content = file_get_contents($inboxFile);
    echo htmlspecialchars($content);
    echo "</pre>";
    
    echo "<h3>Parsed JSON:</h3>";
    $data = json_decode($content, true);
    echo "<pre>";
    print_r($data);
    echo "</pre>";
    
    echo "<h3>Valid Emails (subject not null):</h3>";
    $valid = array_filter($data, function($item) {
        return isset($item['subject']) && $item['subject'] !== null;
    });
    echo "<pre>";
    print_r($valid);
    echo "</pre>";
}
?>