代码拉取完成,页面将自动刷新
package emailscraper
import (
"bytes"
"regexp"
"strconv"
"strings"
"sync"
"github.com/lawzava/go-tld"
)
type emails struct {
emails []string
m sync.Mutex
}
func (s *emails) add(email string) {
if !isValidEmail(email) {
return
}
// check for already existing emails
s.m.Lock()
defer s.m.Unlock()
for _, existingEmail := range s.emails {
if existingEmail == email {
return
}
}
s.emails = append(s.emails, email)
}
// Initialize once.
var (
reg = regexp.MustCompile(`([a-zA-Z0-9._-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z0-9_-]+)`)
obfuscatedSeparators = regexp.MustCompile(`.(AT|at|ETA).`)
)
// Parse any *@*.* string and append to the slice.
func (s *emails) parseEmails(body []byte) {
body = obfuscatedSeparators.ReplaceAll(body, []byte("@"))
res := reg.FindAll(body, -1)
for _, r := range res {
s.add(string(r))
}
}
func (s *emails) parseCloudflareEmail(cloudflareEncodedEmail string) {
decodedEmail := decodeCloudflareEmail(cloudflareEncodedEmail)
email := reg.FindString(decodedEmail)
s.add(email)
}
// nolint:gomnd // hardcoded byte values
func decodeCloudflareEmail(email string) string {
var e bytes.Buffer
r, _ := strconv.ParseInt(email[0:2], 16, 0)
for n := 4; n < len(email)+2; n += 2 {
i, _ := strconv.ParseInt(email[n-2:n], 16, 0)
c := i ^ r
e.WriteRune(rune(c))
}
return e.String()
}
// Check if email looks valid.
func isValidEmail(email string) bool {
if email == "" {
return false
}
split := strings.Split(email, ".")
// nolint:gomnd // allow magic number here
if len(split) < 2 {
return false
}
ending := split[len(split)-1]
// nolint:gomnd // allow magic number here
if len(ending) < 2 {
return false
}
// check if TLD name actually exists and is not some image ending
if !tld.IsValid(ending) {
return false
}
if _, err := strconv.Atoi(ending); err == nil {
return false
}
return true
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。