Overview
Package mail implements parsing of mail messages.
For the most part, this package follows the syntax as specified by RFC 5322 and
extended by RFC 6532. Notable divergences:
Index
Package files
- var ErrHeaderNotPresent = errors.("mail: header not in message")
func ParseAddressList
ParseAddressList parses the given string as a list of addresses.
Example:
const list = "Alice <alice@example.com>, Bob <bob@example.com>, Eve <eve@example.com>"
emails, err := mail.ParseAddressList(list)
if err != nil {
log.Fatal(err)
}
for _, v := range emails {
}
// Output:
// Alice alice@example.com
// Bob bob@example.com
// Eve eve@example.com
func ParseDate
ParseDate parses an RFC 5322 date string.
- type Address struct {
- Name string // Proper name; may be empty.
- Address // user@domain
- }
Address represents a single mail address. An address such as “Barry Gibbs
bg@example.com“ is represented as Address{Name: “Barry Gibbs”, Address:
“”}.
func ParseAddress
Parses a single RFC 5322 address, e.g. “Barry Gibbs bg@example.com“
Example:
log.Fatal(err)
}
fmt.Println(e.Name, e.Address)
// Output:
// Alice alice@example.com
- func (a *Address) String()
String formats the address as a valid RFC 5322 address. If the address’s name
contains non-ASCII characters the name will be rendered according to RFC 2047.
type AddressParser
- type AddressParser struct {
- // WordDecoder optionally specifies a decoder for RFC 2047 encoded-words.
- WordDecoder *mime.
- }
An AddressParser is an RFC 5322 address parser.
func (*AddressParser) Parse
- func (p *AddressParser) Parse(address ) (*Address, )
Parse parses a single RFC 5322 address of the form “Gogh Fir gf@example.com“
or “”.
func (*AddressParser) ParseList
- func (p *AddressParser) ParseList(list ) ([]*Address, )
ParseList parses the given string as a list of comma-separated addresses of the
form “Gogh Fir gf@example.com“ or “”.
type Header
A Header represents the key-value pairs in a mail message header.
AddressList parses the named header field as a list of addresses.
func (Header) Date
Date parses the Date header field.
func (Header) Get
Get gets the first value associated with the given key. It is case insensitive;
CanonicalMIMEHeaderKey is used to canonicalize the provided key. If there are no
values associated with the key, Get returns “”. To access multiple values of a
key, or to use non-canonical keys, access the map directly.
- type Message struct {
- Header
- Body io.
A Message represents a parsed mail message.