forked from phalaaxx/milter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample_test.go
49 lines (40 loc) · 1.29 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package milter_test
import (
"io/ioutil"
"log"
"github.com/mschneider82/milter"
)
// A Session embetted the SessionHandler Interface
type Session struct {
milter.DefaultSession
}
// Body in this case we just want to show some chars of the mail
// All other Interactions are done by DefaultSession implementation
func (s *Session) Body(m *milter.Modifier) (milter.Response, error) {
b, _ := ioutil.ReadAll(s.Message)
log.Printf("Mail's first 100 chars: %s", string(b[0:100]))
return milter.RespAccept, nil
}
func Example() {
panichandler := func(e error) {
log.Printf("Panic happend: %s\n", e.Error())
}
setsymlist := make(milter.RequestMacros)
setsymlist[milter.SMFIM_CONNECT] = []milter.Macro{milter.MACRO_DAEMON_NAME, milter.Macro("{client_addr}")}
milterfactory := func() (milter.SessionHandler, milter.OptAction, milter.OptProtocol, milter.RequestMacros) {
return &Session{},
milter.OptAllActions, // BitMask for wanted Actions
0, // BitMask for unwanted SMTP Parts; 0 = nothing to opt out
setsymlist // optional: can be nil
}
m := milter.New(milterfactory,
milter.WithTCPListener("127.0.0.1:12349"),
milter.WithLogger(milter.StdOutLogger),
milter.WithPanicHandler(panichandler),
)
err := m.Run()
if err != nil {
log.Fatalf("Error: %s", err.Error())
}
defer m.Close()
}