rmime

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 16 Imported by: 2

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

Constants

This section is empty.

Variables

View Source
var ErrHeaderSyntax = errors.New("bad syntax in header")

ErrHeaderSyntax is the error indicating bad mail header syntax.

View Source
var ErrUnimplemented = errors.New("unimplemented")

ErrUnimplemented is the error indicating an unimplemented feature.

Functions

func ReadBody

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

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.

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

func (*DeliveryStatus) WriteTo

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

WriteTo implements io.WriterTo.

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.

func (Field) Name

func (f Field) Name() string

Name returns the name of a field in canonical form.

func (Field) Value

func (f Field) Value() string

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

func (Field) WriteTo

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

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. The defaultType parameter sets the DefaultType field of the resulting Header. Pass "" to get the default defaultType of "text/plain".

func (Header) Charset

func (h Header) Charset() string

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

func (Header) Disposition

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

func (h Header) Encoding() string

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

func (Header) InReplyTo

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

func (h Header) MajorType() string

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

func (Header) MessageID

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

func (h Header) MinorType() string

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

func (Header) Params

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

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

Recipients returns the parsed recipient addresses.

func (Header) References

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

func (h Header) Sender() *Address

Sender returns the parsed sender address.

func (Header) Subject

func (h Header) Subject() string

Subject returns the decoded subject text of h.

func (Header) Time

func (h Header) Time() time.Time

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

func (Header) Type

func (h Header) Type() string

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

func (Header) WriteTo

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

WriteTo implements the io.WriterTo interface.

type Message

type Message Part

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

func ReadMessage

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

ReadMessage reads a message from r.

func (*Message) WriteTo

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

WriteTo implements the io.WriterTo interface.

type Multipart

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

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

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

func ReadPart

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

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

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

WriteTo implements the io.WriterTo interface.

Jump to

Keyboard shortcuts

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