7 "github.com/mjl-/mox/dns"
10// Path is an SMTP forward/reverse path, as used in MAIL FROM and RCPT TO
17func (p Path) IsZero() bool {
18 return p.Localpart == "" && p.IPDomain.IsZero()
21// String returns a string representation with ASCII-only domain name.
22func (p Path) String() string {
23 return p.XString(false)
26// LogString returns both the ASCII-only and optional UTF-8 representation.
27func (p Path) LogString() string {
28 if p.Localpart == "" && p.IPDomain.IsZero() {
32 lp := p.Localpart.String()
33 qlp := strconv.QuoteToASCII(lp)
34 escaped := qlp != `"`+lp+`"`
35 if p.IPDomain.Domain.Unicode != "" || escaped {
39 s += "/" + lp + "@" + p.IPDomain.XString(false)
44// XString is like String, but returns unicode UTF-8 domain names if utf8 is
46func (p Path) XString(utf8 bool) string {
47 if p.Localpart == "" && p.IPDomain.IsZero() {
50 return p.Localpart.String() + "@" + p.IPDomain.XString(utf8)
53// ASCIIExtra returns an ascii-only path if utf8 is true and the ipdomain is a
54// unicode domain. Otherwise returns an empty string.
56// For use in comments in message headers added during SMTP.
57func (p Path) ASCIIExtra(utf8 bool) string {
58 if utf8 && p.IPDomain.Domain.Unicode != "" {
59 return p.XString(false)
64// DSNString returns a string representation as used with DSN with/without
67// If utf8 is false, the domain is represented as US-ASCII (IDNA), and the
68// localpart is encoded with in 7bit according to RFC 6533.
69func (p Path) DSNString(utf8 bool) string {
71 return p.XString(utf8)
73 return p.Localpart.DSNString(utf8) + "@" + p.IPDomain.XString(utf8)
76func (p Path) Equal(o Path) bool {
77 if p.Localpart != o.Localpart {
82 if len(d0.IP) > 0 || len(d1.IP) > 0 {
83 return d0.IP.Equal(d1.IP)
85 return strings.EqualFold(d0.Domain.ASCII, d1.Domain.ASCII)