mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
The current default is "procmail" for historical reasons, but the program has been unmaintained for years and its use is not generally advisable. This patch changes the default MDA binary to "maildrop", which is a more modern and reasonable MDA to use. We keep the courier.Procmail name for now, as that's internal, but it may be changed later. Its documentation is updated to note that the name is just for reference but it actually works with almost any binary.
94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
// Package config implements the chasquid configuration.
|
|
package config
|
|
|
|
// Generate the config protobuf.
|
|
//go:generate protoc --go_out=. config.proto
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"blitiri.com.ar/go/chasquid/internal/log"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
// Load the config from the given file.
|
|
func Load(path string) (*Config, error) {
|
|
c := &Config{}
|
|
|
|
buf, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
log.Errorf("Failed to read config at %q", path)
|
|
log.Errorf(" (%v)", err)
|
|
return nil, err
|
|
}
|
|
|
|
err = proto.UnmarshalText(string(buf), c)
|
|
if err != nil {
|
|
log.Errorf("Error parsing config: %v", err)
|
|
return nil, err
|
|
}
|
|
|
|
// Fill in defaults for anything that's missing.
|
|
|
|
if c.Hostname == "" {
|
|
c.Hostname, err = os.Hostname()
|
|
if err != nil {
|
|
log.Errorf("Could not get hostname: %v", err)
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
if c.MaxDataSizeMb == 0 {
|
|
c.MaxDataSizeMb = 50
|
|
}
|
|
|
|
if len(c.SmtpAddress) == 0 {
|
|
c.SmtpAddress = append(c.SmtpAddress, "systemd")
|
|
}
|
|
if len(c.SubmissionAddress) == 0 {
|
|
c.SubmissionAddress = append(c.SubmissionAddress, "systemd")
|
|
}
|
|
|
|
if c.MailDeliveryAgentBin == "" {
|
|
c.MailDeliveryAgentBin = "maildrop"
|
|
}
|
|
if len(c.MailDeliveryAgentArgs) == 0 {
|
|
c.MailDeliveryAgentArgs = append(c.MailDeliveryAgentArgs,
|
|
"-f", "%from%", "-d", "%to_user%")
|
|
}
|
|
|
|
if c.DataDir == "" {
|
|
c.DataDir = "/var/lib/chasquid"
|
|
}
|
|
|
|
if c.SuffixSeparators == "" {
|
|
c.SuffixSeparators = "+"
|
|
}
|
|
|
|
if c.DropCharacters == "" {
|
|
c.DropCharacters = "."
|
|
}
|
|
|
|
if c.MailLogPath == "" {
|
|
c.MailLogPath = "<syslog>"
|
|
}
|
|
|
|
return c, nil
|
|
}
|
|
|
|
func LogConfig(c *Config) {
|
|
log.Infof("Configuration:")
|
|
log.Infof(" Hostname: %q", c.Hostname)
|
|
log.Infof(" Max data size (MB): %d", c.MaxDataSizeMb)
|
|
log.Infof(" SMTP Addresses: %v", c.SmtpAddress)
|
|
log.Infof(" Submission Addresses: %v", c.SubmissionAddress)
|
|
log.Infof(" Monitoring address: %s", c.MonitoringAddress)
|
|
log.Infof(" MDA: %s %v", c.MailDeliveryAgentBin, c.MailDeliveryAgentArgs)
|
|
log.Infof(" Data directory: %s", c.DataDir)
|
|
log.Infof(" Suffix separators: %s", c.SuffixSeparators)
|
|
log.Infof(" Drop characters: %s", c.DropCharacters)
|
|
log.Infof(" Mail log: %s", c.MailLogPath)
|
|
}
|