mailutil

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidAddress = errors.New("invalid email address")
View Source
var RobustAddressParser = mail.AddressParser{
	TryMimeDecoder,
}

Decodes the Name (not used at the moment). mail.ParseAddress and mail.ParseAddressList yield errors on encoded input, so we should this

View Source
var TryMimeDecoder = &mime.WordDecoder{
	CharsetReader: func(charset string, input io.Reader) (io.Reader, error) {
		if enc, err := htmlindex.Get(charset); err == nil {
			return enc.NewDecoder().Reader(input), nil
		} else {
			return input, nil
		}
	},
}

CharsetReader never returns an error

Functions

func IsSpamKey

func IsSpamKey(headerKey string) bool

func RFC5322AddrSpecs added in v0.10.5

func RFC5322AddrSpecs(addrs []*Addr) []string

func TryMimeDecode

func TryMimeDecode(input string) string

"[DecodeHeader] decodes all encoded-words of the given string"

func WriteHeader

func WriteHeader(w io.Writer, header mail.Header) error

Types

type Addr

type Addr struct {
	Display string // RFC 5322 display-name
	Local   string // RFC 5322 local-part, only a subset of ASCII is allowed
	Domain  string // RFC 5322 domain
}

func NewAddr

func NewAddr(address *mail.Address) (*Addr, error)

func ParseAddress

func ParseAddress(rfc5322Address string) (*Addr, error)

parses an address like "Alice <alice@example.org>", "<alice@example.org>" or "alice@example.org" returns the canonicalized address

It is recommended to canonicalize or parse all input data (from form post data, url parameters, SMTP commands, header fields).

func ParseAddresses

func ParseAddresses(rawAddresses string, limit int) (addrs []*Addr, errs []error)

ParseAddresses expects one RFC 5322 address-list per line. It does lax parsing and is intended for user input.

func ParseAddressesFromHeader

func ParseAddressesFromHeader(header mail.Header, fieldName string, limit int) ([]*Addr, error)

ParseAddressesFromHeader parses email addresses from a header line. In contrast to ParseAddresses, parsing is strictly.

func SingleFrom

func SingleFrom(header mail.Header) (*Addr, bool)

func (*Addr) DisplayOrLocal

func (a *Addr) DisplayOrLocal() string

Returns a.Display if it exists, else a.Local.

rspamd has the rule "SPOOF_DISPLAY_NAME" which yields a huge penalty if the "From" field looks like "foo@example.net via List<list@example.com>" [1]. To be on the safe side, we crop the result at the first "@", if any.

[1] https://github.com/rspamd/rspamd/blob/master/rules/misc.lua#L517

func (*Addr) Equals

func (a *Addr) Equals(other *Addr) bool

compares Local and Domain case-insensitively

func (Addr) RFC5322AddrSpec

func (a Addr) RFC5322AddrSpec() string

RFC 5322 addr-spec = local-part "@" domain

Because the local-part might be quoted, we let golang do the work

func (*Addr) RFC5322NameAddr

func (a *Addr) RFC5322NameAddr() string

RFC 5322 name-addr = [display-name] angle-addr angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr

mail.Address.String(): "If the address's name contains non-ASCII characters the name will be rendered according to RFC 2047."

func (*Addr) RFC6068URI

func (a *Addr) RFC6068URI(query string) string

RFC 6068 The 'mailto' URI Scheme

func (*Addr) String

func (a *Addr) String() string

type ChanMTA

type ChanMTA chan *MTAEnvelope

used for testing

func (ChanMTA) Send

func (c ChanMTA) Send(envelopeFrom string, envelopeTo []string, header mail.Header, body io.Reader) error

func (ChanMTA) String

func (ChanMTA) String() string

type DummyMTA

type DummyMTA struct{}

func (DummyMTA) Send

func (DummyMTA) Send(envelopeFrom string, envelopeTo []string, header mail.Header, body io.Reader) error

func (DummyMTA) String

func (DummyMTA) String() string

type MTA

type MTA interface {
	Send(envelopeFrom string, envelopeTo []string, header mail.Header, body io.Reader) error
	String() string
}

type MTAEnvelope

type MTAEnvelope struct {
	EnvelopeFrom string
	EnvelopeTo   []string
	Message      string
}

used for testing

type Message

type Message struct {
	Header mail.Header
	Body   []byte // can be copied easily
}

Replacement for golang's mail.Message. The only difference is that the body is stored as a byte slice.

Just aliasing golang's mail.Message is not feasible because we can't rewind mail.Message.Body.(bufio.Reader), so Copy() had to create two new buffers each time.

func NewMessage

func NewMessage() *Message

func ReadMessage

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

wraps mail.ReadMessage

func (*Message) BodyReader

func (m *Message) BodyReader() io.Reader

func (*Message) Save

func (m *Message) Save(w io.Writer) error

func (*Message) SingleFrom

func (m *Message) SingleFrom() (*Addr, bool)

type Sendmail

type Sendmail struct{}

func (Sendmail) Send

func (Sendmail) Send(envelopeFrom string, envelopeTo []string, header mail.Header, body io.Reader) error

func (Sendmail) String

func (Sendmail) String() string

Jump to

Keyboard shortcuts

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