diff --git a/defaultsqlmail.go b/default.go similarity index 90% rename from defaultsqlmail.go rename to default.go index 79869d2..68fa389 100644 --- a/defaultsqlmail.go +++ b/default.go @@ -35,4 +35,5 @@ func init() { } module.RegisterInstance(mod) + module.RegisterInstance(Dummy{instName: "default-remote-delivery"}) } diff --git a/maddy.go b/maddy.go index 2cd0978..d8540fd 100644 --- a/maddy.go +++ b/maddy.go @@ -63,15 +63,11 @@ func Start(cfg []config.CfgTreeNode) error { } func authProvider(args []string) (module.AuthProvider, error) { - var ( - authName string - ok bool - ) if len(args) != 1 { return nil, errors.New("auth: expected 1 argument") } - authName = args[0] + authName := args[0] authMod := module.GetInstance(authName) if authMod == nil { 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) { - var ( - authName string - ok bool - ) if len(args) != 1 { return nil, errors.New("storage: expected 1 argument") } - authName = args[0] + authName := args[0] authMod := module.GetInstance(authName) if authMod == nil { return nil, fmt.Errorf("unknown storage backend instance: %s", authName) @@ -105,3 +97,21 @@ func storageBackend(args []string) (module.Storage, error) { } 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 +} diff --git a/smtp.go b/smtp.go index c3cee3f..6eb4549 100644 --- a/smtp.go +++ b/smtp.go @@ -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 { endp.Auth, err = authProvider([]string{"default-auth"}) if err != nil {