-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspfcheck.go
41 lines (33 loc) · 886 Bytes
/
spfcheck.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
package main
import "fmt"
import "net"
import "blitiri.com.ar/go/spf"
import "os"
import "strings"
import "time"
func main() {
if env_defined("RELAYCLIENT") ||
env_defined("TRUSTCLIENT") ||
!env_defined("TCPREMOTEIP") {
fmt.Println()
os.Exit(0)
}
var smtpmailfrom string = os.Getenv("SMTPMAILFROM")
var addrparts []string = strings.Split(smtpmailfrom, "@")
ip := net.ParseIP(os.Getenv("TCPREMOTEIP"))
r, _ := spf.CheckHost(ip, addrparts[1])
if (r == "fail") {
fmt.Fprintf(os.Stderr, "%d SPF check failed for %s\n", os.Getppid(), smtpmailfrom)
fmt.Fprintf(os.Stderr, "%d Mail recipient would have been %s\n", os.Getppid(), os.Getenv("SMTPRCPTTO"))
time.Sleep(5 * time.Second)
fmt.Println("E451 SPF check failed")
} else {
fmt.Println()
}
os.Exit(0)
}
func env_defined(key string) bool {
value, exists := os.LookupEnv(key)
_ = value
return exists
}