Documentation ¶
Overview ¶
Package address provides utilities for parsing and validation of RFC 2821 addresses.
Index ¶
- Variables
- func CleanDomain(addr string) (string, error)
- func Equal(addr1, addr2 string) bool
- func ForLookup(addr string) (string, error)
- func IsASCII(s string) bool
- func SelectIDNA(ulabel bool, addr string) (string, error)
- func Split(addr string) (mailbox, domain string, err error)
- func ToASCII(addr string) (string, error)
- func ToUnicode(addr string) (string, error)
- func UnquoteMbox(mbox string) (string, error)
- func Valid(addr string) bool
- func ValidDomain(domain string) bool
- func ValidMailboxName(mbox string) bool
Constants ¶
This section is empty.
Variables ¶
var (
ErrUnicodeMailbox = errors.New("address: cannot convert the Unicode local-part to the ACE form")
)
Functions ¶
func CleanDomain ¶
CleanDomain returns the address with the domain part converted into its canonical form.
More specifically, converts the domain part of the address to U-labels, normalizes it to NFC and then case-folds it.
Original value is also returned on the error.
func Equal ¶
Equal reports whether addr1 and addr2 are considered to be case-insensitively equivalent.
The equivalence is defined to be the conjunction of IDN label equivalence for the domain part and canonical equivalence* of the local-part converted to lower case.
* IDN label equivalence is defined by RFC 5890 Section 2.3.2.4. ** Canonical equivalence is defined by UAX #15.
Equivalence for malformed addresses is defined using regular byte-string comparison with case-folding applied.
func ForLookup ¶
ForLookup transforms the local-part of the address into a canonical form usable for map lookups or direct comparisons.
If Equal(addr1, addr2) == true, then ForLookup(addr1) == ForLookup(addr2).
On error, case-folded addr is also returned.
func SelectIDNA ¶
SelectIDNA is a convenience function for conversion of domains in the email addresses to/from the Punycode form.
ulabel=true => ToUnicode is used. ulabel=false => ToASCII is used.
func Split ¶
Split splits a email address (as defined by RFC 5321 as a forward-path token) into local part (mailbox) and domain.
Note that definition of the forward-path token includes the special postmaster address without the domain part. Split will return domain == "" in this case.
Split does almost no sanity checks on the input and is intentionally naive. If this is a concern, ValidMailbox and ValidDomain should be used on the output.
func ToASCII ¶
ToASCII converts the domain part of the email address to the A-label form and fails with ErrUnicodeMailbox if the local-part contains non-ASCII characters.
func UnquoteMbox ¶
UnquoteMbox undoes escaping and quoting of the local-part. That is, for local-part `"test\" @ test"` it will return `test" @test`.
func ValidDomain ¶
ValidDomain checks whether the specified string is a valid DNS domain.
func ValidMailboxName ¶
ValidMailboxName checks whether the specified string is a valid mailbox-name element of e-mail address (left part of it, before at-sign).
Types ¶
This section is empty.