# package mail
`import "net/mail"`
mail包实现了邮件的解析。
本包大部分都遵守[RFC 5322](http://tools.ietf.org/html/rfc5322)规定的语法,值得注意的区别是:
```
* 旧格式地址和嵌入远端信息的地址不会被解析
* 组地址不会被解析
* 不支持全部的间隔符(CFWS语法元素),如分属两行的地址
```
## Index
* [Variables](#pkg-variables)
* [type Address](#Address)
* [func ParseAddress(address string) (\*Address, error)](#ParseAddress)
* [func (a \*Address) String() string](#Address.String)
* [func ParseAddressList(list string) ([]\*Address, error)](#ParseAddressList)
* [type Header](#Header)
* [func (h Header) AddressList(key string) ([]\*Address, error)](#Header.AddressList)
* [func (h Header) Date() (time.Time, error)](#Header.Date)
* [func (h Header) Get(key string) string](#Header.Get)
* [type Message](#Message)
* [func ReadMessage(r io.Reader) (msg \*Message, err error)](#ReadMessage)
## Variables
```
var ErrHeaderNotPresent = errors.New("mail: header not in message")
```
## type [Address](https://github.com/golang/go/blob/master/src/net/mail/message.go#L136 "View Source")
```
type Address struct {
Name string // 固有名,可以为空
Address string // user@domain
}
```
Address类型表示一个邮箱地址。
例如地址"Barry Gibbs <bg@example.com>"表示为Address{Name: "Barry Gibbs", Address: "bg@example.com"}
### func [ParseAddress](https://github.com/golang/go/blob/master/src/net/mail/message.go#L142 "View Source")
```
func ParseAddress(address string) (*Address, error)
```
解析单个的[RFC 5322](http://tools.ietf.org/html/rfc5322)地址,例如"Barry Gibbs <bg@example.com>"。
### func (\*Address) [String](https://github.com/golang/go/blob/master/src/net/mail/message.go#L154 "View Source")
```
func (a *Address) String() string
```
将a代表的地址表示为合法的[RFC 5322](http://tools.ietf.org/html/rfc5322)地址字符串。如果Name字段包含非ASCII字符将根据[RFC 2047](http://tools.ietf.org/html/rfc2047)转义。
## func [ParseAddressList](https://github.com/golang/go/blob/master/src/net/mail/message.go#L147 "View Source")
```
func ParseAddressList(list string) ([]*Address, error)
```
函数将list作为一串邮箱地址并解析返回。
## type [Header](https://github.com/golang/go/blob/master/src/net/mail/message.go#L105 "View Source")
```
type Header map[string][]string
```
Header代表邮件头域的多个键值对。
### func (Header) [AddressList](https://github.com/golang/go/blob/master/src/net/mail/message.go#L125 "View Source")
```
func (h Header) AddressList(key string) ([]*Address, error)
```
将键key对应的值(字符串)作为邮箱地址列表解析并返回。
### func (Header) [Date](https://github.com/golang/go/blob/master/src/net/mail/message.go#L116 "View Source")
```
func (h Header) Date() (time.Time, error)
```
解析头域Date项的值并返回。
### func (Header) [Get](https://github.com/golang/go/blob/master/src/net/mail/message.go#L109 "View Source")
```
func (h Header) Get(key string) string
```
返回键key对应的第一个值,如果没有对应值,将返回空字符串。
## type [Message](https://github.com/golang/go/blob/master/src/net/mail/message.go#L44 "View Source")
```
type Message struct {
Header Header
Body io.Reader
}
```
Message代表一个解析后的邮件。
### func [ReadMessage](https://github.com/golang/go/blob/master/src/net/mail/message.go#L52 "View Source")
```
func ReadMessage(r io.Reader) (msg *Message, err error)
```
从r读取一个邮件,会解析邮件头域,消息主体可以从r/msg.Body中读取。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe