1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-01-08 17:51:57 +00:00

Normalize domains

We should ignore the domains' case, and treat them uniformly, specially when it
comes to local domains.

This patch extends the existing normalization (IDNA, keeping domains as
UTF8 internally) to include case conversion and NFC form for
consistency.
This commit is contained in:
Alberto Bertogli
2016-10-09 16:05:25 +01:00
parent ad25706d72
commit 112e492c3a
7 changed files with 102 additions and 41 deletions

View File

@@ -6,8 +6,6 @@ import (
"fmt"
"strings"
"golang.org/x/net/idna"
"blitiri.com.ar/go/chasquid/internal/set"
)
@@ -50,27 +48,3 @@ func AddHeader(data []byte, k, v string) []byte {
header := []byte(fmt.Sprintf("%s: %s\n", k, v))
return append(header, data...)
}
// Take an address with a potentially unicode domain, and convert it to ASCII
// as per IDNA.
// The user part is unchanged.
func IDNAToASCII(addr string) (string, error) {
if addr == "<>" {
return addr, nil
}
user, domain := Split(addr)
domain, err := idna.ToASCII(domain)
return user + "@" + domain, err
}
// Take an address with an ASCII domain, and convert it to Unicode as per
// IDNA.
// The user part is unchanged.
func IDNAToUnicode(addr string) (string, error) {
if addr == "<>" {
return addr, nil
}
user, domain := Split(addr)
domain, err := idna.ToUnicode(domain)
return user + "@" + domain, err
}