mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
This patch introduces the couriers, which the queue uses to deliver mail. We have a local courier (using procmail), a remote courier (uses SMTP), and a router courier that decides which of the two to use based on a list of local domains. There are still a few things pending, but they all have their basic functionality working and tested.
45 lines
746 B
Go
45 lines
746 B
Go
package courier
|
|
|
|
import "testing"
|
|
|
|
// Counter courier, for testing purposes.
|
|
type counter struct {
|
|
c int
|
|
}
|
|
|
|
func (c *counter) Deliver(from string, to string, data []byte) error {
|
|
c.c++
|
|
return nil
|
|
}
|
|
|
|
func TestRouter(t *testing.T) {
|
|
localC := &counter{}
|
|
remoteC := &counter{}
|
|
r := Router{
|
|
Local: localC,
|
|
Remote: remoteC,
|
|
LocalDomains: map[string]bool{
|
|
"local1": true,
|
|
"local2": true,
|
|
},
|
|
}
|
|
|
|
for domain, c := range map[string]int{
|
|
"local1": 1,
|
|
"local2": 2,
|
|
"remote": 9,
|
|
} {
|
|
for i := 0; i < c; i++ {
|
|
r.Deliver("from", "a@"+domain, nil)
|
|
}
|
|
}
|
|
|
|
if localC.c != 3 {
|
|
t.Errorf("local mis-count: expected 3, got %d", localC.c)
|
|
}
|
|
|
|
if remoteC.c != 9 {
|
|
t.Errorf("remote mis-count: expected 9, got %d", remoteC.c)
|
|
}
|
|
}
|