feat(mail) : intégration mail OVH IMAP — boîte partagée, lecture, création/lien tâche #5

Merged
matthieu merged 70 commits from feat/mail-integration into develop 2026-05-20 07:45:33 +00:00
3 changed files with 42 additions and 11 deletions
Showing only changes of commit f313e74c9e - Show all commits
@@ -23,21 +23,23 @@ class MailTestConnectionController extends AbstractController
public function __invoke(): JsonResponse
{
try {
$folders = $this->mailProvider->listFolders();
$foldersCount = $this->mailProvider->testConnection();
return $this->json([
'ok' => true,
'foldersCount' => count($folders),
'foldersCount' => $foldersCount,
]);
} catch (MailProviderException) {
} catch (MailProviderException $e) {
return $this->json([
'ok' => false,
'error' => 'Connexion IMAP impossible. Vérifiez la configuration.',
'ok' => false,
'error' => 'Connexion IMAP impossible. Vérifiez la configuration.',
'detail' => $e->getMessage(),
]);
} catch (Throwable) {
} catch (Throwable $e) {
return $this->json([
'ok' => false,
'error' => 'Erreur inattendue lors du test de connexion.',
'ok' => false,
'error' => 'Erreur inattendue lors du test de connexion.',
'detail' => $e->getMessage(),
]);
}
}
+23 -3
View File
@@ -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()) {
+9
View File
@@ -11,6 +11,15 @@ use App\Mail\Exception\MailProviderException;
interface MailProviderInterface
{
/**
* Opens a connection using the stored configuration and returns the number
* of folders found. Used by the admin "test connection" endpoint, so it
* MUST work even when the configuration is not yet enabled.
*
* @throws MailProviderException
*/
public function testConnection(): int;
/**
* Returns the full folder tree of the configured mailbox.
*