<?php
header('Content-Type: application/json; charset=UTF-8');

try {
    $host = 'localhost';
    $database = 'C:\Program Files (x86)\Common Files\Aspel\Sistemas Aspel\SAE7.00\Ejemplos\Ejemplos.fdb';
    $username = 'SYSDBA';
    $password = 'masterkey';

    $dsn = "firebird:dbname={$host}:{$database};charset=UTF8";
    $pdo = new PDO($dsn, $username, $password, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]);

    $stmt = $pdo->query("SELECT REMITENTE, ASUNTO, MENSAJE, FECHA_ENVIO FROM CORREO ORDER BY FECHA_ENVIO DESC");
    $correos = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode(['success' => true, 'correos' => $correos]);
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
