Files
crm_ecosplay/docker/dovecot/init-esymail.sql
Serreau Jovann 5c4576ca27 feat: ajout Dovecot avec authentification PostgreSQL (base esymail)
Architecture :
- Base de données esymail sur PostgreSQL existant, table mailbox
  (email, password BLF-CRYPT, domain, quota_mb, is_active, timestamps)
- Dovecot auth via dovecot-sql.conf : passdb + userdb en SQL
- Stockage mails en Maildir /var/mail/vhosts/%d/%n
- UID/GID 1000 (vmail) pour les fichiers mail
- Socket auth Postfix pour SASL (/var/spool/postfix/private/auth)

Fichiers :
- docker/dovecot/Dockerfile : dovecot/dovecot + dovecot-pgsql, user vmail
- docker/dovecot/dovecot.conf : protocols imap/pop3, auth SQL, logging
- docker/dovecot/dovecot-sql.conf : connexion PostgreSQL, queries
  password_query/user_query/iterate_query sur table mailbox
- docker/dovecot/init-esymail.sql : CREATE DATABASE esymail, CREATE TABLE
  mailbox avec index, compte test test@siteconseil.fr/test1234

Docker :
- Service dovecot sans port exposé (interne uniquement)
- Volumes dovecot-mail (Maildir) et dovecot-logs (partagé avec fail2ban)
- Dépend de database (healthcheck)
- init-esymail.sql monté dans /docker-entrypoint-initdb.d/ de PostgreSQL

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 16:44:45 +02:00

30 lines
1.0 KiB
SQL

-- Création de la base esymail si elle n'existe pas
SELECT 'CREATE DATABASE esymail OWNER app'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'esymail')\gexec
\connect esymail
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,
quota_mb INTEGER NOT NULL DEFAULT 5120,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL
);
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);
-- Boite de test dev
INSERT INTO mailbox (email, password, domain)
VALUES (
'test@siteconseil.fr',
-- Password: test1234 (bcrypt via BLF-CRYPT)
'$2y$12$LJ3m4yPnMDCE1xPKm5VwS.YNbKH7JQXZ8VmYD5PJT5dKzJDkPmyG',
'siteconseil.fr'
) ON CONFLICT (email) DO NOTHING;