mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-19 14:57:04 +00:00
Implement basic IDNA support
This patch implements the first steps of support for IDNA (Internationalized Domain Names for Applications). Internally, we maintain the byte-agnostic representation, including configuration. We support receiving IDNA mail over SMTP, which we convert to unicode for internal handling. Local deliveries are still kept agnostic. For sending over SMTP, we use IDNA for DNS resolution, but there are some corner cases pending in the SMTP courier that are tied with SMTPUTF8 and will be fixed in subsequent patches.
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/idna"
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/set"
|
||||
)
|
||||
|
||||
@@ -48,3 +50,27 @@ 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user