getAll(); $id = $mailboxId; if ($id === null) { $id = isset($mailboxes['default']) ? 'default' : array_key_first($mailboxes); } elseif (str_contains($id, '@')) { $id = null; foreach ($mailboxes as $candidate => $mailbox) { if (strcasecmp($mailbox['mailbox'], $mailboxId) === 0) { $id = $candidate; break; } } } if ($id === null) { throw new \FOSSBilling\InformationException('Mailbox not found'); } $settings = $store->get($id); printf("Checking %s at %s:%d using %s with certificate validation enabled...\n", $settings['mailbox'], $settings['host'], $settings['port'], $settings['encryption'] === 'ssl' ? 'implicit TLS' : 'STARTTLS'); $result = (new \Box\Mod\Mailgateway\ImapConnectionTest())->test($settings, $createFolders); // A read-only check does not change the saved readiness state. if ($createFolders) { $store->recordTest($id, $settings, $result); } echo $result['connected'] ? "IMAP login succeeded.\n" : "IMAP login failed.\n"; if ($result['connected']) { echo 'Native MOVE support: ', $result['move_supported'] === true ? 'available' : 'unavailable or unverified', PHP_EOL; } foreach ($result['folders'] as $folder) { printf("%s — %s\n", $folder['path'], $folder['error'] ?? ($folder['created'] ? 'created' : ($folder['exists'] ? 'found' : 'MISSING'))); } foreach ($result['errors'] as $error) { fwrite(STDERR, $error . PHP_EOL); } echo $createFolders ? "Folder setup finished. " : "Read-only check finished. "; echo "No messages were fetched, marked, moved, deleted, or imported.\n"; exit($result['success'] ? 0 : ($result['connected'] && $result['move_supported'] === true ? 2 : 1)); } catch (\FOSSBilling\InformationException $error) { fwrite(STDERR, $error->getMessage() . PHP_EOL); exit(1); } catch (\Throwable $error) { fwrite(STDERR, 'IMAP check could not complete (' . $error::class . "). Check the module configuration and tables.\n"); exit(1); }