forked from willwhite/freemail
-
Notifications
You must be signed in to change notification settings - Fork 2
/
freemail.go
39 lines (33 loc) · 863 Bytes
/
freemail.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
package freemail
import (
"strings"
)
//go:generate go run gen.go
//go:generate go fmt .
// IsFree returns true if the email domain is a known free email provider.
func IsFree(domain string) bool {
return find(domain, free)
}
// IsDisposable returns true if the email domain is known to be a disposable
// email provider.
func IsDisposable(domain string) bool {
return find(domain, disposable)
}
// IsSpammy returns true if the email domain is known to be a source of spammy
// and abusive behavior, per Stop Forum Spam.
func IsSpammy(domain string) bool {
return find(domain, spammy)
}
func find(domain string, domains map[string]bool) bool {
if domains[domain] {
return true
}
parts := strings.Split(domain, ".")
for i := 0; i < len(parts); i++ {
test := strings.Join(parts[i:], ".")
if domains[test] {
return true
}
}
return false
}