Package mail

import "net/mail"
Overview
Index
Examples

Overview ▾

打包邮件实现邮件消息的解析.

在大多数情况下,此软件包遵循RFC 5322指定并由RFC 6532扩展的语法.值得注意的区别:

* Obsolete address formats are not parsed, including addresses with
  embedded route information.
* The full range of spacing (the CFWS syntax element) is not supported,
  such as breaking addresses across lines.
* No unicode normalization is performed.
* The special characters ()[]:;@\, are allowed to appear unquoted in names.

Variables

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

func ParseDate 1.8

func ParseDate(date string) (time.Time, error)

ParseDate解析RFC 5322日期字符串.

type Address

地址代表一个邮件地址. 诸如" Barry Gibbs <bg@example.com>"的地址表示为地址{名称:" Barry Gibbs",地址:" bg@example.com"}.

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

func ParseAddress 1.1

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

ParseAddress解析单个RFC 5322地址,例如" Barry Gibbs <bg@example.com>"

Example

Alice alice@example.com

func ParseAddressList 1.1

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

ParseAddressList将给定的字符串解析为地址列表.

Example

Alice alice@example.com
Bob bob@example.com
Eve eve@example.com

func (*Address) String

func (a *Address) String() string

字符串将地址格式化为有效的RFC 5322地址. 如果地址名称包含非ASCII字符,则将根​​据RFC 2047呈现名称.

type AddressParser 1.5

AddressParser是RFC 5322地址解析器.

type AddressParser struct {
    // WordDecoder optionally specifies a decoder for RFC 2047 encoded-words.
    WordDecoder *mime.WordDecoder
}

func (*AddressParser) Parse 1.5

func (p *AddressParser) Parse(address string) (*Address, error)

Parse解析一个格式为" Gogh Fir <gf@example.com>"或" foo@example.com"的RFC 5322地址.

func (*AddressParser) ParseList 1.5

func (p *AddressParser) ParseList(list string) ([]*Address, error)

ParseList将给定的字符串解析为格式为" Gogh Fir <gf@example.com>"或" foo@example.com"的逗号分隔地址列表.

标头表示邮件标头中的键/值对.

type Header map[string][]string

func (Header) AddressList

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

AddressList将命名的标头字段解析为地址列表.

func (Header) Date

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

日期解析日期标题字段.

func (Header) Get

func (h Header) Get(key string) string

Get获取与给定键关联的第一个值. 不区分大小写; CanonicalMIMEHeaderKey用于规范化所提供的密钥. 如果没有与键关联的值,则Get返回"". 要访问键的多个值或使用非规范键,请直接访问地图.

type Message

消息表示已解析的邮件.

type Message struct {
    Header Header
    Body   io.Reader
}

func ReadMessage

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

ReadMessage从r读取一条消息. 标头被解析,并且邮件的正文将可用于从msg.Body中读取.

Example

Date: Mon, 23 Jun 2015 11:40:36 -0400
From: Gopher <from@example.com>
To: Another Gopher <to@example.com>
Subject: Gophers at Gophercon
Message body

by  ICOPY.SITE