feat: service EsyMailService complet pour gestion messagerie

EsyMailService - connexion DBAL directe vers base esymail :

Gestion domaines :
- listDomains() : liste avec count mailboxes par domaine
- getDomain(name) : détails d'un domaine
- createDomain(name, maxMailboxes, defaultQuotaMb) : création
- updateDomain(name, maxMailboxes, defaultQuotaMb, isActive) : mise à jour
- deleteDomain(name) : suppression cascade (mailboxes + alias)
- domainExists(name) : vérification existence

Gestion boîtes mail :
- listMailboxes(?domain) : liste toutes ou par domaine
- getMailbox(email) : détails d'une boîte
- createMailbox(email, password, ?displayName, quotaMb) : création avec
  hash bcrypt BLF-CRYPT, vérification domaine existant
- updateMailbox(email, displayName, quotaMb, isActive) : mise à jour
- changePassword(email, newPassword) : changement mot de passe
- deleteMailbox(email) : suppression
- mailboxExists(email) : vérification existence
- countMailboxes(domain) : nombre de boîtes par domaine

Gestion alias :
- listAliases(?domain) : liste tous ou par domaine
- createAlias(source, destination, domain) : création redirection
- deleteAlias(id) : suppression

Stats :
- getStats() : compteurs domains, mailboxes, aliases, active_mailboxes

Base de données esymail :
- Table domain : name unique, max_mailboxes, default_quota_mb, is_active
- Table mailbox : email unique, password bcrypt, domain FK, display_name,
  quota_mb, is_active, timestamps
- Table alias : source/destination unique, domain FK, is_active
- Domaines dev : siteconseil.fr, esy-web.dev
- Compte test : test@siteconseil.fr / test1234

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-04-03 23:17:01 +02:00
parent 3061600fba
commit fe42f221a6
3 changed files with 416 additions and 4 deletions

View File

@@ -4,11 +4,26 @@ WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'esymail')\gexec
\connect esymail
-- Table des domaines
CREATE TABLE IF NOT EXISTS domain (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
max_mailboxes INTEGER NOT NULL DEFAULT 50,
default_quota_mb INTEGER NOT NULL DEFAULT 5120,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_domain_name ON domain (name);
CREATE INDEX IF NOT EXISTS idx_domain_active ON domain (is_active);
-- Table des boites mail
CREATE TABLE IF NOT EXISTS mailbox (
id SERIAL PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
domain VARCHAR(255) NOT NULL,
domain VARCHAR(255) NOT NULL REFERENCES domain(name) ON DELETE CASCADE,
display_name VARCHAR(255) DEFAULT NULL,
quota_mb INTEGER NOT NULL DEFAULT 5120,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
@@ -19,11 +34,29 @@ CREATE INDEX IF NOT EXISTS idx_mailbox_email ON mailbox (email);
CREATE INDEX IF NOT EXISTS idx_mailbox_domain ON mailbox (domain);
CREATE INDEX IF NOT EXISTS idx_mailbox_active ON mailbox (is_active);
-- Table des alias
CREATE TABLE IF NOT EXISTS alias (
id SERIAL PRIMARY KEY,
source VARCHAR(255) NOT NULL,
destination VARCHAR(255) NOT NULL,
domain VARCHAR(255) NOT NULL REFERENCES domain(name) ON DELETE CASCADE,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
UNIQUE(source, destination)
);
CREATE INDEX IF NOT EXISTS idx_alias_source ON alias (source);
CREATE INDEX IF NOT EXISTS idx_alias_domain ON alias (domain);
-- Domaine de test dev
INSERT INTO domain (name) VALUES ('siteconseil.fr') ON CONFLICT (name) DO NOTHING;
INSERT INTO domain (name) VALUES ('esy-web.dev') ON CONFLICT (name) DO NOTHING;
-- Boite de test dev
INSERT INTO mailbox (email, password, domain)
INSERT INTO mailbox (email, password, domain, display_name)
VALUES (
'test@siteconseil.fr',
-- Password: test1234 (bcrypt via BLF-CRYPT)
'$2y$12$LJ3m4yPnMDCE1xPKm5VwS.YNbKH7JQXZ8VmYD5PJT5dKzJDkPmyG',
'siteconseil.fr'
'siteconseil.fr',
'Compte Test'
) ON CONFLICT (email) DO NOTHING;