config

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(cfg LoggerConfig) (*zap.Logger, error)

NewLogger creates a structured logger based on configuration

Types

type ACMEConfig

type ACMEConfig struct {
	Enabled  bool   `yaml:"enabled" env:"ACME_ENABLED" default:"false"`
	Email    string `yaml:"email" env:"ACME_EMAIL"`
	Provider string `yaml:"provider" env:"ACME_PROVIDER" default:"cloudflare"`
	APIToken string `yaml:"api_token" env:"CLOUDFLARE_API_TOKEN"`
	CacheDir string `yaml:"cache_dir" env:"ACME_CACHE_DIR" default:"./data/acme"`
}

ACMEConfig holds Let's Encrypt ACME configuration

type APIConfig

type APIConfig struct {
	Port           int      `mapstructure:"port" yaml:"port" env:"API_PORT" default:"8980"`
	ReadTimeout    int      `mapstructure:"read_timeout" yaml:"read_timeout" env:"API_READ_TIMEOUT" default:"15"`
	WriteTimeout   int      `mapstructure:"write_timeout" yaml:"write_timeout" env:"API_WRITE_TIMEOUT" default:"15"`
	MaxHeaderBytes int      `mapstructure:"max_header_bytes" yaml:"max_header_bytes" env:"API_MAX_HEADER_BYTES" default:"1048576"` // 1MB
	AdminToken     string   `mapstructure:"admin_token" yaml:"admin_token" env:"API_ADMIN_TOKEN"`                                  // Bearer token for admin endpoints (deprecated, use JWT)
	JWTSecret      string   `mapstructure:"jwt_secret" yaml:"jwt_secret" env:"API_JWT_SECRET"`                                     // Secret for signing JWT tokens
	CORSOrigins    []string `mapstructure:"cors_origins" yaml:"cors_origins" env:"API_CORS_ORIGINS"`                               // Allowed CORS origins
}

APIConfig holds admin API server configuration

type ClamAVConfig

type ClamAVConfig struct {
	SocketPath string `mapstructure:"socket_path" yaml:"socket_path" env:"CLAMAV_SOCKET_PATH" default:"/var/run/clamav/clamd.ctl"`
	Timeout    int    `mapstructure:"timeout" yaml:"timeout" env:"CLAMAV_TIMEOUT" default:"60"`
}

ClamAVConfig holds ClamAV connection configuration All scanning policies and actions are stored in SQLite per-domain

type Config

type Config struct {
	Server   ServerConfig   `mapstructure:"server" yaml:"server"`
	Database DatabaseConfig `mapstructure:"database" yaml:"database"`
	Logger   LoggerConfig   `mapstructure:"logger" yaml:"logger"`
	TLS      TLSConfig      `mapstructure:"tls" yaml:"tls"`
	SMTP     SMTPConfig     `mapstructure:"smtp" yaml:"smtp"`
	IMAP     IMAPConfig     `mapstructure:"imap" yaml:"imap"`
	API      APIConfig      `mapstructure:"api" yaml:"api"`
	WebUI    WebUIConfig    `mapstructure:"webui" yaml:"webui"`
	WebDAV   WebDAVConfig   `mapstructure:"webdav" yaml:"webdav"`
	Security SecurityConfig `mapstructure:"security" yaml:"security"`
}

Config holds the entire application configuration

func Load

func Load(configPath string) (*Config, error)

Load loads configuration from file and environment variables

func (*Config) ValidateSecurityConfig

func (c *Config) ValidateSecurityConfig() error

ValidateSecurityConfig validates external security service connection settings All security policies are validated at the domain level in the database

type DNSConfig

type DNSConfig struct {
	Resolver        string   `mapstructure:"resolver" yaml:"resolver" env:"DNS_RESOLVER" default:"1.1.1.1:53"`
	FallbackServers []string `mapstructure:"fallback_servers" yaml:"fallback_servers" env:"DNS_FALLBACK_SERVERS"`
	Timeout         int      `mapstructure:"timeout" yaml:"timeout" env:"DNS_TIMEOUT" default:"5"`
	UseTCP          bool     `mapstructure:"use_tcp" yaml:"use_tcp" env:"DNS_USE_TCP" default:"false"`
}

DNSConfig holds DNS resolver configuration for DANE, MTA-STS, and other DNS lookups

type DatabaseConfig

type DatabaseConfig struct {
	Driver   string         `mapstructure:"driver" yaml:"driver" env:"DB_DRIVER" default:"sqlite3"`
	SQLite   SQLiteConfig   `mapstructure:"sqlite" yaml:"sqlite"`
	Postgres PostgresConfig `mapstructure:"postgres" yaml:"postgres"`
}

DatabaseConfig holds database configuration

type IMAPConfig

type IMAPConfig struct {
	Port        int `mapstructure:"port" yaml:"port" env:"IMAP_PORT" default:"143"`
	IMAPSPort   int `mapstructure:"imaps_port" yaml:"imaps_port" env:"IMAPS_PORT" default:"993"`
	IdleTimeout int `mapstructure:"idle_timeout" yaml:"idle_timeout" env:"IMAP_IDLE_TIMEOUT" default:"1800"` // 30 minutes
}

IMAPConfig holds IMAP server configuration

type LoggerConfig

type LoggerConfig struct {
	Level      string `yaml:"level" env:"LOG_LEVEL" default:"info"`
	Format     string `yaml:"format" env:"LOG_FORMAT" default:"json"`
	OutputPath string `yaml:"output_path" env:"LOG_OUTPUT_PATH" default:"stdout"`
}

LoggerConfig holds logging configuration

type PostgresConfig

type PostgresConfig struct {
	Host            string `mapstructure:"host" yaml:"host" env:"DB_POSTGRES_HOST" default:"localhost"`
	Port            int    `mapstructure:"port" yaml:"port" env:"DB_POSTGRES_PORT" default:"5432"`
	Database        string `mapstructure:"database" yaml:"database" env:"DB_POSTGRES_DATABASE" default:"gomailserver"`
	User            string `mapstructure:"user" yaml:"user" env:"DB_POSTGRES_USER" default:"gomailserver"`
	Password        string `mapstructure:"password" yaml:"password" env:"DB_POSTGRES_PASSWORD"`
	SSLMode         string `mapstructure:"ssl_mode" yaml:"ssl_mode" env:"DB_POSTGRES_SSL_MODE" default:"disable"`
	MaxOpenConns    int    `mapstructure:"max_open_conns" yaml:"max_open_conns" env:"DB_POSTGRES_MAX_OPEN_CONNS" default:"25"`
	MaxIdleConns    int    `mapstructure:"max_idle_conns" yaml:"max_idle_conns" env:"DB_POSTGRES_MAX_IDLE_CONNS" default:"5"`
	ConnMaxLifetime string `mapstructure:"conn_max_lifetime" yaml:"conn_max_lifetime" env:"DB_POSTGRES_CONN_MAX_LIFETIME" default:"1h"`
	ConnMaxIdleTime string `mapstructure:"conn_max_idle_time" yaml:"conn_max_idle_time" env:"DB_POSTGRES_CONN_MAX_IDLE_TIME" default:"30m"`
}

PostgresConfig holds PostgreSQL-specific configuration

type SMTPConfig

type SMTPConfig struct {
	SubmissionPort int    `mapstructure:"submission_port" yaml:"submission_port" env:"SMTP_SUBMISSION_PORT" default:"587"`
	RelayPort      int    `mapstructure:"relay_port" yaml:"relay_port" env:"SMTP_RELAY_PORT" default:"25"`
	SMTPSPort      int    `mapstructure:"smtps_port" yaml:"smtps_port" env:"SMTPS_PORT" default:"465"`
	MaxMessageSize int64  `mapstructure:"max_message_size" yaml:"max_message_size" env:"SMTP_MAX_MESSAGE_SIZE" default:"52428800"` // 50MB
	Hostname       string `mapstructure:"hostname" yaml:"hostname" env:"SMTP_HOSTNAME"`
}

SMTPConfig holds SMTP server configuration

type SQLiteConfig

type SQLiteConfig struct {
	Path       string `mapstructure:"path" yaml:"path" env:"DB_SQLITE_PATH" default:"./data/mailserver.db"`
	WALEnabled bool   `mapstructure:"wal_enabled" yaml:"wal_enabled" env:"DB_SQLITE_WAL_ENABLED" default:"true"`
}

SQLiteConfig holds SQLite-specific configuration

type SecurityConfig

type SecurityConfig struct {
	ClamAV       ClamAVConfig       `mapstructure:"clamav" yaml:"clamav"`
	SpamAssassin SpamAssassinConfig `mapstructure:"spamassassin" yaml:"spamassassin"`
	DNS          DNSConfig          `mapstructure:"dns" yaml:"dns"`
}

SecurityConfig holds external security service connection configuration All security policies and settings are stored in SQLite per-domain

type ServerConfig

type ServerConfig struct {
	Hostname string `mapstructure:"hostname" yaml:"hostname" env:"SERVER_HOSTNAME"`
	Domain   string `mapstructure:"domain" yaml:"domain" env:"SERVER_DOMAIN"`
}

ServerConfig holds general server configuration

type SpamAssassinConfig

type SpamAssassinConfig struct {
	Host    string `mapstructure:"host" yaml:"host" env:"SPAMASSASSIN_HOST" default:"localhost"`
	Port    int    `mapstructure:"port" yaml:"port" env:"SPAMASSASSIN_PORT" default:"783"`
	Timeout int    `mapstructure:"timeout" yaml:"timeout" env:"SPAMASSASSIN_TIMEOUT" default:"30"`
}

SpamAssassinConfig holds SpamAssassin connection configuration All spam scoring policies and thresholds are stored in SQLite per-domain/user

type TLSConfig

type TLSConfig struct {
	CertFile string     `yaml:"cert_file" env:"TLS_CERT_FILE"`
	KeyFile  string     `yaml:"key_file" env:"TLS_KEY_FILE"`
	ACME     ACMEConfig `yaml:"acme"`
}

TLSConfig holds TLS/certificate configuration

type WebDAVConfig

type WebDAVConfig struct {
	Enabled      bool `mapstructure:"enabled" yaml:"enabled" env:"WEBDAV_ENABLED" default:"true"`
	Port         int  `mapstructure:"port" yaml:"port" env:"WEBDAV_PORT" default:"8800"`
	ReadTimeout  int  `mapstructure:"read_timeout" yaml:"read_timeout" env:"WEBDAV_READ_TIMEOUT" default:"30"`
	WriteTimeout int  `mapstructure:"write_timeout" yaml:"write_timeout" env:"WEBDAV_WRITE_TIMEOUT" default:"30"`
}

WebDAVConfig holds WebDAV/CalDAV/CardDAV server configuration

type WebUIConfig

type WebUIConfig struct {
	Enabled  bool `mapstructure:"enabled" yaml:"enabled" env:"WEBUI_ENABLED" default:"true"`
	Port     int  `mapstructure:"port" yaml:"port" env:"WEBUI_PORT" default:"8080"`
	VitePort int  `mapstructure:"vite_port" yaml:"vite_port" env:"WEBUI_VITE_PORT" default:"5173"` // Dev mode Vite server port
}

WebUIConfig holds Web UI (admin and webmail) server configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL