Provide default SMTP pipeline

default-remote-delivery is no-op for now because we don't have
message queue (https://github.com/emersion/maddy/issues/11).
This commit is contained in:
fox.cpp 2019-03-19 20:52:21 +03:00 committed by emersion
parent e7128276db
commit 06a84609bc
3 changed files with 47 additions and 10 deletions

View file

@ -35,4 +35,5 @@ func init() {
} }
module.RegisterInstance(mod) module.RegisterInstance(mod)
module.RegisterInstance(Dummy{instName: "default-remote-delivery"})
} }

View file

@ -63,15 +63,11 @@ func Start(cfg []config.CfgTreeNode) error {
} }
func authProvider(args []string) (module.AuthProvider, error) { func authProvider(args []string) (module.AuthProvider, error) {
var (
authName string
ok bool
)
if len(args) != 1 { if len(args) != 1 {
return nil, errors.New("auth: expected 1 argument") return nil, errors.New("auth: expected 1 argument")
} }
authName = args[0] authName := args[0]
authMod := module.GetInstance(authName) authMod := module.GetInstance(authName)
if authMod == nil { if authMod == nil {
return nil, fmt.Errorf("unknown auth. provider instance: %s", authName) return nil, fmt.Errorf("unknown auth. provider instance: %s", authName)
@ -85,15 +81,11 @@ func authProvider(args []string) (module.AuthProvider, error) {
} }
func storageBackend(args []string) (module.Storage, error) { func storageBackend(args []string) (module.Storage, error) {
var (
authName string
ok bool
)
if len(args) != 1 { if len(args) != 1 {
return nil, errors.New("storage: expected 1 argument") return nil, errors.New("storage: expected 1 argument")
} }
authName = args[0] authName := args[0]
authMod := module.GetInstance(authName) authMod := module.GetInstance(authName)
if authMod == nil { if authMod == nil {
return nil, fmt.Errorf("unknown storage backend instance: %s", authName) return nil, fmt.Errorf("unknown storage backend instance: %s", authName)
@ -105,3 +97,21 @@ func storageBackend(args []string) (module.Storage, error) {
} }
return provider, nil return provider, nil
} }
func deliveryTarget(args []string) (module.DeliveryTarget, error) {
if len(args) != 1 {
return nil, errors.New("delivery: expected 1 argument")
}
modName := args[0]
mod := module.GetInstance(modName)
if mod == nil {
return nil, fmt.Errorf("unknown storage backend instance: %s", modName)
}
target, ok := mod.(module.DeliveryTarget)
if !ok {
return nil, fmt.Errorf("module %s doesn't implements delivery target interface", mod.Name())
}
return target, nil
}

26
smtp.go
View file

@ -142,6 +142,32 @@ func NewSMTPEndpoint(instName string, cfg config.CfgTreeNode) (module.Module, er
} }
} }
if endp.domain == "" {
return nil, fmt.Errorf("hostname is not set")
}
if len(endp.pipeline) == 0 {
log.Printf("smtp %s: using default pipeline configuration")
localDelivery, err := deliveryTarget([]string{"default-local-delivery"})
if err != nil {
localDelivery, err = deliveryTarget([]string{"default"})
if err != nil {
return nil, errors.New("missing default local delivery target, must set custom")
}
}
remoteDelivery, err := deliveryTarget([]string{"default-remote-delivery"})
if err != nil {
return nil, errors.New("missing default remote delivery target, must set custom")
}
endp.pipeline = append(endp.pipeline,
deliveryStep{t: localDelivery, opts: map[string]string{"local-only": ""}},
deliveryStep{t: remoteDelivery, opts: map[string]string{"remote-only": ""}},
)
}
if endp.Auth == nil { if endp.Auth == nil {
endp.Auth, err = authProvider([]string{"default-auth"}) endp.Auth, err = authProvider([]string{"default-auth"})
if err != nil { if err != nil {