<?php
/**
 * FreshCloud Mail — test IMAP connection
 * POST /api/email/test-imap
 * Body: { host, port, username, password, ssl? }
 *
 * v0.1.0-test stub. Validates the body shape only.
 * When the engine ships, will open a real IMAP connection.
 */

require_once __DIR__ . '/_bootstrap.php';

$body = json_decode(file_get_contents('php://input') ?: '{}', true) ?: [];
$host = $body['host'] ?? null;
$port = $body['port'] ?? null;
$username = $body['username'] ?? null;
$password = $body['password'] ?? null;

if (!$host || !$username || !$password) {
    freshcloud_mail_error(400, 'missing_field', 'host, port, username, and password are required');
}

freshcloud_mail_json(200, [
    'status' => 'shape_valid',
    'note' => 'v0.1.0-test stub — body shape is valid but no real IMAP connection attempted. Engine not yet wired.',
    'host' => $host,
    'port' => $port,
    'username' => $username,
    'timestamp' => gmdate('c'),
]);
