1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-28 20:56:03 +00:00

Implement couriers

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.
This commit is contained in:
Alberto Bertogli
2015-11-06 02:03:21 +00:00
parent e5c2676f83
commit 77d547288f
10 changed files with 639 additions and 25 deletions

View File

@@ -0,0 +1,44 @@
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)
}
}