Documentation ¶
Overview ¶
Package rmime implements rich parsing of e-mail message headers and bodies.
(Compare with net/mail, which implements MIME parsing of headers and minimal parsing of bodies.)
Index ¶
- Variables
- func ReadBody(r io.Reader, header *Header) (interface{}, error)
- func TextPlainReader(r io.Reader, flowed, delsp bool) io.Reader
- type Address
- type DeliveryStatus
- type Field
- type Header
- func (h Header) Charset() string
- func (h Header) Disposition() (string, map[string]string)
- func (h Header) Encoding() string
- func (h Header) InReplyTo() []string
- func (h Header) MajorType() string
- func (h Header) MessageID() string
- func (h Header) MinorType() string
- func (h Header) Params() map[string]string
- func (h Header) Recipients() []*Address
- func (h Header) References() []string
- func (h Header) Sender() *Address
- func (h Header) Subject() string
- func (h Header) Time() time.Time
- func (h Header) Type() string
- func (h Header) WriteTo(w io.Writer) (int64, error)
- type Message
- type Multipart
- type Part
Constants ¶
This section is empty.
Variables ¶
var ErrHeaderSyntax = errors.New("bad syntax in header")
ErrHeaderSyntax is the error indicating bad mail header syntax.
var ErrUnimplemented = errors.New("unimplemented")
ErrUnimplemented is the error indicating an unimplemented feature.
Functions ¶
func ReadBody ¶
ReadBody reads a message body from r after the header has been read and parsed. The type of the result depends on the content-type specified in the header:
message/rfc822: *Message message/delivery-status: *DeliveryStatus multipart/*: *Multipart */*: string
func TextPlainReader ¶
TextPlainReader decodes text/plain body parts using the "flowed" and "delsp" features. Note that Part.Body() already returns a TextPlainReader when Part.Type() is "text/plain". If flowed==false, TextPlainReader simply returns its input, r.
Types ¶
type Address ¶
type Address struct { Name string `json:"name,omitempty"` Address string `json:"address,omitempty"` }
Address is the type of an e-mail address.
type DeliveryStatus ¶
type DeliveryStatus struct { Message *Header `json:"message"` Recipients []*Header `json:"recipients"` }
DeliveryStatus is the type of a parsed message/delivery-status body part. TODO: further parse message/delivery-status bodies (parse out specific fields).
type Field ¶
type Field struct { N string `json:"name"` // Name of the field. V []string `json:"value"` // Values of the field. }
Field is a field in a message or message-part header.
type Header ¶
Header is a message header or message-part header. It consists of a sequence of fields and a default content-type dictated by context: text/plain by default, message/rfc822 for the children of a multipart/digest.
func ReadHeader ¶
ReadHeader reads a message header or message-part header from r, which must be positioned at the start of the header. The defaultType parameter sets the DefaultType field of the resulting Header. Pass "" to get the default defaultType of "text/plain".
func (Header) Charset ¶
Charset returns the character set indicated by h (when h has content-type text/*).
func (Header) Disposition ¶
Disposition parses the Content-Disposition field. The first return value is normally "inline" or "attachment". The second is a map of associated key=value pairs, and may be nil. If there is no Content-Disposition field, this function returns "inline", nil.
func (Header) InReplyTo ¶
InReplyTo returns the list of message-ids in the In-Reply-To field(s). The message ids are parsed as in Header.MessageID.
func (Header) MajorType ¶
MajorType returns the major part of the content type of h in canonical form.
func (Header) MessageID ¶
MessageID returns the parsed contents of the Message-Id field or "" if not found or parseable.
Per RFC2822, "the angle bracket characters are not part of the msg-id; the msg-id is what is contained between the two angle bracket characters."
func (Header) MinorType ¶
MinorType returns the minor part of the content type of h in canonical form.
func (Header) Params ¶
Params parses the key=value pairs in the Content-Type field, if any. The return value may be nil.
func (Header) Recipients ¶
Recipients returns the parsed recipient addresses.
func (Header) References ¶
References returns the list of message-ids in the References field(s). The message ids are parsed as in Header.MessageID.
type Message ¶
type Message Part
Message is a message-part that can serve as a top-level e-mail message.
func ReadMessage ¶
ReadMessage reads a message from r.
type Multipart ¶
Multipart is the body of a multipart/* message. It contains a slice of *Part as its children.
type Part ¶
type Part struct { *Header B interface{} `json:"body"` }
Part is a message part, consisting of a header and a body.
func (*Part) Body ¶
Body produces a reader over the decoded body. Transfer encoding is removed. Text is normalized to utf8 if possible, and CRLFs to LFs, and trailing blank lines are removed. Text/plain formatting per RFC3676 is also done. It is an error to call Body on non-leaf parts (multipart/*, message/*).