rmime: github.com/bobg/rmime Index | Files

package rmime

import "github.com/bobg/rmime"

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

Package Files

body.go charset.go doc.go field.go header.go message.go multipart.go part.go plain.go write.go

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.

func ReadBody Uses

func ReadBody(r io.Reader, header *Header) (interface{}, error)

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 Uses

func TextPlainReader(r io.Reader, flowed, delsp bool) io.Reader

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.

type Address Uses

type Address struct {
    Name    string `json:"name,omitempty"`
    Address string `json:"address,omitempty"`
}

Address is the type of an e-mail address.

type DeliveryStatus Uses

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).

func (*DeliveryStatus) WriteTo Uses

func (ds *DeliveryStatus) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type Field Uses

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.

func (Field) Name Uses

func (f Field) Name() string

Name returns the name of a field in canonical form.

func (Field) Value Uses

func (f Field) Value() string

Value returns the values of the field combined with canonical spacing.

func (Field) WriteTo Uses

func (f Field) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface.

type Header struct {
    Fields      []*Field `json:"fields"`
    DefaultType string   `json:"default_type"`
}

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 Uses

func ReadHeader(r io.Reader, defaultType string) (*Header, error)

ReadHeader reads a message header or message-part header from r, which must be positioned at the start of the header.

func (Header) Charset Uses

func (h Header) Charset() string

Charset returns the character set indicated by h (when h has content-type text/*).

func (Header) Disposition Uses

func (h Header) Disposition() (string, map[string]string)

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) Encoding Uses

func (h Header) Encoding() string

Encoding returns the content-transfer-encoding indicated by h.

func (Header) InReplyTo Uses

func (h Header) InReplyTo() []string

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 Uses

func (h Header) MajorType() string

MajorType returns the major part of the content type of h in canonical form.

func (Header) MessageID Uses

func (h Header) MessageID() string

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 Uses

func (h Header) MinorType() string

MinorType returns the minor part of the content type of h in canonical form.

func (Header) Params Uses

func (h Header) Params() map[string]string

Params parses the key=value pairs in the Content-Type field, if any The return value may be nil.

func (Header) Recipients Uses

func (h Header) Recipients() []*Address

Recipients returns the parsed recipient addresses.

func (Header) References Uses

func (h Header) References() []string

References returns the list of message-ids in the References field(s). The message ids are parsed as in Header.MessageID.

func (Header) Sender Uses

func (h Header) Sender() *Address

Sender returns the parsed sender address.

func (Header) Subject Uses

func (h Header) Subject() string

Subject returns the decoded subject text of h.

func (Header) Time Uses

func (h Header) Time() time.Time

Time returns the parsed time of h, or the zero time if absent or unparseable.

func (Header) Type Uses

func (h Header) Type() string

Type returns the content-type indicated by h in canonical form.

func (Header) WriteTo Uses

func (h Header) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface.

type Message Uses

type Message Part

Message is a message-part that can serve as a top-level e-mail message.

func ReadMessage Uses

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

ReadMessage reads a message from r.

func (*Message) WriteTo Uses

func (m *Message) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface.

type Multipart Uses

type Multipart struct {
    Preamble, Postamble string
    Parts               []*Part
}

Multipart is the body of a multipart/* message. It contains a slice of *Part as its children.

type Part Uses

type Part struct {
    *Header
    B   interface{} `json:"body"`
}

Part is a message part, consisting of a header and a body.

func ReadPart Uses

func ReadPart(r io.Reader, header *Header) (*Part, error)

ReadPart reads a message part from r after having read and parsed a header for it.

func (*Part) Body Uses

func (p *Part) Body() (io.Reader, error)

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/*).

func (*Part) WriteTo Uses

func (p *Part) WriteTo(w io.Writer) (int64, error)

WriteTo implements the io.WriterTo interface.

Package rmime imports 16 packages (graph) and is imported by 3 packages. Updated 2020-04-06. Refresh now. Tools for package owners.