mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-07 17:47:14 +00:00
This patch introduces an "envelope" package which, for now, provides simple utilities for getting the user and domain of an address. It also changes the couriers to use it (but other implementations remain, will be moved over in subsequent patches).
29 lines
761 B
Go
29 lines
761 B
Go
// Package courier implements various couriers for delivering messages.
|
|
package courier
|
|
|
|
import "blitiri.com.ar/go/chasquid/internal/envelope"
|
|
|
|
// Courier delivers mail to a single recipient.
|
|
// It is implemented by different couriers, for both local and remote
|
|
// recipients.
|
|
type Courier interface {
|
|
Deliver(from string, to string, data []byte) error
|
|
}
|
|
|
|
// Router decides if the destination is local or remote, and delivers
|
|
// accordingly.
|
|
type Router struct {
|
|
Local Courier
|
|
Remote Courier
|
|
LocalDomains map[string]bool
|
|
}
|
|
|
|
func (r *Router) Deliver(from string, to string, data []byte) error {
|
|
d := envelope.DomainOf(to)
|
|
if r.LocalDomains[d] {
|
|
return r.Local.Deliver(from, to, data)
|
|
} else {
|
|
return r.Remote.Deliver(from, to, data)
|
|
}
|
|
}
|