Version: v0.0.0-...-1d03baa Latest Latest

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

Go to latest
Published: Jan 21, 2013 License: BSD-3-Clause Imports: 12 Imported by: 0



Package mail implements parsing of mail messages.

For the most part, this package follows the syntax as specified by RFC 5322. Notable divergences:

  • Obsolete address formats are not parsed, including addresses with embedded route information.
  • Group addresses are not parsed.
  • The full range of spacing (the CFWS syntax element) is not supported, such as breaking addresses across lines.



This section is empty.


View Source
var ErrHeaderNotPresent = errors.New("mail: header not in message")


This section is empty.


type Address

type Address struct {
	Name    string // Proper name; may be empty.
	Address string // user@domain

Address represents a single mail address. An address such as "Barry Gibbs <>" is represented as Address{Name: "Barry Gibbs", Address: ""}.

func ParseAddress

func ParseAddress(address string) (*Address, error)

Parses a single RFC 5322 address, e.g. "Barry Gibbs <>"

func ParseAddressList

func ParseAddressList(list string) ([]*Address, error)

ParseAddressList parses the given string as a list of addresses.

func (*Address) String

func (a *Address) String() 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 Header map[string][]string

A Header represents the key-value pairs in a mail message header.

func (Header) AddressList

func (h Header) AddressList(key string) ([]*Address, error)

AddressList parses the named header field as a list of addresses.

func (Header) Date

func (h Header) Date() (time.Time, error)

Date parses the Date header field.

func (Header) Get

func (h Header) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "".

type Message

type Message struct {
	Header Header
	Body   io.Reader

A Message represents a parsed mail message.

func ReadMessage

func ReadMessage(r io.Reader) (msg *Message, err error)

ReadMessage reads a message from r. The headers are parsed, and the body of the message will be available for reading from r.

Source Files

Jump to

Keyboard shortcuts

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