mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
Normalize local usernames using PRECIS
This patch implements local username normalization using PRECIS (https://tools.ietf.org/html/rfc7564, https://tools.ietf.org/html/rfc7613) It makes chasquid accept local email and authentication regardless of the case. It covers both userdb and aliases. Note that non-local usernames remain untouched.
This commit is contained in:
31
internal/normalize/normalize.go
Normal file
31
internal/normalize/normalize.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Package normalize contains functions to normalize usernames and addresses.
|
||||
package normalize
|
||||
|
||||
import (
|
||||
"blitiri.com.ar/go/chasquid/internal/envelope"
|
||||
"golang.org/x/text/secure/precis"
|
||||
)
|
||||
|
||||
// User normalices an username using PRECIS.
|
||||
// On error, it will also return the original username to simplify callers.
|
||||
func User(user string) (string, error) {
|
||||
norm, err := precis.UsernameCaseMapped.String(user)
|
||||
if err != nil {
|
||||
return user, err
|
||||
}
|
||||
|
||||
return norm, nil
|
||||
}
|
||||
|
||||
// Name normalices an email address using PRECIS.
|
||||
// On error, it will also return the original address to simplify callers.
|
||||
func Addr(addr string) (string, error) {
|
||||
user, domain := envelope.Split(addr)
|
||||
|
||||
user, err := User(user)
|
||||
if err != nil {
|
||||
return addr, err
|
||||
}
|
||||
|
||||
return user + "@" + domain, nil
|
||||
}
|
||||
Reference in New Issue
Block a user