-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisposable.go
50 lines (43 loc) · 1.77 KB
/
disposable.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
//go:generate go run ./cmd/parser/ -pkg=disposable -var=disposable -out=disposable_list.go -url=https://raw.githubusercontent.com/ivolo/disposable-email-domains/master/index.json
//go:generate go run ./cmd/parser/ -pkg=disposable -var=wildcards -out=disposable_list_wildcard.go -url=https://raw.githubusercontent.com/ivolo/disposable-email-domains/master/wildcard.json
// Package disposable can be used to detect if a domain or email address is
// potentially fake or temporary based on it being registered using a
// disposable email provider (identified by the domain name).
package disposable
import "strings"
var mapping map[string]struct{}
func init() {
mapping = make(map[string]struct{}, len(disposable))
for _, domain := range disposable {
mapping[domain] = struct{}{}
}
}
// IsDomainDisposable determines if a specified domain is disposable based
// on an exact match check against a list of domains known for creating
// diposable email addresses.
func IsDomainDisposable(domain string) bool {
_, found := mapping[domain]
return found
}
// IsDomainWildcard determines if a specified domain is disposable based on if
// it is a subdomain of a known wildcard domain used to create disposable
// email addresses.
func IsDomainWildcard(domain string) bool {
for _, wildcard := range wildcards {
if strings.HasSuffix(domain, wildcard) {
return true
}
}
return false
}
// IsEmailAddressDisposable parses a valid email address and checks the domain
// part against known disposable domains. If an invalid email is passed,
// correct behavior can not be guaranteed.
func IsEmailAddressDisposable(email string) bool {
parts := strings.SplitN(email, "@", 2)
if len(parts) != 2 {
return false
}
domain := parts[1]
return IsDomainDisposable(domain) || IsDomainWildcard(domain)
}