2 || (isset($argv[1]) && $argv[1] !== '--force')) { fwrite(STDERR, "Usage: php tools/poll.php [--force]\n"); exit(1); } require dirname(__DIR__, 3) . '/load.php'; try { $result = $di['mod_service']('mailgateway')->poll(($argv[1] ?? '') === '--force'); echo json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR), PHP_EOL; $failed = array_filter($result['mailboxes'], fn ($mailbox) => $mailbox['status'] !== 'completed' || $mailbox['failed'] > 0 || $mailbox['retry_pending'] > 0 || $mailbox['move_pending'] > 0); exit($failed === [] ? 0 : 2); } catch (Throwable) { fwrite(STDERR, "Mail Gateway polling failed. Check the module tables, configuration, and cron logs.\n"); exit(1); }