mirror of https://github.com/writeas/writefreely
A focused writing and publishing space.
https://write.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
997 B
44 lines
997 B
3 years ago
|
/*
|
||
|
* Copyright © 2020-2021 A Bunch Tell LLC.
|
||
|
*
|
||
|
* This file is part of WriteFreely.
|
||
|
*
|
||
|
* WriteFreely is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License, included
|
||
|
* in the LICENSE file in this source code package.
|
||
|
*/
|
||
|
|
||
|
package spam
|
||
|
|
||
|
import (
|
||
|
"github.com/writeas/web-core/id"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
var honeypotField string
|
||
|
|
||
|
func HoneypotFieldName() string {
|
||
|
if honeypotField == "" {
|
||
|
honeypotField = id.Generate62RandomString(39)
|
||
|
}
|
||
|
return honeypotField
|
||
|
}
|
||
|
|
||
|
// CleanEmail takes an email address and strips it down to a unique address that can be blocked.
|
||
|
func CleanEmail(email string) string {
|
||
|
emailParts := strings.Split(strings.ToLower(email), "@")
|
||
|
if len(emailParts) < 2 {
|
||
|
return ""
|
||
|
}
|
||
|
u := emailParts[0]
|
||
|
d := emailParts[1]
|
||
|
// Ignore anything after '+'
|
||
|
plusIdx := strings.IndexRune(u, '+')
|
||
|
if plusIdx > -1 {
|
||
|
u = u[:plusIdx]
|
||
|
}
|
||
|
// Strip dots in email address
|
||
|
u = strings.ReplaceAll(u, ".", "")
|
||
|
return u + "@" + d
|
||
|
}
|