version: '3.8'
services:
  mailserver:
    image: ghcr.io/docker-mailserver/docker-mailserver:latest
    container_name: dms-mailserver
    hostname: mail.andreasknuth.de
    env_file: mailserver.env
    ports:
      - "2525:25"    # SMTP
      - "1443:143"   # IMAP
      - "1465:465"   # SMTPS (deine Änderung)
      - "1993:993"   # IMAPS (deine Änderung)
      - "2587:587"   # Submission
    volumes:
      - ./data/:/var/mail/
      - ./state/:/var/mail-state/
      - ./config/:/tmp/docker-mailserver/
    environment:
      - ENABLE_FAIL2BAN=1
      - SSL_TYPE=self-signed  # Geändert: Self-signed für Test, da Caddy TLS handhabt
      - PERMIT_DOCKER=host
      - ONE_DIR=1
    cap_add:
      - NET_ADMIN
    restart: always
    networks:
      - dms_network
      - mail_network  # Dein bestehendes für Caddy

  roundcube:
    image: roundcube/roundcubemail:latest
    container_name: dms-roundcube
    environment:
      - ROUNDCUBEMAIL_DEFAULT_HOST=mail.andreasknuth.de
      - ROUNDCUBEMAIL_DEFAULT_PORT=1443  # Dein IMAP-Port
      - ROUNDCUBEMAIL_SMTP_SERVER=mail.andreasknuth.de
      - ROUNDCUBEMAIL_SMTP_PORT=2587
      - ROUNDCUBEMAIL_PLUGINS=archive,zipdownload,managesieve,password  # Für Features
      - ROUNDCUBEMAIL_DB_TYPE=sqlite  # Neu: SQLite für DB, vermeidet Connection-Fehler
      - ROUNDCUBEMAIL_DB_DSNW=sqlite:////var/roundcube/db/sqlite.db?mode=0646  # SQLite-Pfad
    volumes:
      - ./roundcube/db/:/var/roundcube/db/  # Persistenz für SQLite-DB
      - ./roundcube/config/:/var/roundcube/config/  # Custom Config
    ports:
      - "9000:80"  # Intern
    depends_on:
      - mailserver
    restart: always
    networks:
      - dms_network
      - mail_network

networks:
  dms_network:
    external: true
  mail_network:
    external: true