address

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package address provides utilities for parsing and validation of RFC 2821 addresses.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnicodeMailbox = errors.New("address: cannot convert the Unicode local-part to the ACE form")
)

Functions

func CleanDomain

func CleanDomain(addr string) (string, error)

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

func Equal(addr1, addr2 string) bool

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

func ForLookup(addr string) (string, error)

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 IsASCII

func IsASCII(s string) bool

func SelectIDNA

func SelectIDNA(ulabel bool, addr string) (string, error)

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

func Split(addr string) (mailbox, domain string, err error)

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

func ToASCII(addr string) (string, error)

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 ToUnicode

func ToUnicode(addr string) (string, error)

ToUnicode converts the domain part of the email address to the U-label form.

func UnquoteMbox

func UnquoteMbox(mbox string) (string, error)

UnquoteMbox undoes escaping and quoting of the local-part. That is, for local-part `"test\" @ test"` it will return `test" @test`.

func Valid

func Valid(addr string) bool

Valid checks whether ths string is valid as a email address as defined by RFC 5321.

func ValidDomain

func ValidDomain(domain string) bool

ValidDomain checks whether the specified string is a valid DNS domain.

func ValidMailboxName

func ValidMailboxName(mbox string) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL