<?php
$config_file = 'config_email.json';
$config = json_decode(file_get_contents($config_file), true);
$mailbox = "{" . $config['imap_host'] . ":" . $config['imap_port'] . "/imap/ssl/novalidate-cert}";
$imap_stream = @imap_open($mailbox, $config['email'], $config['senha']);

if (!$imap_stream) {
    die("Erro ao conectar IMAP: " . imap_last_error());
}

$folders = imap_getmailboxes($imap_stream, $mailbox, '*');
if ($folders === false) {
    echo "Não foi possível listar pastas: " . imap_last_error();
} else {
    echo "<pre>Pastas IMAP:\n";
    foreach ($folders as $folder) {
        echo $folder->name . "\n";
    }
    echo "</pre>";
}

imap_close($imap_stream);
?>
