eml

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxHeaderLineLength ...
	MaxHeaderLineLength = 78

	// MaxHeaderTotalLength ...
	MaxHeaderTotalLength = 998
)
View Source
const (
	// MaxBodyLineLength ...
	MaxBodyLineLength = 76
)

Variables

View Source
var ErrHeadersMissingField = errors.New("Message missing header field")

ErrHeadersMissingField ...

Functions

func DecodeBase64GBK added in v1.0.1

func DecodeBase64GBK(raw string) (string, error)

func GbkToUtf8 added in v1.0.1

func GbkToUtf8(s []byte) ([]byte, error)

func GenContentID

func GenContentID(filename string) (string, error)

GenContentID creates and returns a Content-ID, without surrounding angle brackets.

func GenMessageID

func GenMessageID() (string, error)

GenMessageID creates and returns a Message-ID, without surrounding angle brackets.

func IsGBK added in v1.0.1

func IsGBK(data []byte) bool

func ParsePart

func ParsePart(m *Message, msg *mailfile.Message)

func ParseParts

func ParseParts(m *Message, msg *mailfile.Message)

Types

type Header map[string][]string

Header represents the key-value MIME-style pairs in a mail message header. Based on textproto.MIMEHeader and mail.Header.

func NewHeader

func NewHeader(from string, subject string, to ...string) Header

NewHeader returns a Header for the most typical use case: a From address, a Subject, and a variable number of To addresses.

func (Header) Add

func (h Header) Add(key, value string)

Add adds the key, value pair to the header. It appends to any existing values associated with key.

func (Header) AddressList

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

AddressList parses the named header field as a list of addresses.

func (Header) Bcc

func (h Header) Bcc() []string

Bcc ...

func (Header) Bytes

func (h Header) Bytes() ([]byte, error)

Bytes returns the bytes representing this header. It is a convenience method that calls WriteTo on a buffer, returning its bytes.

func (Header) Cc

func (h Header) Cc() []string

Cc ...

func (Header) ContentDisposition

func (h Header) ContentDisposition() (string, map[string]string, error)

ContentDisposition parses and returns the media disposition, any parameters on it, and an error if there is no content disposition header field.

func (Header) ContentType

func (h Header) ContentType() (string, map[string]string, error)

ContentType parses and returns the content media type, any parameters on it, and an error if there is no content type header field.

func (Header) Date

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

Date parses the Date header field.

func (Header) Del

func (h Header) Del(key string)

Del deletes the values associated with key.

func (Header) From

func (h Header) From() string

From ...

func (Header) Get

func (h Header) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "". Get is a convenience method. For more complex queries, access the map directly.

func (Header) IsSet

func (h Header) IsSet(key string) bool

IsSet tests if a key is present in the Header

func (Header) Save

func (h Header) Save() error

Save adds headers for the "Message-Id", "Date", and "MIME-Version", if missing. An error is returned if the Message-Id can not be created.

func (Header) Set

func (h Header) Set(key, value string)

Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key.

func (Header) SetBcc

func (h Header) SetBcc(emails ...string)

SetBcc ...

func (Header) SetCc

func (h Header) SetCc(emails ...string)

SetCc ...

func (Header) SetFrom

func (h Header) SetFrom(email string)

SetFrom ...

func (Header) SetSubject

func (h Header) SetSubject(subject string)

SetSubject ...

func (Header) SetTo

func (h Header) SetTo(emails ...string)

SetTo ...

func (Header) Subject

func (h Header) Subject() string

Subject ...

func (Header) To

func (h Header) To() []string

To ...

func (Header) WriteTo

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

WriteTo writes this header out, including every field except for Bcc.

type Message

type Message struct {
	// Header is this message's key-value MIME-style pairs in its header.
	Header Header

	// Preamble is any text that appears before the first mime multipart,
	// and may only be full in the case where this Message has a Content-Type of "multipart".
	Preamble []byte

	// Epilogue is any text that appears after the last mime multipart,
	// and may only be full in the case where this Message has a Content-Type of "multipart".
	Epilogue []byte

	// Parts is a slice of Messages contained within this Message,
	// and is full in the case where this Message has a Content-Type of "multipart".
	Parts []*Message

	// SubMessage is an encapsulated message, and is full in the case
	// where this Message has a Content-Type of "message".
	SubMessage *Message

	// Body is a byte array of the body of this message, and is full
	// whenever this message doesn't have a Content-Type of "multipart" or "message".
	// The Body is already decoded if the Content-Transfer-Encoding was
	// quoted-printable or base64, and will be re-encoded when written out
	// based on the Content-Type.
	Body []byte
}

Message represents a full email message, or a mime-message (such as a single part in a multipart message). It has fields for the Header and the payload, which may take several forms depending on the Content-Type of this message. If the Content-Type is "message", then the payload will be a SubMessage. If the Content-Type is "multipart", then the payload will be Parts, and optionally the Preamble and Epilogue will be full. If the Content-Type is neither "message" nor "multipart", then the payload will be a Body (decoded if quoted-printable or base64).

func New

func New(file string) (*Message, error)

func ParseMessage

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

ParseMessage parses and returns a Message from an io.Reader containing the raw text of an email message. (If the raw email is a string or []byte, use strings.NewReader() or bytes.NewReader() to create a reader.) Any "quoted-printable" or "base64" encoded bodies will be decoded.

func (*Message) Bytes

func (m *Message) Bytes() ([]byte, error)

Bytes returns the bytes representing this message. It is a convenience method that calls WriteTo on a buffer, returning its bytes.

func (*Message) Format

func (m *Message) Format() *mailfile.Message

func (*Message) HasBody

func (m *Message) HasBody() bool

HasBody returns true if the Content-Type is not "multipart" nor "message"

func (*Message) HasParts

func (m *Message) HasParts() bool

HasParts returns true if the Content-Type is "multipart"

func (*Message) HasSubMessage

func (m *Message) HasSubMessage() bool

HasSubMessage returns true if the Content-Type is "message"

func (*Message) MessagesAll

func (m *Message) MessagesAll() []*Message

MessagesAll will return a slice of Messages, starting with this message, and followed by all messages contained within this message, recursively. This method is similar to Python's email message "walk" function. This method DOES recurse into sub-messages and sub-parts.

func (*Message) MessagesContentTypePrefix

func (m *Message) MessagesContentTypePrefix(contentTypePrefix string) []*Message

MessagesContentTypePrefix will return a slice of all Messages that have this contentTypePrefix, potentially including this message and messages contained within this message. contentTypePrefix can be a prefix ("text"), or a full type ("text/html"). This method DOES recurse into sub-messages and sub-parts.

func (*Message) MessagesFilter

func (m *Message) MessagesFilter(filter func(*Message) bool) []*Message

MessagesFilter will return a slice of all Messages that match this lambda function, potentially including this message and messages contained within this message. This method DOES recurse into sub-messages and sub-parts.

func (*Message) PartsContentTypePrefix

func (m *Message) PartsContentTypePrefix(contentTypePrefix string) []*Message

PartsContentTypePrefix will return a slice of all parts of this message that have this contentTypePrefix. contentTypePrefix can be a prefix ("text"), or a full type ("text/html"). The slice will be empty if this message is not a multipart message. This method does NOT recurse into sub-messages and sub-parts.

func (*Message) PartsFilter

func (m *Message) PartsFilter(filter func(*Message) bool) []*Message

PartsFilter will return a slice of all parts of this message that match this lambda function. The slice will be empty if this message is not a multipart message. This method does NOT recurse into sub-messages and sub-parts.

func (*Message) Payload

func (m *Message) Payload() interface{}

Payload will return the payload of the message, which can only be one the following: Body ([]byte), SubMessage (*Message), or Parts ([]*Message)

func (*Message) Save

func (m *Message) Save() error

Save adds headers for the "Message-Id", "Date", and "MIME-Version", if missing. An error is returned if the Message-Id can not be created.

func (*Message) WriteTo

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

WriteTo writes out this Message and its payloads, recursively. Any text bodies will be quoted-printable encoded, and all other bodies will be base64 encoded.

Jump to

Keyboard shortcuts

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