-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
55 lines (47 loc) · 1.5 KB
/
main.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
50
51
52
53
54
55
package main
/*
This code example implements a simple echo server using the postfix-policy-server framework.
It creates a new policy server that listens for incoming policy requests from postfix on
the default port (10005) and returns a JSON representation of the received PolicySet{} values
to STDOUT
To integrate this test server with your postfix configuration, you simply have to add
"check_policy_service inet:127.0.0.1:10005" to the "smtpd_recipient_restrictions" of
your postfix' main.cf and reload postfix.
Example:
smtpd_recipient_restrictions =
[...]
reject_unauth_destination
check_policy_service inet:127.0.0.1:10005
[...]
*/
import (
"context"
"encoding/json"
"fmt"
"github.com/wneessen/postfix-policy-server"
"log"
)
// Hi is an empty struct to work as the Handler interface
type Hi struct{}
// Handle is the test handler for the test server as required by the Handler interface
func (h Hi) Handle(ps *pps.PolicySet) pps.PostfixResp {
log.Println("received new policy set...")
jps, err := json.Marshal(ps)
if err != nil {
log.Printf("failed to marshal policy set data: %s", err)
return pps.RespWarn
}
fmt.Println(string(jps))
return pps.TextResponseOpt(pps.RespInfo, "this might be a cool mail!")
}
// main starts the server
func main() {
s := pps.New()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
h := Hi{}
log.Println("Starting policy echo server...")
if err := s.Run(ctx, h); err != nil {
log.Fatalf("could not run server: %s", err)
}
}