fix(mail) : le test de connexion fonctionne même si la config est désactivée + remonte l'erreur IMAP réelle
Le guard enabled dans getClient() bloquait le test de connexion alors que le workflow naturel est configurer → tester → activer. getClient(requireEnabled) permet au nouveau testConnection() de se connecter sans exiger enabled=true. Le controller (ROLE_ADMIN) renvoie désormais le détail de l'erreur pour faciliter le diagnostic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,22 @@ final class ImapMailProvider implements MailProviderInterface
|
||||
private readonly LoggerInterface $logger,
|
||||
) {}
|
||||
|
||||
public function testConnection(): int
|
||||
{
|
||||
$client = $this->getClient(requireEnabled: false);
|
||||
|
||||
try {
|
||||
$folders = $client->getFolders(false);
|
||||
$client->disconnect();
|
||||
|
||||
return count($folders);
|
||||
} catch (Throwable $e) {
|
||||
$this->logger->error('ImapMailProvider::testConnection failed: '.$e->getMessage());
|
||||
|
||||
throw MailProviderException::connectionFailed($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function listFolders(): array
|
||||
{
|
||||
$client = $this->getClient();
|
||||
@@ -269,12 +285,16 @@ final class ImapMailProvider implements MailProviderInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function getClient(): Client
|
||||
private function getClient(bool $requireEnabled = true): Client
|
||||
{
|
||||
$config = $this->configRepository->findSingleton();
|
||||
|
||||
if (null === $config || !$config->isEnabled()) {
|
||||
throw MailProviderException::connectionFailed('Mail configuration is missing or disabled');
|
||||
if (null === $config) {
|
||||
throw MailProviderException::connectionFailed('Mail configuration is missing');
|
||||
}
|
||||
|
||||
if ($requireEnabled && !$config->isEnabled()) {
|
||||
throw MailProviderException::connectionFailed('Mail configuration is disabled');
|
||||
}
|
||||
|
||||
if (null === $config->getEncryptedPassword()) {
|
||||
|
||||
Reference in New Issue
Block a user